JAVA PROGRAMMING
Class Notes & Study Guide
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Topics Covered:
Lecture 1 — Introduction to Java & OOP
Lecture 2 — Variables, Data Types & Type Casting
Lecture 3 — Classes, Objects & Conditionals
Lecture 4 — Variable Types, Strings, Scanner & Arrays
Lecture 5 — Loops
Lecture 6 — Encapsulation, Inheritance
Lecture 7— Association
Lecture 8 — Polymorphism
Lecture 9 — Abstraction
Lecture 10 — Final Keyword
Lecture 11 — Interface
Lecture 12 —User Defined Package
Lecture 13 — Exception Handling
Lecture 14 — File I/O in Java
Lecture 15 — Graphical User Interface (GUI)
Lecture 16 — Class Practice
Lecture 1 — Introduction to Java
1.1 History of Programming Languages
Programming languages evolved over decades:
Era Trend Examples
1950s High-level languages born Assembly, Fortran
1960s Specialised languages Simula, Lisp, COBOL
1970s Structured programming C, Pascal
1980s Object-oriented experiments Smalltalk, C++
1990s OOP goes mainstream Java, Python, PHP
2000s Internet programming C#, Scala
2010s Concurrency & async JavaScript, Go
,1.2 The Creation of Java
• Conceived by James Gosling et al. at Sun Microsystems in 1991
• First working version took 18 months to develop
• Originally called "Oak"; renamed Java in 1995
• Primary goal: platform-independent language ("Write Once, Run Anywhere")
1.3 What is OOP?
Object-Oriented Programming (OOP) organises programs around objects — entities that combine state (data)
and behaviour (methods).
💡 Key OOP Pillars
Encapsulation • Inheritance • Abstraction • Polymorphism
1.4 Why OOP over Procedural?
The old Process-Oriented model organised code as linear steps acting on shared global data. Problems arose as
programs grew:
• Any function could accidentally corrupt global data
• No data security — everything was exposed
• Hard to map to real-world entities
OOP solves this by binding data tightly to the methods that use it, protecting it from accidental modification.
1.5 JVM, JRE & JDK
• JDK (Java Development Kit) — full toolkit: compiler (javac), JVM, libraries
• JVM (Java Virtual Machine) — runs bytecode; enables platform independence
• JRE (Java Runtime Environment) — JVM + libraries needed to run Java apps
🔄 Compilation Flow
.java source → javac compiler → .class bytecode → JVM executes
1.6 Hello World
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Compile: javac HelloWorld.java Run: java HelloWorld
Lecture 2 — Variables, Data Types & Type Casting
2.1 Variables
A variable is a named storage location in memory. Each variable has a type and a unique identifier.
String name = "Aman";
int age = 30;
String friend = "Akku";
, 2.2 Primitive Data Types
Fixed-size, built-in types stored directly in memory:
Data Type Size Range / Notes Default
byte 1 byte -128 to 127 0
short 2 bytes -32,768 to 32,767 0
int 4 bytes -2,147,483,648 to 2,147,483,647 0
long 8 bytes -9.2×10¹⁸ to 9.2×10¹⁸ 0L
float 4 bytes Up to 7 decimal digits 0.0F
double 8 bytes Up to 16 decimal digits 0.0
char 2 bytes '\u0000' to '\uFFFF' (Unicode) '\u0000'
boolean 1 byte true or false false
2.3 Non-Primitive (Reference) Data Types
Variable-size types that reference objects in heap memory. Declared with the new keyword.
String name = new String("Aman"); // String object
int[] marks = new int[3]; // Integer array
marks[0] = 97;
marks[1] = 98;
marks[2] = 95;
2.4 Constants
Use the final keyword to declare a constant — its value cannot change after assignment.
final float PI = 3.14F;
final int MAX_SIZE = 100;
2.5 Wrapper Classes
Every primitive has a corresponding wrapper class in java.lang that provides useful utility methods.
Primitive Type Wrapper Class
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
Common uses: Integer.parseInt("42") → 42 Double.parseDouble("3.14") → 3.14
2.6 Type Casting
Class Notes & Study Guide
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Topics Covered:
Lecture 1 — Introduction to Java & OOP
Lecture 2 — Variables, Data Types & Type Casting
Lecture 3 — Classes, Objects & Conditionals
Lecture 4 — Variable Types, Strings, Scanner & Arrays
Lecture 5 — Loops
Lecture 6 — Encapsulation, Inheritance
Lecture 7— Association
Lecture 8 — Polymorphism
Lecture 9 — Abstraction
Lecture 10 — Final Keyword
Lecture 11 — Interface
Lecture 12 —User Defined Package
Lecture 13 — Exception Handling
Lecture 14 — File I/O in Java
Lecture 15 — Graphical User Interface (GUI)
Lecture 16 — Class Practice
Lecture 1 — Introduction to Java
1.1 History of Programming Languages
Programming languages evolved over decades:
Era Trend Examples
1950s High-level languages born Assembly, Fortran
1960s Specialised languages Simula, Lisp, COBOL
1970s Structured programming C, Pascal
1980s Object-oriented experiments Smalltalk, C++
1990s OOP goes mainstream Java, Python, PHP
2000s Internet programming C#, Scala
2010s Concurrency & async JavaScript, Go
,1.2 The Creation of Java
• Conceived by James Gosling et al. at Sun Microsystems in 1991
• First working version took 18 months to develop
• Originally called "Oak"; renamed Java in 1995
• Primary goal: platform-independent language ("Write Once, Run Anywhere")
1.3 What is OOP?
Object-Oriented Programming (OOP) organises programs around objects — entities that combine state (data)
and behaviour (methods).
💡 Key OOP Pillars
Encapsulation • Inheritance • Abstraction • Polymorphism
1.4 Why OOP over Procedural?
The old Process-Oriented model organised code as linear steps acting on shared global data. Problems arose as
programs grew:
• Any function could accidentally corrupt global data
• No data security — everything was exposed
• Hard to map to real-world entities
OOP solves this by binding data tightly to the methods that use it, protecting it from accidental modification.
1.5 JVM, JRE & JDK
• JDK (Java Development Kit) — full toolkit: compiler (javac), JVM, libraries
• JVM (Java Virtual Machine) — runs bytecode; enables platform independence
• JRE (Java Runtime Environment) — JVM + libraries needed to run Java apps
🔄 Compilation Flow
.java source → javac compiler → .class bytecode → JVM executes
1.6 Hello World
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Compile: javac HelloWorld.java Run: java HelloWorld
Lecture 2 — Variables, Data Types & Type Casting
2.1 Variables
A variable is a named storage location in memory. Each variable has a type and a unique identifier.
String name = "Aman";
int age = 30;
String friend = "Akku";
, 2.2 Primitive Data Types
Fixed-size, built-in types stored directly in memory:
Data Type Size Range / Notes Default
byte 1 byte -128 to 127 0
short 2 bytes -32,768 to 32,767 0
int 4 bytes -2,147,483,648 to 2,147,483,647 0
long 8 bytes -9.2×10¹⁸ to 9.2×10¹⁸ 0L
float 4 bytes Up to 7 decimal digits 0.0F
double 8 bytes Up to 16 decimal digits 0.0
char 2 bytes '\u0000' to '\uFFFF' (Unicode) '\u0000'
boolean 1 byte true or false false
2.3 Non-Primitive (Reference) Data Types
Variable-size types that reference objects in heap memory. Declared with the new keyword.
String name = new String("Aman"); // String object
int[] marks = new int[3]; // Integer array
marks[0] = 97;
marks[1] = 98;
marks[2] = 95;
2.4 Constants
Use the final keyword to declare a constant — its value cannot change after assignment.
final float PI = 3.14F;
final int MAX_SIZE = 100;
2.5 Wrapper Classes
Every primitive has a corresponding wrapper class in java.lang that provides useful utility methods.
Primitive Type Wrapper Class
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
Common uses: Integer.parseInt("42") → 42 Double.parseDouble("3.14") → 3.14
2.6 Type Casting