Introduction to Object Oriented Programming and Java- ICSE Notes
Introduction to Object Oriented Programming and Java – ICSE
Introduction
Object Oriented Programming (OOP) is a modern programming approach in which a program is designed using objects and classes. Java is a popular object-oriented programming language widely used in schools, colleges, and the software industry.
This chapter helps students understand the basic concepts of OOP and Java, which form the foundation of advanced programming.
1. Principles of Object Oriented Programming
Object Oriented Programming is based on four main principles:
Procedure Oriented Programming vs Object Oriented Programming
| Procedure Oriented Programming | Object Oriented Programming |
|---|---|
| Program is divided into functions | Program is divided into objects |
| Data is not well protected | Data is well protected |
| Less secure | More secure |
| Example: C language | Example: Java, C++ |
| Reusability is less | Reusability is high |
1. Abstraction
Definition:
Abstraction means showing only essential features of an object and hiding the unnecessary details.
Real Life Example:
An ATM machine allows users to withdraw money but hides internal processing like verification and calculations.
Importance:
-
Reduces complexity
-
Makes programs easier to use
2. Encapsulation
Definition:
Encapsulation is the process of binding data and methods together into a single unit called a class.
Real Life Example:
A medicine capsule contains medicines safely enclosed inside it.
Advantages:
-
Provides data security
-
Prevents misuse of data
3. Inheritance
Definition:
Inheritance is the process by which one class acquires the properties and methods of another class.
Real Life Example:
A child inherits qualities and properties from parents.
Advantages:
-
Code reusability
-
Saves time and effort
4. Polymorphism
Definition:
Polymorphism means one name, many forms. The same method can perform different tasks.
Real Life Example:
A person behaves differently as a student, son, or friend.
Advantages:
-
Increases flexibility
-
Improves code readability
2. Introduction to Java
Java is a high-level, object-oriented programming language developed by Sun Microsystems. It is widely used because of its simplicity, security, and platform independence.
Types of Java Programs
1. Java Applications
-
Standalone programs
-
Use the
main()method -
Run on desktop systems
Examples:
Calculator, Text Editor
2. Java Applets
-
Small Java programs that run inside a web browser
-
Do not use the
main()method -
Require a browser or applet viewer
Note: Applets are now outdated but still included in ICSE syllabus.
Java Compilation Process
Steps Involved:
-
Java Source Code (.java file)
-
Java Compiler (javac)
-
Byte Code (.class file)
-
Java Virtual Machine (JVM)
-
Output
Java Source Code
The program written by the programmer in Java language is called source code.
It is saved with the extension .java.
Byte Code
The intermediate code generated by the Java compiler is called byte code.
It is platform-independent and stored in .class files.
Object Code
Object code is machine-dependent code that can be directly understood by the computer hardware.
Java Virtual Machine (JVM)
Definition:
JVM is a virtual machine that converts byte code into machine code and executes it.
Functions of JVM:
-
Executes Java programs
-
Manages memory
-
Provides security
Features of Java
-
Simple – Easy to learn and use
-
Object Oriented – Based on OOP concepts
-
Platform Independent – Write once, run anywhere
-
Secure – Safe from viruses
-
Robust – Strong error handling
-
Portable – Easily transferable
-
Multithreaded – Performs multiple tasks simultaneously
Most Important Questions
Short Answer Questions – Answers
1. Define Object Oriented Programming.
Object Oriented Programming (OOP) is a programming approach in which a program is designed using objects and classes. It focuses on data and the operations performed on that data.
2. What is Abstraction? Give one real-life example.
Abstraction is the process of hiding unnecessary details and showing only essential features of an object.
Example: An ATM machine allows the user to withdraw cash without showing the internal processing.
3. Define Encapsulation.
Encapsulation is the process of binding data and methods together into a single unit called a class. It helps in protecting data from unauthorized access.
4. What is Inheritance?
Inheritance is a mechanism in which one class acquires the properties and methods of another class, allowing code reuse and reducing duplication.
5. What is Polymorphism?
Polymorphism means one name, many forms. It allows the same method or function to perform different tasks in different situations.
Long Answer Questions – Answers
1. Explain the four principles of Object Oriented Programming with real-life examples.
The four principles of Object Oriented Programming are:
1. Abstraction:
It shows only important details and hides unnecessary information.
Example: ATM machine.
2. Encapsulation:
It binds data and methods into a single unit.
Example: A medicine capsule.
3. Inheritance:
It allows a class to inherit properties from another class.
Example: Child inheriting qualities from parents.
4. Polymorphism:
It allows one method to perform multiple functions.
Example: A person acting as a student, son, and friend.
2. Differentiate between Procedure Oriented Programming and Object Oriented Programming.
Procedure Oriented Programming Object Oriented Programming Focuses on functions Focuses on objects Data is less secure Data is more secure No data hiding Supports data hiding Example: C Example: Java, C++
| Procedure Oriented Programming | Object Oriented Programming |
|---|---|
| Focuses on functions | Focuses on objects |
| Data is less secure | Data is more secure |
| No data hiding | Supports data hiding |
| Example: C | Example: Java, C++ |
3. Explain the Java Compilation Process with a diagram (description).
The Java compilation process involves the following steps:
-
The programmer writes the Java source code (.java).
-
The source code is compiled using the Java Compiler (javac).
-
The compiler converts source code into byte code (.class).
-
The Java Virtual Machine (JVM) converts byte code into machine code.
-
The program is executed and output is displayed.
4. What is JVM? Explain its functions.
JVM (Java Virtual Machine) is a virtual machine that executes Java byte code and converts it into machine-readable code.
Functions of JVM:
-
Executes Java programs
-
Manages memory
-
Provides security
-
Makes Java platform independent
5. Describe the features of Java.
The important features of Java are:
-
Simple: Easy to learn and understand
-
Object Oriented: Based on OOP principles
-
Platform Independent: Write once, run anywhere
-
Secure: Protects against viruses and threats
-
Robust: Strong error handling
-
Portable: Can run on any system
-
Multithreaded: Performs multiple tasks at the same time


Comments
Post a Comment