Java Programming
5. What Are .java and .class Files?
.java file:
• Contains Java source code.
• Written by the programmer.
• Human-readable.
• Compiled using javac.
.class file:
• Contains compiled Java bytecode.
• Generated by the Java compiler.
• Executed by the JVM.
6. Basic Java Program Structure
Let's understand the previous program line by line.
Explanation:
• public: Access modifier.
• class: Used to define a class.
• HelloWorld: Name of the class.
• static: Allows the main method to be called without creating an object.
• void: Means the method does not return a value.
• main(): Entry point of a traditional Java application.
• String[] args: Accepts command-line arguments.
• System.out.println(): Prints output to the console.
7. What is the main() Method?
The main method is the traditional entry point of a standalone Java application.
Syntax:
public static void main(String[] args) {
// Your code goes here
}
When you run a standard Java application, the JVM looks for an appropriate main method to start execution.
8. Your First Java Practice Programs
Try writing these programs yourself:
• Print your name.
• Print your age.
• Display your favourite programming language.
• Print your name, city and profession on separate lines.
• Print the sum of two numbers.
public class Practice {
public static void main(String[] args) {
System.out.println("My name is Rahul");
System.out.println("I am learning Java");
System.out.println("Java is interesting!");
}
}
Important Takeaways
• Java is a high-level, object-oriented programming language.
• Java was officially released in 1995.
• JDK is used to develop Java applications.
• JRE provides the runtime environment.
• JVM executes Java bytecode.
• .java files contain source code.
• .class files contain bytecode.
• main() is the traditional entry point of a Java application.
Double Tap ❤️ For Part-2
❤1
49 ·