0% found this document useful (0 votes)
3 views5 pages

UNIT 1 - Introduction To Java

This document provides an introduction to Java, highlighting its key properties such as simplicity, object-orientation, platform independence, security, robustness, multithreading, distribution, portability, and high performance. It compares Java with C++, explaining differences in memory management, pointers, and inheritance, while also detailing the roles of JDK, JRE, JVM, and JIT in Java development. Additionally, it covers garbage collection, its necessity, and how it operates within the Java environment.

Uploaded by

nishaddesai1997
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

UNIT 1 - Introduction To Java

This document provides an introduction to Java, highlighting its key properties such as simplicity, object-orientation, platform independence, security, robustness, multithreading, distribution, portability, and high performance. It compares Java with C++, explaining differences in memory management, pointers, and inheritance, while also detailing the roles of JDK, JRE, JVM, and JIT in Java development. Additionally, it covers garbage collection, its necessity, and how it operates within the Java environment.

Uploaded by

nishaddesai1997
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

📘 UNIT 1: Introduction to Java‬


🟢 1.1 Properties of Java‬

‭Java is:‬
‭●‬ ‭Simple‬‭: Syntax similar to C/C++‬
‭●‬ ‭Object-Oriented‬‭: Everything is an object‬
‭●‬ ‭Platform Independent‬‭: Write Once, Run Anywhere (WORA)‬
‭●‬ ‭Secure‬‭: No pointer access‬
‭●‬ ‭Robust‬‭: Automatic memory management‬
‭●‬ ‭Multithreaded‬‭: Supports multithreading‬
‭●‬ ‭Distributed‬‭: Built-in networking features‬
‭●‬ ‭Portable‬‭: Bytecode can run on any machine‬
‭●‬ ‭High Performance‬‭: JIT compiler improves speed‬

📝
‭ ‬‭Example‬‭: Android apps are written in Java – works‬‭across all Android phones.‬

‭Java Property‬ ‭What it Means‬ ‭Real-Life Use Case‬

‭Simple‬ ‭ yntax is clean and easy to read,‬


S ‭ C/C++ student can quickly start Android app‬
A
‭especially for those who know C/C++‬ ‭development using Java‬

‭Object-Oriented‬ ‭Everything is treated as an object‬ ‭ ‬‭Bank Account‬‭class can represent each‬


A
‭customer’s account in software‬

‭ latform‬
P ‭ ou write code once, and it runs on any‬
Y ‭ ava-based billing software runs on‬
J
‭Independent‬ ‭OS with JVM‬ ‭Windows‬‭,‬‭Linux‬‭, and‬‭Mac‬‭without‬
‭modification‬

‭Secure‬ ‭ o direct pointer access (which prevents‬ ‭Java is used in‬‭Banking and ATM software‬
N
‭memory hacking)‬ ‭for secure transactions‬

‭Robust‬ ‭ utomatic memory management + error‬


A ‭ mobile app doesn’t crash due to memory‬
A
‭handling‬ ‭leaks thanks to‬‭Garbage Collection‬

‭Multithreaded‬ ‭Java can perform many tasks at once‬ ‭ game loads graphics, plays music, and‬
A
‭reads input‬‭simultaneously‬

‭Distributed‬ ‭ ava can connect across computers‬


J ‭ ‬‭chat application‬‭using sockets to connect‬
A
‭over networks‬ ‭users globally‬

‭Portable‬ ‭ ytecode (.class file) runs on any‬


B .class‬‭file to your friend’s‬
‭ ou copy your‬‭
Y
‭machine with JVM‬ ‭computer and it works instantly‬

‭ igh Performance‬
H ‭ ompiles code during execution for‬
C ‭ ‬‭Java web server‬‭uses JIT to respond to‬
A
‭(JIT)‬ ‭faster performance‬ ‭users quickly in real-time‬

‭Prepared By: Nisha D. Desai‬ ‭UNIT : 1 INTRODUCTION‬‭TO JAVA‬ ‭1‬


🟢 1.2 Java vs C++‬

‭Feature‬ ‭Java‬ ‭C++‬

‭Memory Management‬ ‭Automatic (Garbage Collection)‬ ‭Manual (New/Delete)‬

‭Pointers‬ ‭No explicit pointer use‬ ‭Uses pointers‬

‭Platform‬ ‭Platform Independent‬ ‭Platform Dependent‬

‭Multiple Inheritance‬ ‭Through Interfaces‬ ‭Supported directly‬

‭Compilation‬ ‭Bytecode for JVM‬ ‭Native machine code‬

🟢 1.3 Java Compiler and Interpreter‬


javac‬‭converts‬‭
‭●‬ ‭Compiler‬‭:‬‭ .java‬‭→‬‭
.class‬‭(Bytecode)‬

‭●‬ ‭Interpreter (JVM)‬‭: Executes bytecode line by line‬

‭●‬ ‭Java is both compiled and interpreted‬

🧠
‭ ‬‭Analogy‬‭: Like writing a story (compiler) and then‬‭reading it (interpreter)‬

🟢 1.4 Use of JDK, JVM, JRE, JIT‬


‭●‬ ‭JDK (Java Development Kit)‬‭: Contains tools (javac,‬‭java) + JRE. Used by developers.‬

‭●‬ ‭JRE (Java Runtime Environment)‬‭: Contains JVM + Libraries.‬‭Needed to‬‭run‬‭Java.‬

‭●‬ ‭JVM (Java Virtual Machine)‬‭: Core component. Converts‬‭Bytecode to machine code.‬

‭●‬ J
‭ IT (Just-In-Time) Compiler‬‭: Improves performance‬‭by compiling bytecode to native‬
‭code at runtime.‬

‭Prepared By: Nisha D. Desai‬ ‭UNIT : 1 INTRODUCTION‬‭TO JAVA‬ ‭2‬


📊
‭ ‬‭Diagram‬‭:‬

‭Term‬ ‭What it is‬ ‭Real-Life Analogy‬ ‭Function‬

‭ DK‬‭Java‬
J ‭ full‬‭software‬
A ‭ itchen‬‭with all‬
K ‭ ets you‬‭write‬‭and‬
L
‭Development Kit‬ ‭package‬‭used by‬ ‭utensils + stove +‬ ‭compile‬‭Java code‬
‭developers‬ ‭recipes‬

‭ RE‬‭Java‬
J ‭ ‬‭software‬
A ‭ ining table + food‬
D ‭ eeded only to‬‭run‬‭Java‬
N
‭Runtime‬ ‭package‬‭that‬ ‭warmer‬ ‭programs‬
‭Environment‬ ‭includes JVM +‬
‭Libraries‬

‭ VM‬‭Java Virtual‬
J ‭ ‬‭software engine‬
A ‭ hef‬‭who reads your‬ C
C ‭ onverts bytecode →‬
‭Machine‬ ‭that runs Java‬ ‭recipe and cooks‬ ‭machine code‬
‭bytecode‬ ‭accordingly‬

‭ IT‬‭Just-In-Time‬
J ‭ ‬‭compiler inside‬
A ‭ hef who‬
C ‭ peeds up the program by‬
S
‭Compiler‬ ‭JVM‬ ‭memorizes steps‬ ‭converting frequently used‬
‭for repeated orders‬ ‭code into machine code‬

‭Prepared By: Nisha D. Desai‬ ‭UNIT : 1 INTRODUCTION‬‭TO JAVA‬ ‭3‬


🧠 Real-World Analogy:‬

‭Suppose you're a‬‭Java Developer‬‭:‬

‭●‬ ‭JDK‬‭: Your entire‬‭kitchen‬‭– You cook, try recipes (write‬‭+ compile code)‬

‭●‬ ‭JRE‬‭: Just the‬‭tools to eat‬‭– Food is ready, you don’t‬‭cook (only running)‬

‭●‬ ‭JVM‬‭: The‬‭chef‬‭inside the JRE – Interprets the bytecode‬‭(recipe) and cooks (runs code)‬

‭●‬ J
‭ IT‬‭: Chef’s‬‭memory‬‭– Learns which dishes are common‬‭and cooks them faster next‬
‭time (compiles frequently used bytecode)‬

🟢 1.5 Garbage Collection‬


‭🔹 What is Garbage Collection?‬

‭ hen your program creates objects, they take memory. If objects are no longer needed, Java‬
W
‭automatically frees that memory‬‭using‬‭Garbage Collector‬‭.‬

🔹 Why is it Needed?‬

free()‬‭or‬‭
I‭n C/C++, the programmer must manually free memory (using‬‭ delete‬
‭). If they‬
‭forget, memory leaks happen.‬

‭In Java:‬

‭●‬ ‭No need to worry about deleting objects‬

‭●‬ ‭JVM takes care of cleaning up unused memory‬

🔹 Example:‬

‭class Test {‬
‭public static void main(String args[]) {‬
‭String a = new String("Java"); // memory allocated‬
‭a = null; // object is now unreachable‬
‭[Link](); // request garbage collection‬
‭}‬
‭}‬

"Java"‬‭becomes unreachable. JVM will‬‭eventually remove it.‬


‭Here, the object‬‭

‭Prepared By: Nisha D. Desai‬ ‭UNIT : 1 INTRODUCTION‬‭TO JAVA‬ ‭4‬


🔹 How It Works Internally‬

‭1.‬ ‭JVM has a‬‭Heap memory‬‭to store objects.‬

‭2.‬ ‭It runs the‬‭Mark and Sweep‬‭algorithm:‬

‭○‬ ‭Mark‬‭: Find out which objects are still used‬

‭○‬ ‭Sweep‬‭: Delete all unused ones‬

‭3.‬ ‭This happens in the background, without disturbing your program.‬

🔹 Real-Life Analogy:‬

‭Imagine a‬‭cleaning robot (Garbage Collector)‬‭:‬

‭●‬ ‭You’re using a whiteboard (memory) to write ideas (objects).‬

‭●‬ ‭After you're done, old notes are no longer needed.‬

‭●‬ ‭The robot‬‭automatically‬‭erases‬‭unused sections‬‭to give you space.‬

‭Prepared By: Nisha D. Desai‬ ‭UNIT : 1 INTRODUCTION‬‭TO JAVA‬ ‭5‬

You might also like