WDD_lec_04 - Web Design & Development Lecture 4 OOP in Java...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 4
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
OOP in Java
Background image of page 2
OOP in Java Java is fundamentally Object-Oriented Every line of code you write in Java must be inside a Class (not counting import directives) Clear use of Variables Methods Re-use through “packages” Modularity, Encapsulation, Inheritance, Polymorphism etc
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
OOP Vocabulary Review Classes Definition or a blueprint of a userdefined datatype Prototypes for objects Objects Nouns, things in the world Constructor Given a Class, the way to create an Object (that is, an Instance of the Class) and initialize it Attributes Properties an object has Methods Actions that an object can do Object Anything we can put a thumb on
Background image of page 4
Defining Classes
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Structure of Classes class    name    { declarations constructor definitions method definitions } instance variables and symbolic constants how to create and  initialize objects how to manipulate those  objects (may or may not  include its own “driver”,  i.e., main( )) These parts of a class can actually be in any order
Background image of page 6
Defining a Class Comparison with C++ Java gives you the ability to write classes or user-defined data types similar to the way C++ does, with a few differences Points to consider when defining a class There are no global variables or functions. Everything resides inside a class. Remember we wrote our main method inside a class Specify access modifiers (public, private or protected ) for each member method or data members at every line. No semicolon (;) at the end of class All methods (functions) are written inline. There are no separate header and implementation files.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Point Class class    Point    {            private int x;        private int y;                      public Point (……) {……}         public void Display (……) {            ……….                } } instance variables and symbolic constants how to create and  initialize objects how to manipulate those  objects (may or may not  include its own “driver”,  i.e., main( ))
Background image of page 8
Points to consider when defining a class (cont) Automatic initialization of class level data members if you do not initialize them Primitive types Numeric (int, float etc) with zero Char with null Boolean with false Object References With null Remember, the same rule is not applied to local variables. Using a local variable without initialization is a compile time
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/01/2010 for the course CS CS506 taught by Professor mr. umair javed during the Spring '10 term at Virtual University of Pakistan.

Page1 / 39

WDD_lec_04 - Web Design & Development Lecture 4 OOP in Java...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online