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

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

View Full Document Right Arrow Icon
Web Design & Development Lecture 4
Image of page 1

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

View Full Document Right Arrow Icon
OOP in Java
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
Image of page 3

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

View Full Document Right 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
Image of page 4
Defining Classes
Image of page 5

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

View Full Document Right 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
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.
Image of page 7

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

View Full Document Right 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( ))
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.
Image of page 9

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern