Java tutorial

Java is an object oriented high level programming language, developed by Sun Microsystems. Java software development was initiated in 1991 and released in 1995. Java is a very popular programming language which is used everywhere to develop many applications. Java has been acquired by Oracle corporations from Sun Microsystems.

Key features of Java:

  • Java is an open source software that can be downloaded for free.
  • Java is simple , reliable, secure and portable which can run on Windows, UNIX and many other operating systems. Java application runs similarly on all hardware and operating systems. It produces the similar outputs regardless of the hardware or the operating system that is used.
  • This Java tutorial for beginners is developed for new learners, students and also for the corporate level developers who wants to refresh their Java programming skills.

Start with Java tutorial now

Java programming tutorial topics:

Java basic program:

Three things need to be done to make a Java program work. They are 1. Create 2. Compile 3. Run. A source file with .java extension is created and is compiled by Java compiler which yields a class file with .class extension. This class file is run by the JVM and gives the result. A class file, if it is created in….more…

Java – Methods:

Method is defined as the set of code which performs a specific task and returns any data if provided.It is executed, whenever it is invoked.They are used to describe the level of access for the method. There are also static and final modifiers which would be explained later….more…


Java – Constructors:

A constructor is a special method in a class, used to initialize the object’s fields.The name of the constructor is same as that of the class name.Whenever a new object of its class is created, a constructor is invoked.Every class has a constructor. Even if it is not defined, compiler would create a one implicitly….more…

Java – Class and Object:

Objects are anything that exists in the world. A Class is a blueprint to develop objects. If you consider creating objects like chair, table, cupboard, then you need to create a class called Furniture. Similarly, by using Person class, we can create objects like Elaya, Dara, Bharath etc….more…

Java – Comment:

Comments are description given by the programmer within the program. So that if another programmer looks at the program, he can easily understand the program by reading the comments. The characters or words or anything which is given in comments section won’t be considered by the Java compiler for compilation process….more…


Java – Datatypes:

Java is a strongly typed language. Hence every element to be declared, must strictly define its type. There are two kinds of data type. They are, 1. Primitive data type, 2. Reference type….more…

Java – Variables:

Variable is a placeholder (reserved memory block) to store a value of any type. A variable is defined by its name (identifier), type and initialization is optional. Two or more variables of same type can also be declared in a single line separated by commas….more…

Java – Operator:

An operator is used to perform an operation over one or more operands. Operators are classified as Assignment Operator, Arithmetic Operator, Unary Operator, Relational Operator, Logical / Conditional Operator, Bitwise Operator…more…

Java – Arrays:

Array is an object, which stores a group of elements of the same data type. Array is index based and the first element of an array starts with the index 0. The size of array is fixed. Array is Index based and hence accessing a random element and performing any operations over the elements such as sorting, filling etc, can be easily performed….more…

Java – Literals:

Literal in Java represents constant value to be stored in variables. Literals are syntactic representations of boolean, character, numeric, or string data….more…

Java – Control statements:

The statements inside a program are usually executed sequentially. Sometimes a programmer wants to break the normal flow and jump to another statement or execute a set of statements repeatedly. The statements which breaks the normal sequential flow of the program are called control statements….more…

Java – If Then Statement:

The statements under the ‘if’ block are executed only when the condition evaluates to true.Here the value of a is greater than the value of b, thus the statement ‘a is greater than b is printed.Deciding whether to execute the statement(s) or not, depends upon the condition specified. Hence it is called as decision making statement….more…

Java – If Then Else Statement:

If then else statement provides two paths. The if block is executed when the condition holds true. When the condition evaluates to false, the statements inside the else block are executed….more…

Java – For loop:

For loop executes a set of statements repeatedly until a specified condition evaluates to false.Initialization Executes once, initializes the loop variable which causes the loop to iterate Condition Specifies the expression which evaluates to true / false. When this condition becomes false, the loop is terminated….more…

Java – While loop:

While loop executes a set of statements repeatedly until a given condition remains true.In the above program, the value of i is printed until it is not equal to zero. When the value of i reaches 0, the execution of the loop is terminated….more…

Java – Do while loop:

Do while loop is similar to that of the while loop except that the condition is evaluated at the end of the loop in do-while whereas in while loop, it is evaluated before entering into the loop.Do while loop is similar to that of the while loop except that the condition is evaluated at the end of the loop in do-while whereas in while loop, it is evaluated before entering into the loop….more…

Java – Switch statement:

‘switch’ statement can have multiple execution paths. It is similar to that of ‘if else-if’ statement except that switch can handle expressions which results to any primitive data type and if statements handle only boolean expressions….more…

Java – Break statement:

When a program executes a break statement, then the loop (for/switch/while/do while) which contains the break statement is terminated. The flow of the execution jumps to the outside of the loop….more…

Java – Continue statement:

Continue statement skips the current iteration of the loop and evaluates the loop’s condition for the next iteration. Rest of the statements of the loop after the continue statement is not executed and the next iteration is followed….more…

Java – Array Operations:

The arraycopy() method belongs to the System class. It is used to copy the contents of one array to the other.The Arrays class has two commonly used methods for copying the content of array i.e. copyOf() and copyOfRange() method….more…

Java – Multidimensional array:

Multidimensional arrays are array of arrays. The inner member of the array would have equal number of elements.Jagged array is a special case of multidimensional array in which the member arrays of the array, can be of varying size….more…

Java – Static keyword:

Generally, a member declared in a class can only be accessed through the object of that class. But, declaring a member as static means that it can be accessed without creating object and it belongs to the class and not to the instance. The keyword ‘static’ can be applied to variable, method, block and nested class….more…

Java – this keyword:

The keyword ‘this’ is used to represent current object of the class. It is used to access various elements of the class like instance variables and methods. For eg: “this.var1” and “this.method1()”The keyword ‘this’ when used along with parenthesis as in ‘this()’, is used to invoke the constructor of the class….more…

Java – Type Conversion and Casting:

In Java, there are two kinds of data types – primitives and references.  Primitives include int, float, long, double etc. References can be of type classes, interfaces, arrays. A value can change its type either implicitly or explicitly….more…

Java – Wrapper Class:

In Java, numbers are usually used as primitive types.Sometimes, we might need them to be used as objects instead of primitives.Wrapper classes are helpful in this regard. They wrap the primitives in an object.Wrapping is done by the compiler….more…

Java String:

The string represents a group of character. In Java, a string is an object of String class in java.lang package. But, in C language, it is an array of characters in which the last character is ‘\0′. Java has character array too, but String is a class. The string is also a data type as a class is also called user defined data type….more…

Java – String examples:

In C, C++, a string represents an array of characters (last character ends with ‘\0’). In Java, a string represents the object of String class. We also have character array in java. Is string a class or a datatype?String is a class defined in java.lang package. In Java, every class is considered as user defined data type. So we can take string as a data type….more…

Java – String Buffer:

In some cases, there may arise a need for the programmer to modify the content of the string and this is when the StringBuffer comes into play.StringBuffer is similar to the String class except that String class is immutable, whereas the StringBuffer class is mutable (can be changed)….more…

Java – String Builder:

StringBuffer is synchronized (which means that, even when multiple threads act on the StringBuilder object, they would be executed one after the other providing us reliable results) whereas StringBuilder is not.StringBuilder executes faster than StringBuffer since it does not take the time for synchronization….more…

Java input/output operations:

Each and every program needs data which are to be processed. Such data are represented as inputs and the final resulting data which we get after processing is represented as the output. Usually the user enters the data through the keyboard and view the result on the monitor….more…

Java – Input/Output example:

A simple java program takes an input, process the input and produces the output as result.Input can be taken from the keyboard, from a file, from main memory or from elsewhere. Now if the input is defined inside the program itself, then running it anytime would present us the same output….more…

Java – Collections Framework:

Collection is an object representing a group of objects. Collection framework contains a set of classes and interfaces which are used for representing and manipulating collections. Collection interface is the root interface from which the interfaces List, Set,Queue are extended….more…

Java – Arraylist:

ArrayList is a class that implements the List interface. The advantage of ArrayList over the general Array is that ArrayList is dynamic and the size of ArrayList can grow or shrink. ArrayList stores the elements in the insertion order. ArrayList can have duplicate elements. ArrayList is non synchronized….more…

Java – LinkedList:

LinkedList is a class which implements the List interface. It is similar to that of LinkedList except that the ArrayList uses Array data structure implicitly whereas LinkedList uses doubly linked list internally to store the elements. Like ArrayList, LinkedList is also non synchronized….more…

Java – Vector Class:

Vector class implements the List interface. It uses array data structure internally to represent the elements in it. It is similar to that of ArrayList except that the vector class is synchronized. It is thread safe….more…

Java – Hashtable:

Hashtable implements the Map interface and extends the Dictionary class. Like HashMap, Hashtable also stores objects as key-value pairs. Hashtable and HashMap are similar except that Hashtable is synchronized and does not allow null values….more…

Java – HashMap:

HashMap is a class implementing the Map interface, which allows us to store collection of object as key value pairs. It does not maintain the insertion order. It is not synchronized. It allows only one null key with null values….more…

Java – Method overriding:

If a method inherited from the superclass requires a different definition other than the definition provided in the superclass, then the method can be redefined or overridden. The process of redefining/overriding the method is called as Method overriding….more…

Java – Method Overloading:

If a class contains two or more methods with the same name, it is called method overloading.It is used to achieve static polymorphism.Binding of the method to its method call, is done in the compile time itself and hence it is called static binding or early binding….more…

 Java – Abstract Class:

Abstraction is the process of hiding the inner details and showing the functionality.Abstraction can be achieved through abstract class or interface in Java. A class which is declared as abstract is called abstract class. An abstract class may or maynot contain abstract methods….more…

Java – Interface:

Interface is similar to that of a class except that it can contain only constants and abstract methods.Since the methods in interface are implicitly abstract, the keyword ‘abstract’ need not have to be prefixed.Interface cannot be instantiated. It should only be implemented and used by the class implementing it….more…

 Java – Inheritance:

Inheritance is the process of inheriting the attributes (data member) and behaviour (methods) of an existing class into a new class. (i.e. Inheritance is a process in which one class acquires the features of already existing class)The new class which inherits all characteristics of the existing class is called as….more…

 Java – Dynamic Method Dispatch:

A superclass reference can refer to a subclass object. Whenever an overridden method is called through that superclass reference, then the call to that overridden method is resolved at run time based on the object being referred by the superclass reference….more…

Java – Super Keyword:

‘super’ keyword is used to refer the members of immediate parent class. Accessing parent class variable using super keyword:In the below example, class B is a subclass of class A. The display() method of class B prints the value of x. Both class A and class B have the variable x.The compiler by default, takeshe value of current class instance variable….more…

 Java – Final Keyword:

The keyword ‘final’ in java is used to restrict access of an entity.  The keyword ‘final’ can be used with,Variable,Method,Class If a variable is declared as final, its value cannot be changed. Final variable can be initialized only once – either at the declaration time or inside a constructor. Final variables are similar to constants….more…

Java – Object Class:

Object class is the super class of all the other classes in java.Every class is a subclass of the object class and hence they can use or override the methods present in the Object class.Since subclass objects can refer all the elements of parent class, all classes defined in java program can access methods and variables of Object class….more…

Java – Object Cloning:

Object Cloning is the process of creating an exact copy of the object. The clone() method which belongs to the object class, is used for this purpose.The class whose object’s copy has to be created must implement the marker interface, Cloneable….more… 

 Java – Types of Errors:

There are three types of errors in java. 1.Compile-time errors,2.Run time errors,3.logical errors. compile time errors:These errors are errors which prevents the code from compiling because of error in the syntax such as missing a semicolon at the end of a statement or due to missing braces, class not found, etc….more…

 Java – Exception

An exception is a runtime error, which disrupts the normal execution flow of a program.Compile time errors could not be considered as exceptions, since they are treated as errors and not as exceptions.For example, Syntactical errors like missing of semicolon in the end of the statement may result in compile time errors….more…

Java – Exception Handling

A try block contains the code which may possibly raise an exception. A programmer would know the possible cases of exceptions which can erupt while executing a code.Example when file handling is performed, possible subclasses of IOExceptions can occur.he code which can possibly raise an exception can be encapsulated under the try block….more…

Java – User Defined Exceptions:

The other way of classifying exceptions is by its definition.Built-in Exceptions,User-defined Exceptions,built-in exceptions are those which are already available under the Exception class of java. user-defined exceptions are defined by the user/programmer.This can be done by creating a user defined class extending the Exception class….more…

JAVA TUTORIAL REFERENCE E-BOOKS & RESEARCH PAPERS:

  • JAVA – James Gosling and colleagues reference at Sun Microsystems, 1990.

Prev     Next

Share this website !!!
Facebook Twitter Linkedin