Chapter 2: Everything is an Object ● C++ has many non object oriented features inherited from C. It is a hybrid language meaning that it support different.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Lifetime “The lifetime of a variable is the time during which the variable is bound to a specific memory location.” [p. 219] “…the lifetime of a variable.
Run-Time Storage Organization
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
Java and C++, The Difference An introduction Unit - 00.
Presented by: Mojtaba Khezrian. Agenda Object Creation Object Storage More on Arrays Parameter Passing For Each VarArgs Spring 2014Sharif University of.
Object Oriented Programming: Java Edition By: Samuel Robinson.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Runtime Environments Compiler Construction Chapter 7.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
The Java Programming Language
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 1 - Introduction Richard Salomon and Umesh Patel Centre for Information.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
2: Everything is an Object You Manipulate Objects Using References Primitives Arrays in Java Scoping You Never Destroy Objects Creating New Data Types:
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays and Methods l Programming with Arrays.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Everything Is an Object Manipulate objects with references The identifier you manipulate is actually a “reference” to an object. Like a television.
Compiler Construction Dr. Noam Rinetzky and Orr Tamir School of Computer Science Tel Aviv University
Peyman Dodangeh Sharif University of Technology Fall 2013.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R F I V E Memory Management.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Introduction to Java COM379 (Part-Time) University of Sunderland Harry R Erwin, PhD.
More C++ Features True object initialisation
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
Everything is an object (CH-2) Manipulating Objects with References. Manipulating Objects with References. String s; String s = “IS2550” String s = new.
CMSC 341 Java Packages, Classes, Variables, Expressions, Flow Control, and Exceptions.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Objects and Variables Local variables – Confined to single context: allocated on stack – Primitive types such as int or object references – Must be initialized.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
Java FilesOops - Mistake Java lingoSyntax
Peyman Dodangeh Sharif University of Technology Spring 2014.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 1-Introduction to Java Topic 1.3 Write Your First Java Program Produced by Harvey.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Object-Oriented Programming and Problem Solving Dr. Ramzi Saifan Introduction and basics of Java Slides adapted from Steven Roehrig.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Object Oriented Programming Lecture 2: BallWorld.
1 Stack and Heap. 2 “Stack” Stack – a linear data structure in which items are added and removed in last-in, first-out order. Definition: context – the.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Variable Scope & Lifetime
Object Lifetime and Pointers
Intro to ETEC Java.
Static data members Constructors and Destructors
Website: SSD1 Unit 2 Intro to Java Presentation 2.3 Website:
Java Review Hello..This ppt is to give you an introduction about java and why it is soo special The segments all discussed here are the crucial parts of.
Advanced Programming Behnam Hatami Fall 2017.
From C++ to Java Java history: Oak, toaster-ovens, internet language, panacea What it is O-O language, not a hybrid (cf. C++) compiled to byte-code, executed.
Variables and Java vs C++
Classes and Objects Object Creation
CMSC 202 Constructors Version 9/10.
Presentation transcript:

Chapter 2: Everything is an Object ● C++ has many non object oriented features inherited from C. It is a hybrid language meaning that it support different programming styles: non- object oriented and object oriented and even mixture of them. ● Java is a more pure object oriented language – Everything is Object in Java – To program in Java, one should learn OOP first

Objects are manipulated with references ● The identifier (variable) we use to manipulate objects are actually referenc to object ● A variable may not refer to any object when it is defined: – String s; ● Or it may be refer to an object: – String s=”asdf”; ● All objects should be created before usage: – String s = new String(“asdf”);

Where data is stored ● Registers: Fastest storage. It is inside processor. No control on registers in Java programs ● Stack. A part of RAM. Processor has stack pointer for accessing stack. Java stores object references on stack. ● Heap: all Java objects are stored in heap when a new statement is reached at runtime. Java runtime system manages storage allocation of heap. ● Static storage (fixed location): Java objects never stores in static storage ● Constant storage ● Non-RAM storage: for example disk storage

Special case: primitive types ● Types like int that are used frequently in programs, and need a small amount of storage are not treated as objects. ● They are not created with new and are not references (for efficiency) ● They are stored in stack (for efficiency)

Primitive types - Wrapper classes: char c = 'x'; Character char = new Character(c);

Arrays ● Unlike C, Java does range checking and initialization for arrays ● An array of objects is initialized with null references

Never need to destroy an object ● Scoping: ● Lifetime of Objects – Objects may live even after end of scope – Garbage collector destroys un-used objects

Creating new data types: class ● With a class definition, a new type is created ● Fields (Data members)

Creating new types: Class ● Methods, arguments and return values

First Java program //: c02:HelloDate.java // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 // See copyright notice in CopyRight.txt. import java.util.*; /** The first Thinking in Java example program. * Displays a string and today's date. Bruce Eckel */ public class HelloDate { /** Sole entry point to class & application args array of string arguments No return value exceptions No exceptions thrown */ public static void main(String[] args) { System.out.println("Hello, it's: "); System.out.println(new Date()); } } ///:~

Compiling an running ● javac and java ● Editing, compiling and running the program using eclipse IDE. ● Generating documentation using javadoc ● Coding style: class AllTheColorsOfTheRainbow { int anIntegerRepresentingColors; void changeTheHueOfTheColor(int newHue) { //... } //... }