Docsity

Introducing JAVA - Object Oriented and GUI Programming - Lecture Slides, Slides of Object Oriented Programming

Partial preview of the text

Download Introducing JAVA - Object Oriented and GUI Programming - Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

Chapter 1: Introducing JAVA

2

Introduction

Why JAVA

  • Applets and Server Side Programming
  • Very rich GUI libraries
  • Portability (machine independence)
  • A real Object Oriented Language (plus all

the advantages of OOP)

  • Support International character sets

(Unicode)

4

Program Development

  • Editing (any text editor or IDE)
  • Compiling (javac)  Java Object (byte)

code

  • JVM interprets that code and translates it

to machine language code

  • Try installing JDK 5.0 (or the newest one,

JDK 6.0) then use a simple editor edit,

compile and run a simple program

  • Applets

5

OOP in JAVA

  • What is an object? Any thing around us
  • A class is a a term that describes a collection of objects with common properties
  • It is basically a convenient way to group things
  • A class defines a set of instance variables called data members, attributes, or fields & a number of functions operating on these attributes (methods)
  • An instance of a class is an existing object of that class
  • Example: a Student class

7

Operations on Objects

  • Methods: putHatOn(), takeHatOff()
  • Performing an operation on an object amounts to calling the method that defines that operation for the object.
  • Advantages of OOP:
    • Intuitive modeling
    • easier to understand and maintain
    • less error-prone
    • Longer to design but less time to write and test

8

Encapsulation

  • Encapsulation: Hiding implementation
  • Variables and method can be hidden by using the private keyword
  • You can change the internal details of the class without affecting other modules
  • By using a method to set or change the values of a variable you can ensure that only legal values are set
  • Defining a class is equivalent to defining a new data type