Structure of a Java Program, Compilation and Features of Java (ISC Class 11)
Updated 17 October 2026 · Fact-checked
A Java program consists of a class containing methods, and execution starts at public static void main(String[] args). The source (.java) is compiled by javac into bytecode (.class), which the Java Virtual Machine runs on any platform. Features of Java include being simple, object oriented, platform independent, secure, robust and multithreaded. Errors may be syntax (compile-time), run-time or logical.

Notice that javac turns .java source into bytecode (.class), which any platform's JVM can run. This is why Java is platform independent.
Picture: Dcoetzee (File:Computer-blue.svg by OpenClipart, File:Phone-blackberry-bold.svg by User:Techtoucian) · CC0 · Wikimedia Commons
Notice that javac makes bytecode, not machine code, and only the JVM differs by platform, so one .class file runs everywhere.
Illustration drawn for QuestionBuddy.
Understand Structure of a Java Program, Compiling and Running, and Features of Java
Structure.
import java.util.*; // package imports
public class Circle { // class name = file name
public static void main(String[] args) {
double r = 7;
double area = 3.14 * r * r; // statements end with ;
System.out.println(area);
}
}Elements: comments (// and /* */), import statements, class declaration, the main method (public: callable by the JVM; static: runs without an object; void: returns nothing; String[] args: command-line arguments), statements ending with a semicolon, braces { } for blocks. Java is case-sensitive.
From algorithm to code. Define the problem; write an algorithm (step-by-step procedure) or flowchart; code it; compile; test; debug.
Compile and run. javac Circle.java creates Circle.class (bytecode, not machine code). java Circle starts the JVM, which interprets or compiles the bytecode for the machine. Because only the JVM is machine-specific, the same bytecode runs on Windows, Linux or macOS: "write once, run anywhere".
Features of Java. Simple (no pointers, automatic memory management); object oriented; platform independent and portable; secure (bytecode verification, no explicit pointers); robust (strong type checking, exception handling, garbage collection); multithreaded; high performance with just-in-time compilation; distributed.
Errors.
| Type | When found | Example |
|---|---|---|
| Syntax error | Compile time | missing semicolon; misspelled keyword |
| Run-time error | While running | division by zero (ArithmeticException) |
| Logical error | Wrong output | using + instead of * |
Debugging means finding and removing errors.
Structure of a Java Program, Compiling and Running, and Features of Java: key facts
- Compile and run
- javac File.java -> File.class (bytecode) | java File -> JVM runs it
- Two steps.
- main header
- public static void main(String[] args) | Entry point of a program
- Exact form.
- Error types
Syntax compile time Run-time during execution Logical wrong result - Classification.
How to answer Structure of a Java Program, Compiling and Running, and Features of Java questions
Check the structure first, then the logic.
- 1Is there a class and a main method with the correct header?
- 2Does every statement end with a semicolon and every brace match?
- 3Compile in your head: types, declarations, spellings.
- 4Then trace for run-time and logical errors.
Structure of a Java Program, Compiling and Running, and Features of Java in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Platform independence
Suppose a student writes a Java program on a Windows laptop and e-mails the compiled .class file to a friend with a Linux computer, who has Java installed.
Will it run and why?
Try it first, then show the solutionSolution
- The .class file contains bytecode, not Windows machine code.
- The friend's JVM understands bytecode on Linux, so it runs.
Answer: Yes, because bytecode runs on any JVM.
Memory hook: Bytecode travels; the JVM translates.
Tricks to remember Structure of a Java Program, Compiling and Running, and Features of Java
Short memory aids. Say each one aloud once, then use it on a question the same day.
Class, main, braces
Every program: class + main + matching braces.
Use it when: Structure.
javac makes class, java runs it
Compile then run.
Use it when: Steps.
Syntax stops compile, logic gives wrong answer
Three kinds of errors.
Use it when: Errors.
Structure of a Java Program, Compiling and Running, and Features of Java: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Bytecode · 1 mark · MCQBoard level
The output of the Java compiler is:
(a) source code (b) machine code (c) bytecode (d) HTML
Try it first, then show the solutionSolution
- javac produces bytecode in a .class file.
Answer: (c) bytecode
Example 2: Features · 4 marks · Short answerBoard level
State any four features of Java with a one-line reason for each. (4 marks)
Try it first, then show the solutionSolution
- Platform independent: bytecode runs on any JVM.
- Object oriented: programs are built from classes and objects.
- Robust: exception handling and garbage collection.
- Secure: no pointers; bytecode is verified.
Answer: Platform independent (bytecode on any JVM), object oriented, robust (exception handling) and secure (no pointers, bytecode verification).
Example 3: Output of a program · 4 marks · Short answerHarder board level
Give the output of the program in the concept (radius 7). Then give the output if the radius is changed to 10. Why is the second output printed as 314.0 and not 314? (4 marks)
Try it first, then show the solutionSolution
- Area = 3.14 x 7 x 7 = 153.86.
- With r = 10: 3.14 x 10 x 10 = 314.
- The variable area is a double, and println prints a double with a decimal part: 314.0.
Answer: 153.86 and 314.0 (a double is printed with its decimal point)
Example 4: Classify the errors · 4 marks · Short answerHarder board level
Classify each error and name when it is detected: (i) System.out.println("Hi") with the semicolon missing; (ii) int a = 10 / 0; (iii) a program that calculates the average as (a + b) / 3 for two numbers; (iv) writing System.Out.println. (4 marks)
Try it first, then show the solutionSolution
- (i) Syntax error: compile time.
- (ii) Run-time error (ArithmeticException): when run.
- (iii) Logical error: the program runs but the result is wrong.
- (iv) Syntax (compile) error: Out is not the member System.out.
Answer: (i) syntax, compile time; (ii) run-time; (iii) logical; (iv) syntax, compile time.
Example 5: Explain the main header · 5 marks · Long answerHOTS / competency
Explain each word of public static void main(String[] args). A student removes the word static: what happens, and why does the JVM need the others? (5 marks)
Try it first, then show the solutionSolution
- public: accessible to the JVM; static: belongs to the class so it can run without creating an object; void: returns no value; main: the name of the entry point; String[] args: command-line arguments.
- Without static the JVM cannot call main because no object exists when the program starts; the program compiles but fails at run time with an error that main is not found in the required form.
Answer: public (visible to the JVM), static (callable without an object), void (no return), main (entry point), String[] args (arguments). Without static the program cannot start.
Where students lose marks in Structure of a Java Program, Compiling and Running, and Features of Java
The slips examiners see most often, and what to write instead.
Mistake: Naming the file differently from the public class
Careless.
Wrong working
Circle.java contains public class Area
Right working
File name = public class name
Do this: Match them.
Usually costs: 1 mark.
Mistake: Calling bytecode machine code
Confusion.
Wrong working
javac gives machine code
Right working
javac gives bytecode
Do this: JVM turns it into machine code.
Usually costs: 1-2 marks.
Mistake: Missing main header detail
Memory.
Wrong working
public void main(String args)
Right working
public static void main(String[] args)
Do this: Learn the exact header.
Usually costs: 1-2 marks.
Exam tips
- Write the exact main header.
- Give an example for each error type.
- Explain platform independence through bytecode and the JVM.
Practice questions on Structure of a Java Program, Compiling and Running, and Features of Java
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
A missing semicolon at the end of a statement is a:
(a) logical error (b) run-time error (c) syntax error (d) no errorHint
Compile-time.
Answer
(c) syntax error
Q2 · 3 marks · Short answerBoard level
What is the JVM? State its role in making Java platform independent. (3 marks)
Hint
Bytecode runner.
Answer
The Java Virtual Machine is a program that executes bytecode on a particular machine. Since the same bytecode can run on any machine that has a JVM, Java programs are platform independent.
Q3 · 5 marks · Long answerHarder board level
Write a Java program to find and print the perimeter and area of a rectangle with length 12 and breadth 5, and state the output. (5 marks)
Hint
2(l + b) and l x b.
Answer
public class Rect { public static void main(String[] args) { int l = 12, b = 5; System.out.println(2 * (l + b)); System.out.println(l * b); } } Output: 34 then 60.
Q4 · 4 marks · Short answerHarder board level
A program is saved as Demo.java but contains public class demo { public static void main(String[] a) { int y = 4 * 2 System.out.println(y); } }. List all the errors and classify each. (4 marks)
Hint
Name, semicolon.
Answer
The public class name demo does not match the file name Demo.java (a compile-time error; Java is case-sensitive). The semicolon is missing after 4 * 2 (syntax error). If both were corrected, the output would be 8.
Q5 · 3 marks · Short answerHOTS / competency
A student claims "Java is slow because it is interpreted, so it is not suitable for large applications." Evaluate, referring to bytecode, JIT compilation and portability. (3 marks)
Hint
JIT compilers.
Answer
Java bytecode can be translated to machine code at run time by a just-in-time compiler, giving good speed. Its portability and robustness make it suitable for large applications; speed is therefore not a serious drawback.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.Java source file extension?Show answer
.java
2.Compiled file?Show answer
.class (bytecode).
3.Program entry point?Show answer
main.
4.Who runs bytecode?Show answer
The JVM.
5.Three error types?Show answer
Syntax, run-time, logical.
Structure of a Java Program, Compiling and Running, and Features of Java: frequently asked questions
Is Java case-sensitive?
Yes.
What are comments for?
To explain code; ignored by the compiler.
What is args?
Command-line arguments.
Can a file have more than one class?
Yes, but only one public class.