Skip to main content

Java Hello World Example

This article describes how to create a "Hello World" java program using Eclipse IDE. This program will print "Hello World" in the console.


Technologies used in this article :
  1. JDK 1.6 +
  2. Eclipse 3.7

  3. JDK Installer : Download  from JDK 1.7.
    Eclipse Installer : Download from Eclipse.

    1. Create Java Project

    Select from the menu File --> New --> Java Project. 


    reate java project

Enter "HelloWorld" as the project name. Keep rest of the settings as it is as shown in the following screenshot.


create java project

Click "Finish" button and Eclipse IDE will generate the java project automatically.


2. Create Java Package

Right click on 'src' folder and select from context menu New --> Package.

create java package


Write 'com.hello.example' in the 'Name' field and click "Finish" button.

create java package

 

3. Create Java Class

Right click on 'com.srccodes.example' package and select from context menu New --> Class.

create java class


Write "HelloWorld" in the 'Name' field and select the check-box for 'public static void main(String[] args)'.


create java class


Click "Finish" button. Eclipse will generate a java class and open the same in the java editor as shown below.

HelloWorld class

 

4. Write Java Code

Edit the generated 'HelloWord' java class as per the following code.
File : HelloWorld.java

package com.srccodes.example;
public class HelloWorld {
    /**
     * @param args
     */
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

 

5. Run Your Code

Right click on 'HelloWorld.java' and select from context menu 'Run As' --> 'Java Application'.

run hello world code

6. Console Output

Your code will print 'Hello World' in the eclipse console.


Hello world

 

Related Blogs:

How to install Oracle JDK on Ubuntu from repository

How to set JAVA_HOME environment variable in Ubuntu

 


 

 


Comments

Popular posts from this blog

JavaMelody: Monitoring the Performance of Tomcat Application Server

Javamelody is an opensource (LGPL) application to monitor Java or Java EE application servers in QA and production environments. JavaMelody is mainly based on statistics of requests and on evolution charts. (Extract from the Javamelody home page) It allows to improve applications in QA and production Give facts about the average response times and number of executions Make decisions when trends are bad, before problems become too serious Optimize based on the more limiting response times Find the root causes of response times Verify the real improvement after optimization It includes summary charts showing the evolution over time of the following indicators: Number of executions, mean execution times and percentage of errors of http requests, sql requests, jsp pages or methods of business façades (if EJB3, Spring or Guice) Java memory Java CPU Number of user sessions Number of jdbc connections These charts can be viewed on the current day, week, month, year or cu...

Tomcat Clustering : Session Replication with Backup Manager

Prerequisite Blogs: How To Install Apache Tomcat Multiple Tomcat Instances on Single Machine Tomcat Clustering: Loadbalancing with mod_jk and Apache Tomcat Clustering : Session Affinity    Backup Manager Backup manager usually used clustered environment. Its like delta manger. But it will  replicate to exactly one other instance(backup instance). Its act  like one instance is Primary  and another instance as backup. Steps to make Session Replication in Tomcat Clustering I am continue from exactly where I left in last session affinity post . So check that post and make sure jumRoute all are set properly. Steps are Enable Multicast routing Add <Cluster> Entries in conf/server.xml file for all instances. Enable the Web Application as distributable Step1:  Enable Multicast routing In Linux Environment most of the system kernel is capable to process the multicast address. We need to add...

How to install Oracle JDK on Ubuntu from repository

This package provides Oracle Java JDK 7 (which includes Java JDK, JRE and the Java browser plugin). However, you can't only install Oracle JRE - the PPA only provides the full Oracle JDK7 package. To install: sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-jdk7-installer And to uninstall: sudo apt-get remove oracle-jdk7-installer And to verify your installation: java -version java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode) And to verify the web browser installation: http://java.com/en/download/installed.jsp Verified Java Version Congratulations! You have the recommended Java installed (1.7.0_51). And to update: If for some reason, the Java version in use is not 1.7.0, you can try to run the following command: sudo update-java-alternatives -s java-7-oracle To Install and Set in environment variable: To...