Program Structure in Java - Detailed Notes
1. Introduction to Java Program Structure
A Java program is organized into classes, methods, statements, and packages.
Java follows an object-oriented approach where every program is built around classes and
objects.
The Java Virtual Machine (JVM) executes compiled Java bytecode.
2. Basic Structure of a Java Program
Components:
• Documentation/Comments
• Package Statement
• Import Statements
• Interface Section (optional)
• Class Definition
• Main Method
• Variables and Statements
• Methods and Objects
3. Comments in Java
Single-line: // comment
Multi-line: /* comment */
Documentation: /** comment */
4. Package Statement
Packages organize related classes and interfaces.
Syntax:
package packagename;
5. Import Statement
Used to access predefined classes and packages.
Example:
import [Link];
6. Class Definition
A class is a blueprint for creating objects.
Syntax:
class ClassName {
// data members and methods
}
7. Main Method
Entry point of every Java application.
Syntax:
public static void main(String[] args) {
// code
}
8. Explanation of Main Method Keywords
public – accessible from anywhere
static – called without creating object
void – returns no value
main – JVM-recognized method name
String[] args – command-line arguments
9. Variables and Data Types
Primitive Types: byte, short, int, long, float, double, char, boolean.
Reference Types: Arrays, Classes, Interfaces, Strings.
10. Statements and Blocks
Java statements perform actions.
Blocks are enclosed within { } and group statements together.
11. Methods in Java
Methods define behavior of objects.
Syntax:
returnType methodName(parameters) {
// code
}
12. Objects and Classes
Objects are instances of classes.
Example:
Student s = new Student();
13. Command Line Arguments
Arguments passed during program execution are stored in String[] args.
14. Java Program Execution Process
1. Write Source Code (.java)
2. Compile using javac
3. Generate Bytecode (.class)
4. JVM executes bytecode
5. Output produced
15. Sample Java Program
class HelloWorld {
public static void main(String[] args) {
[Link]("Hello World");
}
}
16. JVM, JRE, and JDK
JVM: Executes bytecode.
JRE: JVM + libraries.
JDK: JRE + development tools.
17. Coding Standards
Use meaningful names, proper indentation, comments, and follow Java naming conventions.
18. Advantages of Structured Java Programs
Readability, Maintainability, Reusability, Scalability, and Easy Debugging.