RL

Introduction to Java

🔹 Java Overview

Keypoints:

  • High-level, multi-platform, object-oriented programming language.

  • Created by Sun Microsystems in 1995.

  • Common uses: web apps, mobile apps, enterprise systems, AI, IoT, big data, cloud computing.

Importance:

  • Write once, run anywhere (WORA).

  • Widely used with huge community support.

Example:

  • Apps like Minecraft and Android applications are built with Java.


🔹 Java Runtime Environment (JRE)

Keypoints:

  • Provides class libraries & resources needed for Java programs to run.

  • Needed on any device that executes Java apps.

Advantages of Java:

  1. Active community & support.

  2. Many learning resources.

  3. Built-in functions & libraries.

  4. Strong security system.

  5. Platform independence (WORA).


🔹 Java Virtual Machine (JVM)

Keypoints:

  • Runtime engine that executes Java programs.

  • Converts Java bytecode → machine language.

  • Combines compiler + interpreter.

Process:

  1. Source code (.java file).

  2. Compiler → converts to bytecode.

  3. Interpreter (java.exe) → executes line by line on OS.

Importance:

  • Makes Java cross-platform.


🔹 Java APIs

Keypoints:

  • APIs = pre-written Java classes & methods.

  • Add ready-made functionalities (e.g., date, math, text manipulation).

  • Java has ~50 keywords but thousands of API classes/methods.

Example:

  • Math.sqrt(25) → uses API method to calculate square root.


🔹 Java Skeleton Program

Example Code:

class Skeleton {
    public static void main(String[] args){
        System.out.println("First Java Application"); //for display
    }
}

Key Concepts:

  • class = blueprint of objects.

  • Identifiers = names for classes, objects, variables (rules: start with letter/_/$, case-sensitive, no reserved words).

  • Reserved words = keywords like class, public, static, void.

Main Method Breakdown:

  • public → makes method accessible.

  • static → can run without creating an object.

  • void → no return value.

  • main(String[] args) → entry point of program.

Other Notes:

  • String = sequence of characters.

  • Array = collection of same data types.

  • Comments:

    • // single line

    • /* multi-line */


🔹 Saving, Compiling & Running Java Programs

Steps:

  1. Write program in text editor (e.g., Notepad).

  2. Save as .java file (e.g., Demo.java).

  3. Open Command Prompt (cmd).

  4. Set JDK path → set path=%path%;[JDK bin directory].

  5. Compile → javac Demo.java.

  6. Run → java Demo.

Output Example:

First program in Java

Importance:

  • Basic workflow every Java programmer must know.