A step by step guide to working with Java(Jdk 8) In Eclipse(Mars) in Windows 8 Platform

Rajnilari2015
Posted by in Others category on for Beginner level | Points: 250 | Views : 958 red flag
Rating: 4.33 out of 5  
 3 vote(s)

In this step by step article, we will look into how to setup the environment in Eclipse(Mars) and to create a small java application to demonstrate the application development enviornment of Java in the same.


 Download source code for A step by step guide to working with Java(Jdk 8) In Eclipse(Mars) in Windows 8 Platform

Introduction

Eclipse is a popular integrated development environment (IDE) initially targeted for Java Development but later on enhanced for other programming platforms like C,C++,Haskel,COBOL,Groovy etc.Eclipse is mostly written in Java.The current version of Eclipse is 4.5 whose code name is Mars.In this step by step article, we will look into how to setup the environment in Eclipse(Mars) and to create a small java application to demonstrate the application development environment of Java in the same.

Environmental Setup

First of all, we need to install JDK 8.If you are new to java and want to learn about how to install Jdk 8, here is a nice article about the same.

As a Second step,download Eclipse IDE for Java Developers

As a final step, unzip the downloaded file into a directory.In our case we have done that in "D:\MyEclipseWork".

So now we are good to go ahead for our project

Creating the Workspace in Eclipse

Now, we need to visit the installed directory of Eclipse and click on the eclipse.exe. The splash screen opens up.The next screen is the WorkSpace Launcher.Eclipse stores the projects in a workspace. Hence.Hence, we need to define the workspace path.In our case it is D:\MyJavaProject

After setting the "workspace" click on OK button.After that, we will receive the "Welcome" screen.Close that.We will receive the below screen

Click on File->New->Java Project.The "New Java Project" Screen appears.Specify a project name (in our case "MyFirstJavaProjectInEclipse") and click "Next" button.

You can figure out that, all the *.jar files of JRE System library has been listed.

Right click on the "MyFirstJavaProjectInEclipse" -> New -> Package

Provide a "Package Name". In our case it is "test.MyFirstJavaPackage"

Click "Finish" and the package will be created.Next, right click on the package and choose "class".

Specify the "Name" for the Java File. In our case it is "FirstJavaScreen".And click finish.

This will create a file call "FirstJavaScreen.java"

Now replace the existing code with the below code

package test.MyFirstJavaPackage;
import java.awt.*;
import javax.swing.*;

public class FirstJavaScreen extends JFrame{	
	
	//variable declarations
        private JPanel loginPanel;
	private JLabel titleLabel;		
    
        //constructor invocation
        //Purpose: Initialization of the values of various controls
	public FirstJavaScreen(){
		super("Welcome to the Hello World Screen"); 
      	prepareGUI();
   }
    
	//Method: prepareGUI
        //Purpose: Is used to specify the position and size of a GUI component 
        //Access Specifier: Private as it is accessible only within this class
        private void prepareGUI(){
		      	
		      	setSize(400,120);
        		setLocation(500,280);

        		componentsInitialization();
        		setComponentsSizeAndPosition();
        		pushComponentsInsidePanel();

	        	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        		setVisible(true);

  		} //end prepareGUI 

  		//Method: componentsInitialization
    	        //Purpose: Is used to initialize the GUI component 
    	        //Access Specifier: Private as it is accessible only within this class
  		private void componentsInitialization() {

  			loginPanel = new JPanel();       
	        	loginPanel.setLayout (null);
	        	titleLabel = new JLabel("Hello World From Eclispe(Mars)");
	        	titleLabel.setForeground(Color.blue);
        		titleLabel.setFont(new Font("Serif", Font.BOLD, 20));
  		}//end componentsInitialization

  		//Method: setComponentsSizeAndPosition
    	       //Purpose: Is used to specify the position and size of a GUI component 
    	       //Access Specifier: Private as it is accessible only within this class
    	       private void setComponentsSizeAndPosition() {

	                 //setBounds is to specify the position and size of a GUI component 
                         titleLabel.setBounds(80, 20, 500, 30);
    	        }//end setComponentsSizeAndPosition

	  	//Method: pushComponentsInsidePanel
	        //Purpose: Add the controls to the login panel 
	       //Access Specifier: Private as it is accessible only within this class
	     private void pushComponentsInsidePanel() {
	     	loginPanel.add(titleLabel);
	        getContentPane().add(loginPanel);
	     }//end pushComponentsInsidePanel 

  		//*******************************************************************    
    	
	     //The main invocation 
	     public static void main(String[] args) {
		new FirstJavaScreen();
	     }
}

Click on the "Run" button or Press Ctrl+F11. The below is the output

Now let use visit to the "WorkSpace" folder which in our case was "MyJavaProject".

The source file will be generated in "D:\MyJavaProject\MyFirstJavaProjectInEclipse\src\test\MyFirstJavaPackage\FirstJavaScreen.java".

The class files are generated in "D:\MyJavaProject\MyFirstJavaProjectInEclipse\bin\test\MyFirstJavaPackage\FirstJavaScreen.class".

References

eclipse

Conclusion

Hope you will find this useful at some point of time if you are planning to start Java project in Eclipse IDE.Thanks for reading the article.

Page copy protected against web site content infringement by Copyscape

About the Author

Rajnilari2015
Full Name: Niladri Biswas (RNA Team)
Member Level: Platinum
Member Status: Member,MVP
Member Since: 3/17/2015 2:41:06 AM
Country: India
-- Thanks & Regards, RNA Team


Login to vote for this post.

Comments or Responses

Posted by: Crniranjanraj on: 9/30/2015 | Points: 25
helped me a lot..thanks

Login to post response

Comment using Facebook(Author doesn't get notification)