#3 Write a First Code in JAVA | Skyhighes | Lecture 3

11 months ago
29

Ready to bring your Java dreams to life? Let's write your first code!

Here's your step-by-step guide:

1. Open a text editor or IDE:

Choose a comfortable environment for writing code. Popular options include:
Notepad++ (simple text editor)
Visual Studio Code (versatile with Java extensions)
IntelliJ IDEA (comprehensive Java IDE)
Eclipse (another popular Java IDE)
Image of different text editors and IDEs for JavaOpens in a new window
www.differencebetween.net
different text editors and IDEs for Java
2. Create a new file:

Name it HelloWorld.java (or any name you prefer, but keep the .java extension).
3. Type in the following code:

Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Use code with caution. Learn more
4. Save the file.

5. Compile the code:

Open a command prompt or terminal.
Navigate to the directory where you saved the file.
Type javac HelloWorld.java and press Enter. This compiles your code into Java bytecode.
6. Run the code:

Type java HelloWorld and press Enter. This executes the bytecode and displays the output.
Congratulations! You've just written and run your first Java program!

Let's break down the code:

public class HelloWorld { ... }: This line defines a class named HelloWorld. Classes are like blueprints for creating objects in Java.
public static void main(String[] args) { ... }: This is the main method, the entry point of your program. It's where execution begins.
System.out.println("Hello, World!");: This line prints the message "Hello, World!" to the console.
Now that you've mastered the basics, explore more Java concepts and start building awesome projects!

Loading comments...