📖 Scenario: You are learning how Java programs are compiled and run. Understanding this flow helps you know what happens when you write and run Java code.
🎯 Goal: Build a simple Java program step-by-step to see how compilation and execution work together.
📋 What You'll Learn
Create a Java class with a main method
Declare a variable inside the main method
Print the variable value to the console
Understand the order of compilation and execution
💡 Why This Matters
🌍 Real World
Java programs are everywhere, from mobile apps to large servers. Knowing how to write and run Java code is the first step to building these applications.
💼 Career
Understanding Java compilation and execution is essential for software developers working with Java, enabling them to write, debug, and run programs effectively.
Progress0 / 4 steps
1
Create a Java class with a main method
Write a Java class named FlowDemo with a public static void main(String[] args) method. Leave the method body empty for now.
Java
Hint
The main method is the entry point for Java programs. It must be public static void main(String[] args).
2
Declare a variable inside the main method
Inside the main method, declare an integer variable named number and set it to 10.
Java
Hint
Use int number = 10; inside the main method to declare the variable.
3
Print the variable value to the console
Add a line inside the main method to print the value of number using System.out.println.
Java
Hint
Use System.out.println(number); to print the value to the console.
4
Run the program and see the output
Compile and run the FlowDemo class. The program should print 10 to the console.
Java
Hint
Use javac FlowDemo.java to compile and java FlowDemo to run the program in your terminal or command prompt.
Practice
(1/5)
1. What is the first step when running a Java program?
easy
A. Compile the Java source code into bytecode using javac
B. Run the bytecode directly using the java command
C. Convert bytecode into machine code manually
D. Write the Java source code in a text editor
Solution
Step 1: Understand Java program execution
Java source code must first be compiled into bytecode before running.
Step 2: Identify the compilation command
The javac command compiles source code into bytecode.
Final Answer:
Compile the Java source code into bytecode using javac -> Option A