OOPs Concepts

Language Elements

Exceptions

Java String Class

Java Array Class

Collections

Java Example Codes

Core Java Interview Questions

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:

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:

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

 


Copyright © by Zafar Yasin. All rights reserved.