Java is famous for "write once, run anywhere." That magic comes from how Java code is compiled and run. This chapter explains the Java environment (ICSE Class 9).
1Types of Java programs
Java programs come in two kinds:
| Standalone application | Applet | |
|---|---|---|
| Runs | On its own, on your computer | Inside a web browser/web page (older technology) |
| Has main()? | Yes | No (browser controls it) |
| Example | A calculator program | A small animation embedded in a page |
For your course you'll write standalone applications (run in BlueJ/an IDE). Applets are mostly historical now but are part of the syllabus to know about.
Key points
- A standalone application runs on its own and has a main() method.
- An applet runs inside a web browser (older technology) and has no main().
- You'll write standalone applications in this course.
2Compilation, bytecode & the JVM
Running a Java program takes three forms of the code:
Source code --> Bytecode --> Machine code
(Hello.java) (Hello.class) (runs on your CPU)
| | |
you write javac compiler the JVM- Source code — what you write (a
.javafile), in human-readable Java. - The compiler (
javac) turns it into bytecode (a.classfile) — a special intermediate code, not for any one machine. - The JVM (Java Virtual Machine) reads the bytecode and converts it to machine code for whatever computer it's running on.
The JVM is why Java is platform independent: the SAME bytecode runs on Windows, Mac or Linux, because each has its own JVM that translates it. "Write once, run anywhere."
Key points
- Source code (.java) → compiler (javac) → bytecode (.class) → JVM → machine code.
- Bytecode is an intermediate code, not tied to any one machine.
- The JVM converts bytecode to machine code, making Java platform independent.
3Salient features of Java
Java's popularity comes from several features:
| Feature | Means |
|---|---|
| Simple | Clean syntax; easier than C++ (no pointers to manage) |
| Object-Oriented | Everything is organised around classes and objects |
| Platform Independent | Bytecode runs on any machine with a JVM |
| Robust | Strong error checking and automatic memory management (garbage collection) |
| Secured | Runs in a controlled environment; helps keep systems safe |
Key points
- Java is simple, object-oriented and platform independent (via the JVM).
- It is robust (strong error checking, automatic memory management) and secured.
- Platform independence comes from bytecode + the JVM.
★ Practical: trace the journey
Answer in your own words:
- Name the three forms your code takes from writing to running.
- Which tool turns source code into bytecode, and what file does it create?
- Explain in one line why Java is called platform independent.
- Give two salient features of Java.
Ready for the chapter test?
Answer 5 questions. Score 60% or more to mark this chapter complete.
Start the test →💡 Log in to save your progress and earn the certificate.