Sunday 29 November 2015

Installing Java - Part 2

One more thing to do final completion for Installing Java for learning. The things discussed previously may be sufficient to do complete Java programming but getting an IDE (Integrated Development Environment) for Java programming is the best way to go.

Integrated Development Environment A set of programming tools for writing applications (source code editor, compiler, debugger, etc), all activated from a common user interface and menus. IDEs are standard procedure for program development.

In an IDE write the source code and have the same IDE to compile the source code and get errors if any and finally can run the source code in the same IDE which make it a lot easier and saves a lot of time.

For doing Java programming there are tonnes of IDEs in the market as NetBeans, Eclipse, IntelliJ Idea, jCreator, Jgrasp, Jdeveloper BlueJ, Dr. Java and many more. Eclipse is one the best IDEs that can be used for Java programming.



Eclipse is another free Java IDE for developers and programmers and it is mostly written in Java. Eclipse lets you create various cross platform Java applications for use on mobile, web, desktop and enterprise domains. Eclipse is available under a Eclipse Public License and is available on Windows, Mac OS X and Linux.




Download Eclipse installer or zip file from official site of eclipse for Windows, Mac OS X or Linux 32 bit or 64 bit depending upon your operating station configuration that too free of cost.

After installing eclipse and running the Eclipse application for first time it asks where to store the project. Just select the default setting which can be changed later. Then a welcome window appears which contains the overview, tutorials, sample projects on web and what's new in Eclipse Java EE IDE. Close the window to start the Java Programming in Eclipse.

Side Note : Eclipse main features include a Windows Builder, integration with Maven, Mylyn, XML editor, Git client, CVS client, PyDev,  and it contains a base workspace with an extensible plug-in system for customizing the IDE to suit your needs.  Through plugins you can develop applications in other programming languages some of which include , C, C++, JavaScript, Perl, PHP, Prolog, Python, R, Ruby (including Ruby on Rails framework), to name just a few. 
Working on an IDE makes its lot easier to learn basic knowledge of Java efficiently and in a short time span as everything becomes fairly easy and all at one place from writing source code to debugging source code for an output.
Here is the example of again the famous program for first time the Hello World Java program done in eclipse.


To start Java Programming first step is to create a Java Project. For doing so go in New in File tab and in New select Other... This can be directly done by using the shortcut Ctrl+N. 





After this select Java project and give the Project name. On selecting finish it will ask "This kind of project is associated with the Java perspective". This perspective is designed to support the Java development. It offers a Package Explorer, a Type Hierarchy, and Java-specific navigation actions. Select yes to show this perspective.

 



Once the project has been created next step is to add class into the project for that right click on source in world Java project and select Class then enter class name and select Finish.


Adding Class













This completes the making of Java project and adding class into the project and eclipse will add the basic code of class required for further programming. Here we've created a Java Project as world which contains a class called world.
One more thing that I personally found excellent about Eclipse is that as you keep writing the code it constantly gives you predictions of next code you can use or which type of parameters go in that method and hovering over the method gives out its detailed description.

For this Project we'll go in some explaining of code. Fist of all there is a class which contains a main method.The entry point of every Java application is its main method. When you run an application with the Java interpreter, you specify the name of the class that you want to run. The interpreter invokes the main method defined within that class. The main method controls the flow of the program, allocates whatever resources are needed, and runs any other methods that provide the functionality for the application. The main method has body in which all the other methods go which all together makes a complete source code. System is a class in java.lang package. out is the static data member in System class and reference variable of PrintStream class. println() is a normal (overloaded) method of PrintStream class. This method is overloaded to print message to output destination, which is typically a console or file. Inside the println method one can write anything they want to print out on the console in double inverted commas.



As one can see that after running the source code compiling and running the can be done in the same IDE which is done with so much ease and so quickly which gives extra time for learning and doing other stuffs in the Java world. Here we've used some extra line of code in the println method compared to previous example which are as follows
\n : go to the next line
\t  : give out space equivalent of tab
\"  : print special characters here it is "

Now another great thing about Eclipse is that it shows line numbers and white cross in red circle if there is a error in the line. It also gives a popup if errors exist in the project.


And if still proceeded it will show a complete list of things which might have gone wrong and further steps that can be taken to get rid of those errors. It will also automatically take you to the line where error has occurred and show you the line number in console where error has occurred.