java chapter 1

1. What is Java?

  • Java is a high-levelobject-oriented, and platform-independent programming language developed by James Gosling at Sun Microsystems in 1995.
  • Initially called Oak, later renamed Java.
  • Java programs are compiled into bytecode, which can run on any machine that has a Java Virtual Machine (JVM).

2. Features of Java

  1. Simple – Easy to learn and use.
  2. Object-Oriented – Everything is treated as an object.
  3. Platform-Independent – “Write Once, Run Anywhere” (WORA).
  4. Secure – No explicit pointers, runs inside JVM sandbox.
  5. Robust – Strong memory management and exception handling.
  6. Multithreaded – Supports multiple threads (parallel execution).
  7. Portable – Bytecode works across platforms.
  8. High Performance – Uses Just-In-Time (JIT) compiler.
  9. Distributed – Can be used for internet-based applications.

3. Java Editions

  • JSE (Java Standard Edition): Core Java for desktop applications.
  • JEE (Java Enterprise Edition): For web and enterprise applications.
  • JME (Java Micro Edition): For mobile and embedded devices.

4. Java Program Structure

Example:

class Hello {
    public static void main(String args[]) {
        System.out.println("Hello, World!");
    }
}

Explanation:

  • class → defines a class.
  • main() → entry point of Java program.
  • System.out.println() → displays output.

5. Java Compilation Process

  1. Write code → Hello.java
  2. Compile → javac Hello.java (creates Hello.class)
  3. Run → java Hello
  4. JVM executes bytecode.

6. Java Virtual Machine (JVM)

  • Converts bytecode into machine code.
  • Provides platform independence.
  • Handles memory management and garbage collection.

7. Tokens in Java

Basic building blocks:

  • Keywords (e.g., classpublicstaticifelse)
  • Identifiers (names of variables, classes, methods)
  • Literals (constants like 10"Hello")
  • Operators (+-*/%==, etc.)
  • Separators (;{}[]())
  • Comments (// for single-line, /* */ for multi-line)

8. Data Types in Java

  • Primitive: byte, short, int, long, float, double, char, boolean.
  • Non-Primitive: String, Arrays, Classes, Interfaces.

9. Variables and Constants

  • Variable: stores data value.int age = 18;
  • Constant: defined using final keyword.final double PI = 3.14;

10. Operators

  • ArithmeticRelationalLogicalAssignmentUnaryTernary, etc.

11. Input and Output in Java

import java.util.Scanner;
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println("Number = " + num);

🧾 In Short

  • Java = Simple + Object-Oriented + Platform Independent.
  • Code → Bytecode → JVM → Execution.
  • Java programs run safely and consistently across platforms.

Leave a Comment

Your email address will not be published. Required fields are marked *