Introduction to Java · Introduction to Java Programming

Important Classes

Watch lectures

Important Classes

1. Which Classes Matter First

Beginners use 5 classes for 90% programs: String, System, Scanner, Math, ArrayList. All come free with JDK — just import where needed (java.lang auto-imported).

Class Package One-line use
String java.lang text: "hello".length()
System java.lang System.out.println(), System.in
Scanner java.util keyboard input
Math java.lang Math.sqrt(16), Math.max(a,b)
ArrayList java.util resizable list

2. Code — All Five Together

import java.util.Scanner;
import java.util.ArrayList;

public class Demo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in); // System.in = keyboard
        System.out.print("Enter name: ");
        String name = sc.nextLine();          // String class
        System.out.println("Hi " + name + ", len=" + name.length());
        System.out.println("sqrt(16)=" + Math.sqrt(16)); // Math class
        ArrayList<String> list = new ArrayList<>();      // resizable array
        list.add(name);
        System.out.println(list);
        sc.close();
    }
}

3. Beginner Traps

  • java.lang needs no import (String, System, Math). java.util needs import (Scanner, ArrayList).
  • System.out is print; System.in is input; System.err is error print.
  • Close Scanner on System.in once at end.

4. Exam Points

  • List 5 important classes + package + one method — 5 marks, frequent.
  • Which package needs import vs auto — 3 marks, frequent.
Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.

← All Introduction to Java Programming modules