Java an object oriented computing language introduced by Sun Microsystems, and later acquired by Oracle Corporation. A program can run on any computer, with Java installed on it, irrespective of the operating system. Source code after compilation is converted into byte code, which Java Virtual Machine (JVM) can run.
Java Program Structure
Java follows Object Oriented Software approach. Class act as a template to create instance of one or more objects. Java is case sensitive, and naming of classes and methods follows, defined conventions. A typical Java program consist of set of libraries from Java Application Interface (API), main method, associated classes, objects and methods. The program execution starts from the main method.
Use of Java Application Interface (API) helps in decreasing the lines of source code for a program. It provides the set of predefined and prewritten packages, classes, and interfaces with their respective methods, fields and constructors, and how to use them.
Java Development Environment
JDK (Java Development Kit) provides the development environment for developing java applications. To download the latest release, go to the oracle download page Java SE 8 Archive Downloads. Set the JAVA_HOME environment variable to the directory into which JDK is installed.
Java Code Execution
Java code can be executed by using console (for windows), Unix/Linux terminal or a suitable IDE (Integrated Development Environment), such as:
- Eclipse: It can be downloaded from Eclipse Downloads.
- Intelliji: It can be downloaded from Intelliji Downloads.
- Netbeans: It can be downloaded from Netbean Downloads.
For running a java program from windows (without using any IDE), after setting up your java path, write a java program and save it. If "FileName" is name of file, then save as FileName.java. For compiling type javac FileName.java, and it will create a corresponding .class for execution. To run the java program type java FileName, to print the output.
For Linux/Unix, after installing java and setting up the classpath, edit java source code with suitable editor and save it. Compile and run you java source with the normal javac / java commands.
Java Applications
Java is used at variety of places, such as:
- Desktop applications (media players, IDEs, games, financial applications etc).
- Web applications accessed through web browser (on the server side to create dynamic pages). Examples include E-commerce applications, Content Mangement Systems, health care applications, travel applications etc
- Mobile applications (primary programming language for Android platform).
- Enterprise applications to support specific business needs across various units wthin an organization (such as for a bank etc).
Sample Java Code
As an illustration consider the example of the java code as shown below . // is for a single line, and and /* ----*/ are multiline comments. The program can be saved under file name FirstJavaProgram.java.
// This program will print the message "simple java program" as the output. public class FirstJavaProgram { // main method declaration public static void main(String []args) { // printing the output System.out.println("simple java program!"); } }
Useful Links
- Oracle Java Tutorial.
- Book By David J. Eck: Introduction to Programming using Java.
- MIT OCW Course: Introduction to Programming in Java.
- Creating Java Project using Eclipse.