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

Java Tutorials

Creating First Java Application

Overview

In this tutorial, we will learn the steps involved to create First Java Application. The following instructions are for users of the 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/java/

Related Posts

Java Performance

Java Tutorials /

Improving Java Performance with Multithreading

Download Greenfoot Windows

Java Tutorials /

Download & Install Greenfoot on Windows

Java Tutorials /

Java Static Code Analysis

Java Tutorials /

Java Testing Tools

Java Tutorials /

Handle Multiple Exceptions in Java

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

Recent Posts

  • How to secure your SQL Database: Tips and Tricks
  • Shaping the Future of Development: Exploring Key Trends in Software Engineering
  • Improving Java Performance with Multithreading
  • Difference between PHP and JavaScript?
  • Bing Conversation Styles
  • ChatGPT Introduction
  • Open Source AI Frameworks
  • Artificial Intelligence Tools
  • Top AI Music Applications
  • Top AI Website Design Tools

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com