0% found this document useful (0 votes)
13 views

Lecture-2.pptx

The document compares C++ and Java, highlighting their differences in features, security, and programming paradigms. It explains the architecture of the Java Virtual Machine (JVM), detailing its components such as JDK and JRE, and emphasizes Java's platform independence and automatic memory management. The session aims to provide students with a comprehensive understanding of object-oriented programming concepts and the execution model of both languages.

Uploaded by

Yamini Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Lecture-2.pptx

The document compares C++ and Java, highlighting their differences in features, security, and programming paradigms. It explains the architecture of the Java Virtual Machine (JVM), detailing its components such as JDK and JRE, and emphasizes Java's platform independence and automatic memory management. The session aims to provide students with a comprehensive understanding of object-oriented programming concepts and the execution model of both languages.

Uploaded by

Yamini Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

C++ vs Java, JVM Architecture

(JDK, JRE, JVM)

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.

1. Java and C++ are both object-oriented programming languages.

1. C++ is developed by Bjarne Stroustrup in 1979 as an extension of C.

1. C++ combines the power of C with additional features like Object-Oriented


Programming (OOP).

1. Object-Oriented Programming is a methodology to design a program using classes


and objects.
Galgotias University 2
1. There are many differences and similarities between the C++ programming language and
Review of Previous session

Galgotias University 3
Procedural Oriented programming(POP) versus object
oriented Programming(OOP)
Feature Procedural Oriented Programming Object Oriented Programming

Approach Follows a top-down approach Follows a bottom-up approach


Focus Focuses on procedures (functions) Focuses on objects and their interactions

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

Example Languages C, Pascal, Fortran C++, Java, Python, C#


OOPS feature(Encapsulation abstraction, Not supported Supported
Inheritance and polymorphism)
Real-world Modeling Less suitable for real-world applications Well-suited for real-world applications

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

Learning Outcome 1:Comparison between


the C++ and Java in terms of syntax,
memory management, and execution model
etc.

Learning Outcome 2: Explain the


architecture of the Java Virtual
Machine (JVM) and its components
(JDK, JRE, JVM)
Galgotias University 6
1 Introduction of C++ vs Java, JVM
Architecture (JDK, JRE, JVM)

2 Compare between the C++ and Java

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

Platform-independent C++ is platform-dependent. Java is platform-independent.


Java is mainly used for application programming. It is
Mainly used for C++ is mainly used for system programming. widely used in Windows-based, web-based, enterprise,
and mobile applications.

Goto C++ supports the goto statement. Java doesn't support the goto statement.

Java doesn't support multiple inheritance through class.


Multiple inheritance C++ supports multiple inheritance.
It can be achieved by using interfaces in java.

Operator Overloading C++ supports operator overloading. Java doesn't support operator overloading.

Java supports pointer internally. However, you can't


C++ supports pointers. You can write a pointer program
Pointers write the pointer program in java. It means java has
in C++.
restricted pointer support in java.
Java supports call by value only. There is no call by
Call by Value and Call by reference C++ supports both call by value and call by reference.
reference in java.

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++

Java is only an object-oriented C++ is both a procedural and an


Type
programming language. object-oriented programming language.
Java uses the (System
C++ uses cin for input and cout for output
Input-Output mechanism class): System.in for input
operation.
and System.out for output.
It supports only method overloading and It supports both method and operator
Overloading
doesn't allow operator overloading. overloading.
Memory Management is System
Memory Management Memory Management in C++ is Manual.
Controlled.
C++ doesn’t have built-in support for
Java provides built-in support for
Thread Support threads, depends on third-party threading
multithreading.
libraries.
Galgotias University 9
It supports both global scope and
Learning Activity 1 (Role Play)
Discussion Points:
1. Syntax
2. Performance
3. Memory Management
4. Portability
5. Object-Oriented Programming (OOP)
6. Exception Handling
7. Security
8. Compilation & Execution

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.

Compilation & Execution


● C++: Compiled directly to machine code, faster execution.
● Java: Compiled to bytecode, runs on JVM, platform-independent.
Galgotias University 12
Introduction to activity 2-Java Virtual
Machine(JVM)
• JVM(Java Virtual Machine) runs Java applications as a run-time engine. JVM is the one that
calls the main method present in a Java code. JVM is a part of JRE(Java Runtime Environment).

• Java applications are called WORA (Write Once Run Anywhere).

• JDK (Java Development Kit)-A full package for Java development, including JRE and
development tools.

• JRE (Java Runtime Environment)-The environment required to run Java applications.

• 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

MCQ questions based on JVM architecture


1. What is the primary function of the JVM (Java Virtual Machine)?
2. What component of the JVM is responsible for converting bytecode into machine code?
3. Which part of the JVM is responsible for memory management?
4. How is memory allocated for local variables in JVM?
5. What does JDK stand for?

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)

Outcome 1:Compare between the C++ and Java in terms of


syntax, memory management, and execution model etc.

Outcome 2:Explain the architecture of the Java


Virtual Machine (JVM) and its components (JDK,
JRE, JVM)

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

You might also like