Lecture-2.pptx
Lecture-2.pptx
Session No.:2
Course Name: Object Oriented Programming using Java
Course Code: R1UC201C
Duration: 50 Minutes
Date of Conduction of Class: 05-03-2025
Galgotias University 1
Review of Previous session
1. Java is a high-level, object-oriented, platform-independent programming language
developed by Sun Microsystems.
Galgotias University 3
Procedural Oriented programming(POP) versus object
oriented Programming(OOP)
Feature Procedural Oriented Programming Object Oriented Programming
Code Reusability Limited; relies on functions for reuse High; uses inheritance and polymorphism
Security Less secure (global data can be accessed and More secure (data hiding and encapsulation)
modified)
Modularity Code is divided into functions Code is divided into objects and classes
Access specifier There is no access specifier in procedural Object oriented programming have access
Galgotias University 4
programming. specifiers like private, public, protected etc.
Discuss the key differences between C++ and Java in
terms of their features, security, overloading, access
specifier, platform independence, and application areas?
What is architecture of the Java Virtual Machine(JVM)?”.
1. What object-oriented programming (OOP) features are common to
both languages?
2. Why is Java considered more secure than C++?
3. Why is Java considered platform-independent, while C++ is not?
4. How does the compilation process differ between C++ (which compiles
to machine code) and Java (which compiles to bytecode)?
Galgotias University 5
At the end of this session students will be able
to
Session
Outline 3 Explain the architecture of the Java Virtual
Machine (JVM) and its components (JDK,
JRE, JVM)
4 Conclusion
Galgotias University 7
Introduction of activity 1-C++ versus Java
Feature C++ Java
Goto C++ supports the goto statement. Java doesn't support the goto statement.
Operator Overloading C++ supports operator overloading. Java doesn't support operator overloading.
Structure and Union C++ supports structures and unions. Java doesn't support structures and unions.
Galgotias University 8
Java has no virtual keyword. We can override all
C++ supports virtual keyword so that we can decide
C++ versus Java
Feature Java C++
Galgotias University 10
Reflection-Learning Activity 1
Syntax & Learning Curve
● C++: Complex, includes pointers, multiple inheritance.
● Java: Simpler, no pointers, single inheritance with interfaces.
Performance
● C++: Faster, direct memory access, no VM overhead.
● Java: Slower, JIT compilation optimizes performance.
Memory Management
● C++: Manual allocation/deallocation, risk of memory leaks.
● Java: Automatic garbage collection, less memory control.
Portability
● C++: Platform-dependent, requires recompilation.
● Java: “Write Once, Run Anywhere” via JVM.
Galgotias University 11
Reflection-Learning Activity 1
Object-Oriented Programming (OOP)
● C++: Supports both procedural and OOP paradigms.
● Java: Strictly OOP with built-in memory management.
Security
● C++: More prone to security vulnerabilities (e.g., buffer overflow).
● Java: Secure with built-in memory protection and exception handling.
Exception Handling
● C++: Manual exception handling.
● Java: Built-in robust exception handling.
• JDK (Java Development Kit)-A full package for Java development, including JRE and
development tools.
• JVM (Java Virtual Machine)-An abstract machine that executes Java bytecode.
Galgotias University 13
JVM VS JDK VS JRE JDK vs JRE vs JVM
Galgotias University 14
JVM Architecture
Galgotias University 15
Learning Activity 2(Think-Pair-Share)
Exploring JVM Architecture
Galgotias University 16
Reflection-Learning Activity 2
1. What is the primary function of the JVM (Java Virtual Machine)?
Java bytecode into machine-specific instructions
2. What component of the JVM is responsible for converting bytecode into machine
code?
Just-In-Time (JIT) Compiler
3. Which part of the JVM is responsible for memory management?
Garbage Collector (GC)
4. How is memory allocated for local variables in JVM?
Local variables in JVM are allocated in stack memory
5. What does JDK stand for?
Java Development Kit
Galgotias University 17
Ensure attainment of LOs in alignment
to the learning activities: outcomes
(1-2)
Galgotias University 18
Discussion on the post session activities(MCQ)
1. Which programming language allows direct memory manipulation using pointers?
a) Java
b) C++
c) Both Java and C++
d) Neither Java nor C++
2. What is the output format of the Java compiler?
a)Machine code
b)Assembly code
c)Bytecode
d)Source code
3. Which of the following is NOT an Object-Oriented Programming (OOP) feature?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Compilation Galgotias University 19
Information about the next lesson-”Setting up Java
Environment, Writing & Running Java Programs”
The next lesson, “Setting up Java Environment, Writing & Running Java Programs”, will cover.
Key topics:
• Setting Up Java Environment
• Verifying Java Installation
• Writing Java Programs structure
• Understanding Java Syntax
• Compiling & Running Java Programs
• Understanding Java Bytecode & JVM Execution
Galgotias University 20
Summary
• I summarize key points of OOPS, comparison between the C++ and Java and addressing
the questions.
• C++ provides greater control over system resources, including direct memory
manipulation with pointers, manual memory management, and multiple
inheritance.
• Java, on the other hand, focuses on platform independence with its "Write Once,
Run Anywhere" capability, automatic garbage collection, and a more secure
runtime environment.
• The Java Virtual Machine (JVM) is a crucial component of the Java
programming language, enabling platform independence by converting Java
bytecode into machine-specific code at runtime.
• It plays a vital role in memory management, security, and performance
optimization through features like Just-In-Time (JIT) compilation and automatic
garbage collection. Galgotias University 21
Thank You! 🎉🙏
For Your Time & Attention💡 Happy
Learning & Coding!📩 Questions? Feel
Free to Ask!
Thank You
Galgotias University 22