Java Tutorial

Our Java tutorials cover all basic to advance Java topics in depth and detail. Our Java tutorials are very helpful to students and java developers.

Java is an object-oriented programming language conceived and created by a group of engineers led by James Gosling at Sun Microsystems in the 1990s. The green team of James Gosling, Mike Sheridan, and Patrick Naughton started the development in 1991.

The initial idea was to create a new language that allows communication between electronic devices such as step-top boxes, PDA devices, etc. As a result, a language prototype called Oak was created, and its initial version was demonstrated in 1992. But Oak did not get much success and was later discontinued.

In 1994 Oak was renamed Java. Sun Microsystems released the first official version of Java 1.0 in Jan 1996. Sun Microsystems was acquired by Oracle Corporation in 2012, and so was the product Java.

Java has made its inroad in many segments such as mobile applications, embedded systems, and internet servers. Oracle Corporation regularly updates the language and adds new features in every new release of Java. The latest version of Java Standard Edition Java SE 18 was released in March 2022.

Language features

Java is a general-purpose programming language. Java possesses many advanced programming features and something unique, making it one of its kind.

It inherited most of its syntax and style from its two strong predecessors, C and C++, mainly language features from C and object-oriented programming (OOP) features from C++. The similarities were maintained to facilitate easy and smooth migration of the large pool of existing C/C++ programmers to the new language Java.

Other than object orientation, Java is also suitable to use in the web medium. A Java program developed and compiled in any system can be executed in other dissimilar systems without revealing its source code. This unique feature made Java different from other languages.

Object Orientation in Java

Object orientation is the core of Java. It offers almost all OOP features.

Java organizes its data and the code acting on that data within a shell called an object. This object is created from an object template called class defined in the Java program. Objects of different classes interact with each other through the exposed data and functions of the classes.

The three basic OOP principles of encapsulation, inheritance and polymorphism are incorporated into the Java language. Proper application of these principles helps develop large, robust and scalable applications.

a) Code reuse is achieved through a defined class hierarchy following inheritance. This helps with the time and money invested in software development.

b) Encapsulations allow us to hide code and data within the class and expose the part desired through the public interface.

c) Polymorphism helps to create clean and readable code that makes future maintenance easy.

Platform Independent Programming Environment and World Wide Web

World Wide Web greatly influenced Java's architecture. By the time the team Gosling at Sun Microsystems struggled to create a new programming language for device-to-device communications, Web was already in place, so their focus shifted to Web. Unlike other programming languages, the Java compiler does not produce object code for the same machine where it is compiled. If it did, the object code could be deployed only in another machine of the same kind (HW and OS), or the source code has to be recompiled and run on a different machine.

On the contrary, Java produces an intermediate code called bytecode. This bytecode is not directly executable; instead, it is interpreted by a software called Java Runtime Environment (JRE) or a Java Virtual Machine (JVM). This means, for example, a Java program compiled in machine A running Windows 2000 produces a bytecode that can be executed in Machine B running Linux under Mac.

This platform independence feature made Java unique and inseparable from the Internet and the Web. Any web content travelling to a client machine carrying java bytecode can be executed, provided the JVM is built in the browser.

Java's Popularity and Advantages

Java is very popular because of its platform independence and its potential to turn the web more dynamic and interactive through the technologies such as JSP, Java Servlet, JDBC, etc.

Another reason for its popularity is the language similarity to C and C++, which helped many C and C++ programmers to grasp its powerful features and become productive quickly.

Java is a rich programming language and offers many significant improvements over C and C++ that increase programmers' productivity and eliminate the scope of runtime errors.

a) Memory management is not the programmer's responsibility in Java. It is carried out by Java Runtime Environment (JRE).

b) Like C and C++, the pointer mechanism has not been carried forward in Java. Although a pointer is a useful mechanism in C and C++, it makes the program complex, affects its readability and maintainability, and increases the scope of memory errors. Java has nicely eliminated this possibility.

c) Garbage collection is another beautiful feature of Java that dynamically collects free memory when the java program executes. Compared to that, in C and C++, memory allocation and deallocation are the programmer's responsibility. Memory leakage due to improper coding is a very common error in C and C++.

d) Java Applet is a very useful technology of Java. The applet is a small application compiled at the server end and sent to client machines over networks. The JVM running in the client machine executes this applet to bring interactivity to web pages.

e) Multithreading is another good feature of Java that allows multiple threads of an application to run simultaneously. A thread is a path of execution through the sequence of a program's instructions; thus, a multithreading application allows multiple executions of one application through multiple threads.

f) Two features of C++ - multiple inheritances and operator overloading are not supported in Java.