Install IDE and writing our first JAVA program…

Before going into details, let me give you a brief idea on Integrated Development Environment or IDE. IDE is a software application that has all the basic tools developers need to write and test software. Typically it contains a code editor, a compiler or interpreter and a debugger that the developer accesses through a single graphical user interface or GUI. Eclipse and NetBeans are the popular IDEs that most JAVA developers use and they are free to download. IDEs have lots of features that makes a developers life easy…

I will be using Eclipse as I am familiar with this IDE.

Download Eclipse:

Open Browser and navigate to Google. Type in “Eclipse download” and go to downloads page in eclipse.org website. Select the latest version for Java Enterprise Edition (EE) and download. You have to select correct version based on your Windows or Mac machine. Once download is complete in your local machine, you need to click on eclipse executable file. This will open the Eclipse IDE and a Eclipse Launcher prompt will come asking to confirm on the directory for Workspace.  You can either go with the default location or else you can provide your own location. Workspace is where all your source code will be placed.

screen-shot-2017-02-13-at-1-54-21-pm

Click Ok to open up the main window. The steps are pretty much same for Windows and Mac machine.

Writing a simple program in Eclipse:

  • Now the Eclipse download is complete, lets write our first HelloWorld! program using Java as our programming language and Eclipse as our IDE.
  • Open Eclipse and go to File -> New and select Project option.
  • Select “Java Project” from the wizard and click on Next.
  • Enter Project name as “TestMadness”. You can give your own name to your project.
  • You can see the the default location of your project. Click on Next and then Finish to complete the project creation.
  • By default JAVA Project will have “src” folder which will contain your source code and “JRE System Library” folder which is added by Eclipse IDE automatically on creating Java Projects. JRE System Library implements the JAVA API in Eclipse IDE. So all the predefined functions of Java can be accessed by the Java Programs written in Eclipse IDE because of this JRE System Library.

screen-shot-2017-02-13-at-2-15-43-pm

  • Right click “src” folder and click New -> Package. Enter the package name as “com.selenium.testmadness” and click Finish to create a new package. A package in JAVA can be defined as a grouping of related types like classes, interfaces, enumerations and annotations and providing them access protection and namespace management. Here in this case, folder structure will be created in the form of com -> selenium -> test madness.
  • Once a package is created, our next task is to create a class file. Right click on the package and click New -> Class. Enter the class name as “HelloWorld” and select the option “public static void main(String[] args)” and click on Finish to complete JAVA Class creation.

screen-shot-2017-02-13-at-7-14-33-pm

  • If you  directly go to Workspace location in your machine, you can see a folder structure is automatically created as TestMadness -> src -> com -> selenium ->test madness -> HelloWorld.java.
  • For writing a simple HelloWorld program, add “System.out.println(“HelloWorld!”)” in the public static void main method as shown below. This is a simple program to print “HelloWorld!” in the IDE console.

screen-shot-2017-02-13-at-7-50-15-pm

  • To execute the HelloWorld program, right click HelloWorld.java class file and click run as Java Application. You can see the “HelloWorld!” printed in the console.

Additional Notes:

What is public static void main(String[] args) method?

main method in Java is an standard method which is used by JVM to start execution of any Java program. It is the entry point for core JAVA applications. However you can compile a core JAVA application without a main method. main method is always public that is anyone can see or run it. static means that you can call the function without an instance of the class. void means that the method has no return type. String[] args is an array of command-line arguements and the only formal parameter to the method. Here in our case we are not passing any command line arguments. System.out.println command prints “HelloWorld!” on the screen and then adding a new line after it.