Wednesday, 29 July 2015

Java Tutorial : Java Basic Program

Enjoying the tutorial? Join our developer family!

Subscribe to Ram N Java for beginner-friendly Java lessons, tips, and step-by-step programming guides.

Subscribe Now

Introduction to Java Programming

Starting with a new programming language can feel overwhelming, but Java makes the core process straightforward. In this beginner guide, we will write, compile, and run your very first Java program from scratch using the command prompt.

How Java Works Behind the Scenes

To run code in Java, there is an important 3-step cycle you should know:

  1. Create the Source Code: You write your program in plain text and save it with a .java extension (for example, HelloWorld.java).
  2. Compile with Java Compiler: The compiler (javac) checks your code and turns it into a .class file containing platform-independent bytecode.
  3. Run with JVM: The Java Virtual Machine (JVM) executes the bytecode and displays your output on screen.

Why Java is Platform Independent

Because the compiler converts your source code into bytecode rather than machine-specific instructions, the compiled .class file can run on Windows, macOS, Linux, or Solaris without modification—as long as the machine has the Java Virtual Machine (JVM) installed.

Writing the First Program: HelloWorld.java

Open any text editor and type the following code:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

Save this file with the exact name HelloWorld.java.

Compiling and Running via Command Prompt

Follow these quick steps to execute your program:

  • Open your terminal or command prompt and navigate to the folder where you saved HelloWorld.java.
  • Compile the program:
    javac HelloWorld.java
    This creates the HelloWorld.class file in your folder.
  • Run the compiled bytecode:
    java HelloWorld

You will see the output displayed directly in your command window:

Hello World

Recommended Java Tutorials From Our Channel

Continue your Java learning journey with these hand-picked beginner guides:


Click here to watch in Youtube :
https://www.youtube.com/watch?v=9_z81tIs4Mk&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Basic Program

Java Tutorial : Java Basic Program
Java Tutorial : Java Basic Program
Java Tutorial : Java Basic Program
Java Tutorial : Java Basic Program
Java Tutorial : Java Basic Program
Java Tutorial : Java Basic Program
Java Tutorial : Java Basic Program
See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Tutorials