Why learn Java in Class 9?
Imagine a robot that can follow your instructions no matter which playground it’s on. That’s what Java does for computers – it runs everywhere.
Java is a programming language that lets you tell a computer what to do. Think of it as a set of clear, step‑by‑step recipes that the computer follows, just like you follow a cooking recipe.
What is Java?
Java is a high‑level (easy‑to‑read) programming language created by Sun Microsystems in 1995. It’s called "high‑level" because you write code that looks more like English than machine code.
Two big ideas make Java special:
- Write Once, Run Anywhere – You write the code once, then it can run on any device that has a Java Virtual Machine (JVM). Think of a DVD that plays on any DVD player.
- Object‑Oriented – Java treats everything as an "object", which is a tiny bundle of data and actions, like a LEGO brick that has its own shape and the way it can connect.
How does Java run?
When you write Java code, you save it in a .java file. The javac compiler turns that file into a .class file filled with bytecode – a special set of instructions the JVM understands.
The JVM is like a translator that sits between the bytecode and the computer’s hardware. It reads the bytecode and tells the computer what to do, so the same program works on Windows, macOS, or Android.
Writing your first program
Let’s start with the classic "Hello, World!" program. Open any text editor, type the code below, and save it as HelloWorld.java:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Here’s what each part means:
- public class HelloWorld – declares a class named
HelloWorld. A class is a blueprint for objects. - public static void main(String[] args) – the main method. This is the entry point where Java starts running your code.
- System.out.println – a command that prints text to the screen.
From code to output: the compile‑run cycle
To see the program work, you have to compile and then run it. Follow these four steps:
If the compiler finds mistakes, it will show error messages. Fix them, then try again.
Core concepts you’ll need
These are the building blocks that appear in most ICSE questions.
- Variables – containers that store data, like a box labeled "age" that holds a number.
- Data types – tell Java what kind of data a variable holds (int for whole numbers, double for decimals, char for single characters, boolean for true/false).
- Operators – symbols that perform actions, such as
+for addition or==to compare two values. - Control statements – let you decide which path the program takes, like
if‑else(choose one road) or loops (for,while) that repeat actions. - Methods – reusable chunks of code that perform a specific task, similar to a kitchen appliance that does one job repeatedly.
Java at a glance – quick comparison
| Feature | What it means for you |
|---|---|
| Platform independent | Write once, run on any computer with JVM |
| Object‑oriented | Think in terms of objects, makes big programs easier to manage |
| Strongly typed | Every variable has a fixed type, helps catch mistakes early |
| Rich standard library | Lots of ready‑made tools (like math functions) so you don’t reinvent the wheel |
| Automatic memory management | Garbage collector cleans up unused objects, you don’t free memory manually |
Tips for ICSE exams
- Memorise the exact syntax of the
mainmethod – the exam loves to ask it. - Practice writing short programs that use variables, loops, and if‑else.
- When you get a compilation error, read the line number carefully; most mistakes are typos.
- Use proper indentation; it makes your code readable and reduces logical errors.
📝 Likely Exam Questions
- Write a Java program to print the sum of two integers entered by the user.
Answer: Show code usingScannerto read input andSystem.out.printlnfor output. - Explain the purpose of the
mainmethod in a Java program.
Answer: It is the entry point where the JVM starts executing the program. - What is meant by “Write Once, Run Anywhere” in Java?
Answer: Java code is compiled to bytecode, which the JVM interprets on any platform, so the same program runs on Windows, Linux, etc. - Differentiate between
intanddoubledata types with examples.
Answer:intstores whole numbers (e.g., 5),doublestores decimal numbers (e.g., 5.75). - Write a short method named
squarethat returns the square of an integer.
Answer: Provide method code:public static int square(int n){ return n*n; }.