Chapter 1 (Intro To Object Oriented Prog.)
Chapter 1 (Intro To Object Oriented Prog.)
Objectives:
Class Objects
Once you have created a class, you can create instances of the class (objects) in a Driver
Class or inside other Object Classes.
Instances (Objects):
• Inherit all attributes and methods defined in the class template.
• Interact independently of one another.
• Are reference objects.
• Are created using the new operator.
OOP Characteristics:
a. Abstraction ~ designing classes
the ability of the program to focus on the important matters and ignore some
aspects of the information it is manipulating
the creation of a software module containing relevant characteristics of the object to
be represented
Advantages of OOP:
Simpler, easy to read programs
More efficient reuse of code
Faster time to market
More robust, error-free code
A Student
A Student
study() in group:
study() at home: the the student discusses
student does revision with friends
study() in class:
the student listens to
study() in library: the lectures and take
student make references notes
A Student
A Person
Inherits
No Characteristic Description
1. Simple
Java is partially modeled on C++, but greatly simplified and
improved
3. Object
Oriented programming in Java is centered on creating objects, manipulating
objects, and making objects work together.
5. Interpreted Java programs are compiled into the Java Virtual Machine code
called bytecode, and it is machine independent.
6. Robust
Reliability because it puts a lot of emphasis on early checking for
possible errors. Java has a runtime exception-handling feature to
provide programming support for robustness.
7. Secure
As an Internet programming language, Java is used in a
networked and distributed environment. Java implements
several security mechanisms to protect your system against
harm caused by stray program.
8. Portable
Java is architecture neutral. It can run in any platform without
being recompiled. The Java environment is portable to new
hardware and operating systems
9. Performance
Java’s performance is sometimes criticized compared to C++.
Because Java is interpreted, the bytecode is not directly executed by
the system, but is run through the interpreter.
10. Multithread
a program’s capability to perform several tasks simultaneously.
Program 2: TestRectangle.java
import javax.swing.*;
public class TestRectangle
{
public static void main(String[]args)
8
{
Rectangle R = new Rectangle();
Sample output: