Skip to main content

Beginning Java developement with Eclipse

Eclipse is a very popular and widely used software development environment.
It can be used to develop applications in various languages like Java ,C++,PHP and many more.

Here we will discuss about the use of Eclipse to develop Hello World program in 6 simple steps.

STEP 1. Download and Install JDK

JDK(Java Development Kit) will be required to run Eclipse as well as develop and test your application.Various versions of JDK are available, I recommend you to download JDK 1.6

Eclipse and Java

JDK can be downloaded here ---> http://www.oracle.com/technetwork/java/javase/downloads/index.html

STEP 2: Download and Install Eclipse

Eclipse is available in a zip format. Just unzip it to install.

Eclipse download

You can download and install it from this link. http://www.eclipse.org/downloads/moreinfo/java.php

STEP 3: Starting and Configuring Eclipse

Eclipse can be run by launching eclipse.exe in the installation directory.
On starting eclipse, you will be prompted to choose a workspace.This is a folder location where your java files will be saved. I will name the workspace C:\eclipse workspace\MyFirstProject and press OK.

starting eclipse

Eclipse window will open and you will see the welcome screen.Close the welcome screen tab.

eclipse workspace screenshot

Now, go to File -> New -> Java project
You will see a screen like this.

creating new java project

Here I will give the project name as 'Hello World'.
Select the 'Use default JRE(Currently JRE 6)' option.
Click Finish.

The Hello world project will appear in the left side panel.

create new java projectSTEP 4. Creating Java class

Go to File -> New -> Class
A new Java class window will appear as shown below.

new java class created

Here, you have to specify following:
  1. Name of the package - Lets say com.pack.hello
  2. Name of the class - HelloWorld
  3. Select the checkBox 'public static void main...' (This will create the main method for your class)
We will keep the other options as is and click Finish.
The new class will appear in the editor and also a node will appear in the left panel below the project node.

class created

STEP 5
: Writing the code

Let us write a simple java code to print 'Hello world'.

Type following code in the main() method

System.out.println("Hello world !!!");

P.S. A short cut to writing System.out.println is :
Write sysout and press cntrl + space bar
the sysout will convert to System.out.println("");

STEP 6: Running the code

Right-click on the HelloWorld class icon and select

Run As - > Java Application

as shown in the screenshot below.

run java application eclipse

If you have done everything right,you should see 'Hello World !!!' printed in the console in the bottom panel.


eclipse console output

Congrats. You have successfully developed your first java application !!!

Comments

Popular posts from this blog

How to remotly debug java program using Eclipse

Eclipse provides a facility to debug your java programs remotely. To demonstrate how you can remotely debug java programs remotely, I will do the following: Create a .bat file that calls the java program Configure the arguments to the JVM so that the JVM will be capable of being remotely debugged Configure Eclipse to connect to the remote JVM 1. Create a bat file calling the java program I create a java class given below: public class RemoteDebugDemo { public static void main(String[] args) { System.out.println("STEP 1"); System.out.println("STEP 2"); System.out.println("STEP 3"); System.out.println("STEP 4"); System.out.println("STEP 5"); System.out.println("STEP 6"); } } Now I wish to run this program in batch mode.So I write a file called RemoteDebugDemo.bat file with following content. java -jar RemoteDebugDemo.jar I create a jar file named RemoteDebugDe

How to convert a CSV file to XLSX

I wrote this utility for a friend of mine who wanted to convert large (~50MB) CSV files to XLSX. The CSV files had comma "," as a delimiter. I have used apache poi utility in this program. https://www.apache.org/dyn/closer.lua/poi/release/RELEASE-NOTES.txt This code uses SXSSFWorkbook class. The SXSSFWorkbook class uses "BigGridDemo" strategy, where only portions being processed are kept in memory. There are temporary files created which store the rest of the temporary data. setCompressTempFiles() method allows these temp files to be compressed. The size of these files can get quite large. The data to be converted was UTF-8 encoded data. So, we are using  OutputStreamWriter, where we specify the encoding of the data. If you do not need the encoding, just remove that parameter from the constructor call of OutputStreamWriter. The system where this ran, supported Java 7, so have not used features in java 8, such as try with exceptions. import java.io.*; im

How to detect browser closing events and warn user before closing

Recently I came across this problem.I was creating a web application where users were supposed to save their work before logging out.While testing, it turned out that many users closed their browsers instead of logging out. To solve this, I googled the problem and found out that this was a very common problem. I just used below java script code in my webpage's header. Q. How to detect browser closing event and save your data Ans: The onunload event gets fired when the browser is closed or refreshed(using F5 or the refresh button). So now It turns out that the data was getting saved unnecessarily on refreshing the page. For that I stumbled across a forum where I found the solution.(It works for IE only) Q.How to disable function key F5? Ans: document.attachEvent("onkeydown", my_onkeydown_handler); function my_onkeydown_handler() { switch (event.keyCode) { case 116 : // 'F5' event.retur