
Java Programming Language – Complete Overview
Introduction
Java is a general-purpose, high-level, object-oriented programming language originally developed by James Gosling and his team at Sun Microsystems in 1995. It was designed to be simple, secure, portable, and platform-independent. Today, Java is one of the most widely used programming languages in the world for enterprise applications, web development, mobile applications, cloud computing, and large-scale systems.
The main philosophy of Java is:
“Write Once, Run Anywhere (WORA)”
This means Java programs can run on any system that has a Java Virtual Machine (JVM).
History of Java
- 1991: Project Green started by Sun Microsystems.
- 1995: Java officially released.
- 2009: Oracle acquired Sun Microsystems.
- Present: Oracle continues Java development with regular updates.
Java was initially designed for consumer electronic devices but later became popular for internet and enterprise applications.
Features of Java
1. Platform Independent
Java source code is compiled into bytecode, which can run on any operating system using the JVM.
2. Object-Oriented
Java follows object-oriented principles:
- Class
- Object
- Inheritance
- Encapsulation
- Polymorphism
- Abstraction
3. Simple
Java removes many complex features found in C++ such as:
- Multiple inheritance through classes
- Operator overloading
- Explicit pointer manipulation
4. Secure
Java provides:
- Bytecode verification
- Security manager
- No direct memory access
- Automatic memory management
5. Robust
Java offers:
- Exception handling
- Strong memory management
- Type checking
6. Multithreaded
Java supports multiple threads running simultaneously.
7. Distributed
Java supports networking and distributed computing.
8. High Performance
Modern JVMs use Just-In-Time (JIT) compilation for faster execution.
9. Dynamic
Java can load classes during runtime.
Java Architecture
Java architecture consists of:
Source Code
Written by programmers in .java files.
Compiler
Converts source code into bytecode (.class files).
JVM (Java Virtual Machine)
Executes bytecode.
JRE (Java Runtime Environment)
Contains:
- JVM
- Libraries
- Runtime files
JDK (Java Development Kit)
Contains:
- JRE
- Compiler
- Debugging tools
- Development utilities
Relationship:
JDK > JRE > JVM
Java Program Structure
Every Java program generally contains:
- Package
- Import statements
- Class definition
- Main method
- Variables and methods
Example structure:
Package
Import
Class
{
Variables
Methods
Main Method
}
Data Types in Java
Primitive Data Types
Integer Types
- byte (1 byte)
- short (2 bytes)
- int (4 bytes)
- long (8 bytes)
Floating Types
- float (4 bytes)
- double (8 bytes)
Character Type
- char (2 bytes)
Boolean Type
- boolean (true/false)
Non-Primitive Data Types
- String
- Arrays
- Classes
- Interfaces
- Collections
Variables in Java
Local Variable
Declared inside methods.
Instance Variable
Declared inside class but outside methods.
Static Variable
Shared among all objects.
Operators in Java
Arithmetic Operators
- /
- %
Relational Operators
- ==
- !=
- <
- =
- <=
Logical Operators
- &&
- ||
- !
Assignment Operators
- =
- +=
- -=
- *=
- /=
Increment/Decrement
- ++
Bitwise Operators
- &
- |
- ^
- ~
- <<
Control Statements
Decision Making
if
Executes code if condition is true.
if-else
Provides alternative execution.
else-if ladder
Handles multiple conditions.
switch
Selects one block among many.
Looping Statements
for loop
Repeats code fixed number of times.
while loop
Repeats while condition is true.
do-while loop
Executes at least once.
Enhanced for loop
Used for arrays and collections.
Arrays in Java
Array stores multiple values of the same type.
Types:
- One-dimensional array
- Two-dimensional array
- Multi-dimensional array
Advantages:
- Fast access
- Organized storage
Limitations:
- Fixed size
Methods in Java
A method is a block of code performing a specific task.
Types:
Predefined Methods
Provided by Java libraries.
User-Defined Methods
Created by programmers.
Object-Oriented Programming (OOP)
Class
Blueprint for creating objects.
Object
Instance of a class.
Encapsulation
Binding data and methods together.
Benefits:
- Security
- Data hiding
Inheritance
Allows one class to inherit properties from another.
Types:
- Single
- Multilevel
- Hierarchical
Java supports multiple inheritance through interfaces.
Polymorphism
One action, many forms.
Types:
Compile-Time Polymorphism
Method overloading.
Runtime Polymorphism
Method overriding.
Abstraction
Showing essential features while hiding implementation details.
Achieved using:
- Abstract classes
- Interfaces
Constructors
Special methods used to initialize objects.
Types:
Default Constructor
Created automatically.
Parameterized Constructor
Accepts parameters.
Copy Constructor
Created manually in Java.
this Keyword
Refers to the current object.
Uses:
- Access instance variables
- Call constructors
- Pass current object
super Keyword
Refers to parent class.
Uses:
- Access parent variables
- Access parent methods
- Call parent constructor
Static Keyword
Belongs to class rather than objects.
Can be used with:
- Variables
- Methods
- Blocks
- Nested classes
Final Keyword
Used to restrict modification.
final variable
Cannot change value.
final method
Cannot override.
final class
Cannot inherit.
String Handling
String represents text.
Important methods:
- length()
- charAt()
- substring()
- equals()
- compareTo()
- toUpperCase()
- toLowerCase()
- replace()
Exception Handling
Used to handle runtime errors.
Keywords:
- try
- catch
- finally
- throw
- throws
Types:
Checked Exceptions
Checked at compile time.
Examples:
- IOException
- SQLException
Unchecked Exceptions
Occur at runtime.
Examples:
- ArithmeticException
- NullPointerException
Collections Framework
Provides dynamic data structures.
List
Stores ordered elements.
Examples:
- ArrayList
- LinkedList
- Vector
Set
Stores unique elements.
Examples:
- HashSet
- LinkedHashSet
- TreeSet
Queue
FIFO structure.
Examples:
- PriorityQueue
- ArrayDeque
Map
Stores key-value pairs.
Examples:
- HashMap
- LinkedHashMap
- TreeMap
Multithreading
Allows multiple tasks to run concurrently.
Benefits:
- Better CPU utilization
- Faster execution
Thread creation:
- Extend Thread class
- Implement Runnable interface
Important methods:
- start()
- run()
- sleep()
- join()
Synchronization
Controls access to shared resources.
Benefits:
- Prevents data inconsistency
- Avoids race conditions
File Handling
Used for reading and writing files.
Classes:
- File
- FileReader
- FileWriter
- BufferedReader
- BufferedWriter
Operations:
- Create file
- Read file
- Write file
- Delete file
Java Packages
Package is a collection of related classes.
Advantages:
- Organization
- Namespace management
- Access protection
Types:
- Built-in packages
- User-defined packages
Java Interfaces
Interface contains abstract methods and constants.
Benefits:
- Multiple inheritance
- Loose coupling
Abstract Classes
Cannot be instantiated directly.
Can contain:
- Abstract methods
- Concrete methods
Java Memory Management
Memory Areas:
Method Area
Stores class information.
Heap Memory
Stores objects.
Stack Memory
Stores method calls and local variables.
PC Register
Stores current instruction.
Native Method Stack
Handles native methods.
Garbage Collection
Automatically removes unused objects from memory.
Benefits:
- Reduces memory leaks
- Simplifies memory management
Common collectors:
- Serial GC
- Parallel GC
- G1 GC
- ZGC
JDBC (Java Database Connectivity)
Used to connect Java applications with databases.
Steps:
- Load driver
- Create connection
- Create statement
- Execute query
- Process results
- Close connection
Supported databases:
- MySQL
- PostgreSQL
- Oracle Database
- SQL Server
Java Frameworks
Popular frameworks:
Spring
Enterprise application development.
Spring Boot
Rapid application development.
Hibernate
ORM framework.
Struts
Web framework.
JSF
Java Server Faces.
Java Technologies
Java SE
Standard Edition.
Java EE (Jakarta EE)
Enterprise applications.
Java ME
Mobile and embedded systems.
Applications of Java
- Enterprise software
- Banking systems
- E-commerce platforms
- Android applications
- Cloud applications
- Web services
- Desktop software
- Big data processing
- IoT systems
- Scientific applications
Advantages of Java
- Platform independent
- Secure
- Robust
- Object-oriented
- Large community
- Rich libraries
- Multithreading support
- Automatic memory management
Disadvantages of Java
- Higher memory consumption
- Slower than some native languages like C/C++
- Verbose syntax
- Startup time can be slower
Current Importance of Java
Java remains one of the most demanded programming languages because it powers:
- Enterprise systems
- Banking software
- Financial applications
- Android ecosystems
- Cloud-native applications
- Large-scale backend systems
