Lec 4 06_aug [compatibility mode]

331 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
331
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Lec 4 06_aug [compatibility mode]

  1. 1. ObjectObject--Oriented ProgrammingOriented Programming Lecture 4 Naveen Kumar
  2. 2. ObjectObject An object is anything that can be represented by data in a computer’s memory and manipulated by a computer program. Numbers, texts, pictures, sound, video ….. So on
  3. 3. ObjectObject An object can be something in the physical world or even just an abstract idea. for example: An airplane, is a physical object that can be manipulated by a computer.
  4. 4. ObjectObject A bank transaction is an example of an object that is not physical. To a computer, an object is simply something that can be represented by data in the computer’s memory and manipulated by computer programs
  5. 5. ObjectObject The data that represent the object are organized into a set of properties. NameName:: AI 379AI 379 OwnerOwner:: Indian AirlinesIndian Airlines LocationLocation:: 39 52′ 06″N39 52′ 06″N 75 13′ 52″W75 13′ 52″W HeadingHeading:: 271271°° AltitudeAltitude:: 19 m19 m AirSpeedAirSpeed:: 00 MakeMake:: BoeingBoeing ModelModel:: 737737 WeightWeight:: 32,820 kg32,820 kg The values stored in an object’s properties, at any one time, form the state of an object.
  6. 6. ObjectObject--Oriented ProgrammingOriented Programming Computer programs implement algorithms that manipulate the data. In object-oriented programming, the programs that manipulate the properties of an object are the object’s methods.
  7. 7. ObjectObject--Oriented ProgrammingOriented Programming We can think of an object as a collection of properties and, the methods that are used to manipulate those properties. Properties Methods
  8. 8. ObjectObject--Oriented ProgrammingOriented Programming A class is a group of objects with the same properties and the same methods.
  9. 9. ObjectObject--Oriented ProgrammingOriented Programming Each copy of an object, from a particular class is called an instance, of the object. The act of creating a new instance of an object is called instantiation.
  10. 10. ObjectObject--Oriented ProgrammingOriented Programming A class can be thought of as a blueprint for instances of its object. Two different instances of the same class will have the same properties, but different values stored in those properties.
  11. 11. ObjectObject--Oriented ProgrammingOriented Programming The same terminology is used in most object- oriented programming languages. Object Instance Property Method Instantiation Class State
  12. 12. Introduction to Java 12
  13. 13.  Development tools-part of java development kit (JDK)  Classes and methods-part of Java Standard Library (JSL), also known as Application Programming Interface (API) 1. JDK:  Appletviewer ( for viewing applets)  Javac (Compiler)  Java (Interpreter)  Javah (for C header files)  Javadoc ( for creating HTML description) Java Environment
  14. 14. 2. Application Package Interface (API) Contains hundreds of classes and methods grouped into several functional packages:  Language Support Package (String, Integer, Double, etc)  Utility Packages (rand. num. gen., sys. date)  Input/Output Packages  Networking Packages (implementing networking appl. )  AWT Package (classes for painting graphics and images)  Applet Package (web page using java) Java Environment
  15. 15. 1. Java 1.0 (96) 2. Java 1.1 (97)(Add new library, redefine applet handling and reconfigured many features.) 3. Java 2 (98)(Second generation). Version no:1.2 (Internal version number of java library). Also known as J2SE [ Java 2 Platform Standard Edition]. - Add swing, the collection framework, enhanced JVM etc. 4. J2SE 1.3 (2000) 5. J2SE 1.4 (2002) 6. J2SE 1.5 (2004) 7. J2SE 1.6 (2006) [1.7-(2013), in queue 1.8 (exp in 2014) ] The Evolution of Java
  16. 16. Comments In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines When the compiler sees //, it ignores all text after // in the same line When it sees /*, it scans for the next */ and ignores any text between /* and */
  17. 17. Example /* Traditional "Hello World!" program. */ // package pack1; // import java.lang.System; class A { public static void main (String args[]) { System.out.println("Hello World!"); } } Save program as A.java
  18. 18. Java Program Structure Package Statement  Javac command compiles the source code A.java then, generates A.class and store it under a directory which is called as name of the package  package statement if used must be the first statement in a compilation unit. Its syntax is: package packageName;  For example: package pack1;
  19. 19. Import Statement  The import statements are similar to #include statements in C and C++  In the above program, System class of java.lang package is imported into all Java programs by default. The syntax of import statement is as: import fullClassName;  For example, the following import statement imports the System class from java.lang: import java.lang.System; import java.lang.*;
  20. 20. Classes and Methods  Class declarations contain a keyword class and an identifier (Ex: A)  Class members are enclosed within braces. The syntax of defining a class is shown below: class A { // program code }  To execute a class, it must contain a valid main method  It is the first method that automatically gets invoked when the program executed public static void main (String args[]) { //instructions }

×