Introduction to Java
An Overview of Java’s Evolution, Core Components, and Basic Program Structure

History of Java
1991 → Project started by James Gosling and team at Sun Microsystems
Initially named "Oak" after a tree near Gosling's office
Later renamed "Green" and finally "Java" after Java coffee
1995 → First public release of Java 1.0
Known for "Write Once, Run Anywhere" (WORA) — platform independence
1997 → Java Community Process (JCP) started for collaboration & standardization
JDK 1.1 released with major features like JavaBeans and JDBC
JVM standardized to ensure platform-independent execution
1998 → Release of Java 2 (J2SE 1.2), a major milestone
Introduced different editions: J2SE (Standard), J2EE (Enterprise), J2ME (Mobile)
2006 onwards → Naming changed to Java SE (Standard Edition), Java EE (Enterprise), Java ME (Mobile)
JDK, JVM, and JRE

JVM (Java Virtual Machine): The core runtime component that interprets compiled Java bytecode and translates it into machine-specific instructions. It manages memory, security, garbage collection, and provides a platform-independent execution environment.
JRE (Java Runtime Environment): Includes the JVM along with standard libraries and classes required to run Java applications. It does not include development tools like a compiler or debugger. JRE is for executing Java programs only.
JDK (Java Development Kit): This package includes the JRE plus development tools such as the Java compiler (
javac), debugger, and other utilities required for writing, compiling, and debugging Java applications.
How a Java Program is Run
Running a Java program involves several steps:
Writing the Source Code: Create a
.javafile with Java source code.Compilation: The
javaccompiler converts the source code into bytecode, a platform-independent intermediate format, stored in.classfiles.Loading: The JVM loads the bytecode into memory.
Verification: JVM verifies the bytecode to ensure it is valid and secure.
Execution: The JVM interprets or just-in-time compiles the bytecode into native machine code and runs the program.
Skeleton of a Java Program
import java.lang.*; // It will automatically be imported even if we don't import it
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
public: Access modifier, means the class/method is accessible from anywhere.class: Defines a class namedHelloWorld.static: Means the method belongs to the class, not a specific instance. To use main method without creating an object of the class we use static here.void: The method returns no value.main: Entry point of any standalone Java application.String[] args: An array of command-line arguments.System.out.println: Prints text to the console.Systemis a built-in class in the Java standard library (java.langpackage).outis a static variable inside theSystemclass which points to an object of typePrintStream.printlnis a method that belongs to thePrintStreamclass
Reading from Keyboard
The Scanner class in java.util package is used to read user inputs from various sources, including the keyboard.
Example
import java.util.Scanner;
public class InputExample {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // Create Scanner object
System.out.print("Enter your name: ");
String name = input.nextLine(); // Reads a line of text
System.out.println("Hello, " + name);
input.close(); // Close the scanner
}
}
Scanner input = new Scanner(System.in); creates a Scanner object to read input from the keyboard
Methods:
next(): Reads and returns the next single token (word) as a String.nextLine(): Reads and returns an entire line of input as a String.nextInt(): Reads the next token as anintvalue.nextDouble(): Reads the next token as adoublevalue.nextFloat(): Reads the next token as afloatvalue.nextLong(): Reads the next token as alongvalue.nextShort(): Reads the next token as ashortvalue.nextByte(): Reads the next token as abytevalue.nextBoolean(): Reads the next token as abooleanvalue.hasNext(): Checks if there is another token available.hasNextLine(): Checks if there is another line available.Similarly
hasNextInt(),hasNextFloat(), etc.useRadix(int radix):Sets the default number base (radix) the scanner uses to interpret numeric input (e.g., decimal, hexadecimal). If radix = 2 then the input will be taken in Binary.close(): Closes the Scanner object, freeing resources.



