Introduction to Java Programming
Why Do We Need Programming Languages?
• Communication with Computers: Programming languages allow humans to
• communicate instructions to computers in a way they can understand.
Java History
Home: SUN Mc Systems (Oracle Corporation)
Author: James Gosling
Objective: To prepare simple electronic consumer goods.
Project: Green
First Version: JDK 1.0 (1996, Jan-23rd)
Type of Software: Open-Source Software
purpose:
Originally made for devices like TV, remotes etc.
Why we learn java in 2025?
1. 90% 500 fortune companies used in for their BE dev
2. Amazon, Uber, Netflix use Java for their Backend
Java still is best choice for
1. Android
2. Banking and Fintech
3. Big data - Hadoop (java based)
4. Games
5. Cloud, devops
Why we learn java in 2025?
1. Secure and scalable(agar main abhi 10 logo k liy use kr raha hu to main ise 100 logo k
liy bhi kr sakta)
2. Most in demand --> high salary
3. BE systems ---> 90-95%
4. Morden tech --> kakfa, docker , kubernetes, AWS etc
5. Easy to learn
Domain Java role
Banking HDFC, ICICI core system
E-comm Amazon, Flipkart
Android 70% app
Payments Rozorpay, PhonePe backend in java
OTT platform Neflix
Gamming Minecraft
Space Tech NASA uses java for simulations
simulations
How Java Works Internally?
Internal of code execution
-----------------------------------
Case 1: Without JIT
Use interpreter and each instruction converted line by line
Case 2: With JIT
Code is compiled once and resued
What is JVM ?
1. Load .class file
2. Verify bytecode
3. Heap stack memory
4. JIT
What is JRE(Java runtime environment)
JRE = JVM + runtime lib
1. It provide necessary lib to run java app
2. Does not provide compilation (javac) JVM
JDK: java development kit
1. JDK = JRE + Development tools (javac, javadoc, jar)
2. Needed to develop & run java prog
3. Contains everything in JRE + compiler , debugger
What is JIT ?
part of jvm
Convert frequently used bytecode into machine code
Note:
JVM read line by line (interpreter) but If you repeat a task again n again, JIT says , Bhai Main kr
deta hu
and main ise yaad rakh lunga( cache ) then if you call the same code (hotcode) again then JIT will
if you mahine code from cache
Questions:
1. Is java is compiled lang or interpreted?
2. What is JVM and what it does?
3. Difference between JDK, JRE and JVM?
4. How JIT improve performance?
5. Can we run Java program with only JRE? Yes, if I have .class file
Differences between Java and Others
C and C++ are static programming languages but JAVA is dynamic programming language
• If any programming language allows memory allocation for primitive data types at
compilation time [Static Time] then that programming language is called as Static
Programming language
EX: C and C++.
• In C and C++ applications, memory will be allocated for primitive data types at compilation
time only, not at runtime.
• If any programming language allows memory allocation for primitive data types at
runtime, not at compilation time then that programming language is called as Dynamic
Programming Language.
EX: JAVA
• In java applications, memory will be allocated for primitive data types at runtime only, not
at compilation time.
• Note: In Java applications, memory will be allocated for primitive data types at the time of
creating objects only, in java applications, objects are created at runtime only
Pre-Processor is required in C and C++, but Pre-Processor is not required in Java:
In case of C and C++, the complete predefined library is provided in the form of header
files
If we want to use predefined library in C and C++ applications, we have to include header
files in C and C++ applications, for this, we have to use #include<> statement.
EX:
• #include<stdio.h>
• #include<conio.h>
• #include<math.h>
If we compile C and C++ applications then Pre-Processor will perform the following actions.
1) Pre-Processor will recognize all #include<> statement
2) Pre-Processor will take all the specified header files from #include<> statements.
3) If the specified header files are existed then Pre-Processor will load the specified header
files to the memory, this type of loading predefined library at compilation time is called as
"Static Loading"
Code Execution in C/C++
Code Execution in Java
4. C and C++ are platform dependent programming languages, but JAVA is platform
independent programming language
Platform Dependent vs. Platform Independent
Platform Dependent: A programming language that allows its applications to be compiled
and executed on the same operating system (e.g., C with .exe files).
Platform Independent: Java, with its .class files containing bytecode, can be executed on any
operating system.
What are the differences between .exe file and .class file?
Java Program Structure:
What is class?
A class is blueprint/template (CAR) from which individual object are created
Note : Why is everything in java inside class ?
Java is pure object-oriented programming lang that's why all thing wrap inside object
What is object ?
real world instance of class
running of instance of class
Class -> blue for CAR
Object -> Actual CAR built using the blueprint -> Harrier ,Brezza
Methods
• What It Is: Blocks of code that perform specific tasks.
• Why It's Used: Helps to organize code into reusable chunks.
• Note: The main method is the entry point of any Java program
Variables :
Data Types:
Identifiers:
Are the names given to class, variable, method and interfaces
Rules for naming identifiers
1. Valid char : lower case, Upper case , digit, _ , $
2. Start with : letter , _ , $ [it cannot start with digit]
3. Case sensitive : car, CAR, CaR
4. Reserved keyword : (int, for, if else)
What is type casting?
There are two type of casting:
Implicit casting: cast data type from lower to upper
Explicit casting: upper data type into lower, chances of losing data