TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java

Creating First Java Application

Overview

In this tutorial, we will learn steps involved to create First Java Application. The following instructions are for users of Windows operating system.

 

To code the first Java program, we’ll need:

  • JDK(Java Development Kit)
  • Set JAVA_HOME environment variable
  • Appended the JDK bin directory to the PATH variable
  • Text editor like Notepad, Notepad++, etc.

Steps to download and install JDK on Windows:

https://www.testingdocs.com/download-and-installing-java-jdk/

Instructions to download and install Notepad++ text editor on Windows:

https://www.testingdocs.com/installing-notepad-editor-on-windows-10/

 

 

Java Program Execution Java Tutorials

Java Program

Our first Java program, HelloWorldJavaApp, will display the “Hello world!” greeting message on to the console output. To create this Java program, we will:

  • Create a Java Source File
  • Compile the Java source file to .class file
  • Run the Java Application

Create a Java Source File

The source file contains the Java code, written in the Java programming language. The source code is in human readable format, so that we can understand the code. We can use the text editor to create the source files.

Open Text Editor.

Add the following Java source code.

/**
 * The HelloWorldJavaApp application
 * Prints the message "Hello World!" to standard output.
 * Java Tutorials - www.TestingDocs.com
 */
public class HelloWorldJavaApp {

 public static void main(String[] args) {
 System.out.println("Hello World!"); 
// Display the greeting.
 }
} 

 

Save the file as HelloWorldJavaApp.java

 

Java Source Code Notepad++ Editor

Compile the Java source file to .class file

The Java programming language compiler (javac) takes the source file and translates it into instructions that the JVM (Java Virtual Machine) can understand. The instructions contained within this file is the Java bytecode.

To compile the Java source file, change the current directory to the directory where the Java source file is located. At the prompt, type the following command and press Enter.

\> javac HelloWorldJavaApp.java

 

The compiler will generate a bytecode class file, HelloWorldJavaApp.class

We can find the javac and java in the JDK bin directory.(%JAVA_HOME%\bin)

We can set the JAVA_HOME environment variable and appended the JDK bin directory to the PATH variable.

Java JDK Tools bin Directory

Run the Java Application

The Java tool (java) uses the JVM to run the application. Enter the following command at the prompt:

\> java HelloWorldJavaApp

 

Run First Java Application Windows

That’s it. We have successfully created and run a sample Java Application.

—

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/in/java/

Related Posts

Download Greenfoot Windows

Java /

Download & Install Greenfoot on Windows

Java /

Java Static Code Analysis

Java /

Java Testing Tools

Java /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java /

Exceptions in Java Programs

‹ Java super Keyword with Example› Java Hello World Applet Example

Recent Posts

  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Print Triangle Pattern Flowchart
  • RAPTOR Editions
  • Flowgorithm Conditional Breakpoint Statement
  • Flowgorithm Read Numbers from File Example
  • Search Text File Flowchart Example
  • Flowgorithm Turtle Graphics Symbols
  • Draw Circle using Flowgorithm Turtle

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version