0% found this document useful (0 votes)
5 views3 pages

First Java Program-explained

This document provides a step-by-step guide to creating a basic 'Hello, World!' program in Java. It includes instructions for writing, compiling, and running the program, along with explanations of the code structure and best practices. Key points include the importance of case sensitivity in Java and ensuring the Java Development Kit (JDK) is properly installed.

Uploaded by

ayandaprince11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

First Java Program-explained

This document provides a step-by-step guide to creating a basic 'Hello, World!' program in Java. It includes instructions for writing, compiling, and running the program, along with explanations of the code structure and best practices. Key points include the importance of case sensitivity in Java and ensuring the Java Development Kit (JDK) is properly installed.

Uploaded by

ayandaprince11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

First Java Program: Hello World

Creating your first Java program is an essential step in learning the language. The
"Hello, World!" program is a simple yet fundamental example that demonstrates the
basic structure of a Java application. This guide will walk you through writing,
compiling, and running your first Java program.

Writing Your First Java Program

To create a "Hello, World!" program, follow these steps:

1. Open a Text Editor: You can use any text editor, such as Notepad, TextEdit, or
an Integrated Development Environment (IDE) like Eclipse or IntelliJ IDEA.
2. Write the Code: Type the following code into your text editor:

public class HelloWorld {

public static void main(String[] args) {

System.out.println("Hello, World!");

}}

Explanation of the Code

• public class HelloWorld: This line declares a public class named HelloWorld. In
Java, every application must have at least one class definition.
• public static void main(String[] args): This is the main method, the entry point
for any Java application. The main method is always required in a standalone Java
application.
• System.out.println("Hello, World!");: This line prints the text "Hello, World!"
to the console. System.out is a standard output stream, and println is a method that
prints a line of text.

Compiling the Program

Before running your program, you need to compile it:


1. Save the File: Save your file with the name HelloWorld.java. The filename must
match the class name and be case-sensitive.
2. Open Command Prompt/Terminal: Navigate to the directory where
your HelloWorld.java file is saved.
3. Compile the Program: Enter the following command to compile your program:

javac HelloWorld.java

This command uses the Java compiler (javac) to convert your Java code into
bytecode, generating a HelloWorld.class file.

Running the Program

After successful compilation, run your program with the following command:

java HelloWorld

If everything is set up correctly, you should see the output:

Hello, World!

Tips and Best Practices

• Case Sensitivity: Java is case-sensitive. Ensure that you use the correct
capitalization for class names, method names, and file names.
• File Naming: The filename must match the public class name exactly, including
capitalization.
• Environment Setup: Ensure that Java Development Kit (JDK) is installed and
configured correctly on your system. You can verify the installation by
running java -version and javac -version in your command prompt or terminal.
• Use Comments: Add comments to your code to improve readability and
maintainability. For example:

// This is a single-line comment

You might also like