• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer
  • Home
  • Java Tutorial
  • Java Posts
  • Node.js
  • Spring Core
  • Algorithms
  • Docker
  • Blogging
  • Misc
Tech Stack Journal

Tech Stack Journal

First Java Program

Contents

  • 1 Steps to run this Java code:
    • 1.1 Where to write this Java code?
    • 1.2 Writing Java Program in Text Editor
    • 1.3 Writing Java Program in IDE
First Java Program

In our first Java program, we are printing a “Hello World!!!” message.

Steps to run this Java code:

Here is the code to copy:

package com.techstackjournal;

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

Where to write this Java code?

  • Text Editor
  • Integrated Development Environment (IDE)

Though we can write the program in a Simple Text Editor, it is always better to use IDE, as it provides intellisense while to type code. Intellisense means, providing auto-complete options as type your program.

Writing Java Program in Text Editor

  • Copy above program to a text editor
  • Create a workspace folder like “D:\workspace”
  • Save the file with name “App.java”
  • Open Command Prompt
  • Type cd d:\workspace to switch to the location of the file
  • Compile your program using javac -d App.java command
  • A class file with name App.class will be generated inside “com/techstackjournal” folders.
  • To run this program type java com.techstackjournal.App
D:\workspace>javac App.java
D:\workspace>java com.techstackjournal.App
Hello World!!!

Writing Java Program in IDE

Choosing the IDE
  • There are several IDEs available in the market
  • Most used IDEs are Eclipse, IntelliJ IDEA, NetBeans
  • NetBeans is free and opensource IDEs
  • IntelliJ IDEA comes in Community and Commercial versions
  • IntelliJ IDEA Community is free but only for pure Java related programming
  • IntelliJ IDEA Commercial version supports other advanced features to work on web projects
  • Eclipse is free and opensource
  • Eclipse also comes in various versions and for various programming languages
  • Throughout this course I’ll assume that you have downloaded Eclipse IDE for Enterprise Java Developers
  • Eclipse downloads can be executed directly without installation
Create your Java program in Eclipse IDE
  • Extract the eclipse zip file
  • Get into eclipse folder and double click eclipse.exe
  • Eclipse prompts for selecting workspace, give a relevant name here like JavaPracticeWorkspace
  • Select Menu, File >> New >> Project
  • Select, Java >> Java Project, click Next
  • Enter the project name, FirstJavaProject, click Finish
  • Click on Yes, to open associated perspective, that is Java
  • Expand the newly created project
  • Right click on src folder and select, New >> Class
  • Remove the value for Package
  • Enter “App” for Name
  • Select the checkbox for “public static void main(String[] args)”
  • Click on Finish button, you’ll see that partial code is written for you in App.java file
  • Add the print statement inside main method, System.out.println("Hello World!!!");
  • Press Ctrl+S to save the file
  • Right click anywhere in the Java program and select, Run As >> Java Application
  • The output will be printed in the “Console” view, just below the Java Editor

   Install Java    

    Statements and Comments   

Primary Sidebar

More to See

Arrays.asList in Java Examples

February 21, 2021 By Admin

[Solved] Why List.add throws UnsupportedOperationException in Java?

February 20, 2021 By Admin

Secondary Sidebar

  • Java Tutorial
    • Introduction
    • Install Java
    • First Java Program
    • Statements and Comments
    • Packaging the Classes
    • Variables
    • Primitive Data Types
    • Operators
    • if-else statement
    • Loops in Java
    • Arrays
    • break and continue
    • Switch Statement
    • Classes and Objects
    • Methods
    • Encapsulation
    • Constructor
    • Inheritance
    • Access Modifiers
    • Static Variables and Methods
    • Final keyword in Java
    • Abstract Class
    • What is an Interface in Java?
    • Method Overloading
    • Java – Method Overriding
    • Polymorphism
    • Java – super Keyword
    • Nested Classes
    • Exception Handling
    • String Class

Categories

  • Algorithms
  • Blogging
  • Docker
  • Java
  • Misc
  • Node.js
  • Spring Core
  • Windows

Archives

  • February 2021 (6)
  • January 2021 (1)
  • December 2020 (1)
  • September 2020 (2)
  • August 2020 (5)
  • July 2020 (4)
  • June 2020 (1)
  • May 2020 (4)
  • April 2020 (22)
  • November 2019 (3)
  • September 2019 (2)
  • August 2019 (6)

Footer

Navigation

  • Home
  • Java Tutorial
  • Java Posts
  • Node.js
  • Spring Core
  • Algorithms
  • Docker
  • Blogging
  • Misc

Recent

  • How to Make File Explorer Open to This PC instead of Quick Access in Windows 10
  • Arrays.asList in Java Examples
  • [Solved] Why List.add throws UnsupportedOperationException in Java?
  • How to Convert an Array to List in Java?
  • How Many Spaces in a Tab?

Search

Copyright © 2021 · Tech Stack Journal · Log in