Introduction to Java Programming Language

Java is an object-oriented class-based easy and secure programming language developed by Sun Microsystems in 1995 and later owned by Oracle Corporation.

Java is a platform-independent or we can say cross-platform multi-purpose programming language (cross-platform means can run on any platform). Java is also called WORA (Write Once and Run Anywhere) means Java Source code can be written, and compiled on one platform (Operating System) and can run on any other platform (operating system) too.

In Java, the source code file is saved with .java extension. This source code(.java file) is compiled by the compiler and converts the source code into bytecode. This compiled bytecode is saved with .class extension in the hard disk. This bytecode is used by JVM (Java Virtual Machine) to run/execute the program.

Java Compiler

Java programming example

We are taking a simple example to print “Hello” on the console.

In this example FirstTry is a java class name, main() is a method which will be called by JVM to run the program, and println() is also a method name to print “Hello” word on the console.

This program is saved with name FristTry.java (Source code file name is exactly same as given with class). Java compiler will compile this .java source code and will create one more file which will be saved with the same having .class extension. So in this example, the saved file name would be FirstTry.java and compiled (bytecode) file name would be FirstTry.class.

Simple Java Program

Java Features

Java is a language which is loved to develop software because of its amazing features: 

Object Oriented

Java is based on object-oriented programming. In Java everything is based on Object and on the interface of the object. Object is a logical identity. In Java, Object is created by using the new Keyword.

To work with an object it is required to understand the key features of Objects which are behavior, state, and Identity. To understand the object features we will take the example of Speaker. As we know the Speaker has a volume and power button and we can increase or decrease the volume using the volume button as per requirement.

Behaviour: What can be done by the object and what methods can be applied with this object. In another word Behaviour are the functions or methods which define what action can be applied with the object. As per Speaker example applying function to increase or decrease the volume will be the behaviour of the object

State: How object behaves when methods are applied with the object. In another word, states are variables/attributes which define the objects created by the class. As per Speaker example when applying increase/decrease volume function, speaker volume state changed from low to high or high to low as per respective applying function.

Identity: How an object will be identified uniquely. A company has the same speaker with the same state and behavior with a unique identity number to trace it. For example Sony company has many speakers for the same model but then also each speaker has a unique number to identify it.

Platform Independent

Unlike many other programming languages including C and C++, Java compiles the source code into bytecode which is not platform dependent. This byte code can be run/executed on any platform by the Java Virtual Machine.

Simple

Java is based on the OOPS concept so it is easy to learn.  In java, syntaxes are simple. Developers can focus on their development without being worried about unreferenced objects removal because of its Automatic Garbage Collection feature. Automatic Garbage Collection removes the objects automatically which are not used for a long time.

Secured

Java is secured as it does not use pointers and program runs inside JVM. Package feature is also there to separate local files with network files.

Architecture-Neutral

Java is Architectural- neutral because of its compiler feature which converts source code to bytecode which is not computer architecture-dependent. This Byte code is getting used by JVM to execute the program which is Architecture specific.

Portable

Java code can be developed on any platform and can be compiled to convert into byte code. This byte code is not platform-specific and can be run on any platform. Like Java source code is generated and compiled on windows. Now Compiled code can be run on any platform like MAC, Linux, etc by using platform-specific JVM.

Robust

As we know Robust dictionary meaning is powerful. Features like Strong memory Management, pointers unused, Automatic Garbage Collection and Exception Handling, etc make Java a Robust language.

High Performance

Java uses Byte code to execute the program which is comparatively faster than other traditional interpreted programming languages. Java performance becomes high because of the Just-In-time compiler in JVM. It compiles the byte code once, cache the result and on needing bases calls them again. This logic improves the performance tremendously for commonly used code.

Interpreted

Java Interpreter interprets Bytecode prepared by Java Compiler to execute the program on any machine on which the interpreted has been ported. Java interpreter is specific to the machine.

Distributed

Java has extensive libraries to interact with TCP/IP protocols like HTTP and FTP. Java objects can be communicated across the network via URLs. It is as easy as accessing a local file system.

Dynamic

As we know dynamic means constant change or motion. Java is dynamic in a number of ways. Java is dynamic in the sense that it can be adapted to any evolving environment. New methods and instance variables can be added freely to the libraries without making any effect on their clients. JVM can decide at runtime which methods need to be executed through dynamic polymorphism. Memory is allocated to the objects dynamically at runtime.

Multithreaded

Java has features to utilize the advantage of multiprocessor systems (if base operating system support) through Multithreading. A thread is like a separate program which executes concurrently. Java programs can be written to do many tasks at once using multithreading. The advantage of Multithreading is to share a common memory area.

Thread

A thread is a small set of programming instructions which are managed by the CPU independently. Using Threads performance of the application can be improved.  Detailed description will be given in the separate topic of thread in this tutorial

Java Features

History of Java

Java was started in 1991 by the group of Sun Engineers leading by Patrick Naughton and Sun fellow James Gosling. They wanted to design a small computer language that could interact with consumer devices like Television. Since there was a limitation of memory or power in these devices, it was required to keep the language to be small and generate tight code. It was also considered that different manufacturers will use different architecture so it will not be restricted to any specific architecture. This project was started with the name “Green” and teams were called “Green Team”

As per requirement for small, tight, and platform-independent it was decided to design a portable language that will generate an intermediate code for hypothetical machines (virtual machine). Then this intermediate code can be executed on any machine which is having the correct interpreter. Green team used a virtual machine to solve their main problem.

Green team was from a Unix background. For their language they decided to take the base of C++ and OOPS concepts. Gostling gave the name to this language “Oak”. In one of his interviews he said ”All along, the language was a tool, not the end”. Later the Sun team changed the language name from “Oak” to “Java” as they realized Oak was already the name of an already existing computer language.

Java came into use in 1995. The first version of Java was released by Sun in early 1996 and after just a couple of months released Java1.02. In 1998 Java version 1.2 was released which replaces early GUI and graphics toolkits with a sophisticated and scalable version. It was closer to this language aim “Write once, Run Anywhere”. Three days later of this release in December 1998 its name was changed from Java one to Java2.

Since then different incremental Java versions came with a small number of new features, performance incremental, and of course with bug fixes, etc. over the last Java 2 release version.

Java Versions History

So far many Java versions have been released. The latest released version of Java is Java SE 14 which was released in March-2020

VersionRelease Date
JDK Beta1995
JDK 1.0Jan-96
JDK 1.1Feb-97
J2SE 1.2Dec-98
J2SE 1.3May-00
J2SE 1.4Feb-02
J2SE 5.0Sep-04
Java SE 6Dec-06
Java SE 7Jul-11
Java SE 8 (LTS)Mar-14
Java SE 9Sep-17
Java SE 10Mar-18
Java SE 11 (LTS)Sep-18
Java SE 12Mar-19
Java SE 13Sep-19
Java SE 14Mar-20
Java Versions History

Java Applications

Java is the most popular programming language. According to Github as of 2019, Java is one of the most popular programming languages in use particularly for client-server applications. Approximately more than 9 million developers are using this language.

Some of the applications where Java is in use are:

  1. Desktop Applications 
  2. Web Applications 
  3. Enterprise Applications 
  4. Mobile
  5. Embedded System
  6. Smart Card
  7. Robotics
  8. Games, etc.

Types of Java Applications

Different types of Java applications can be created using Java:

  1. Standalone Applications
    Window-based applications or desktop-based applications are called Standalone applications. Standalone applications are a kind of traditional software that is required to be installed on machines. Standalone applications do not require a network connection to run. It runs as a separate process not with the add-on of any other process. Examples of standalone applications are Open office, PDF Studio, etc. To develop Java standalone applications, AWT and Swing is used.

  2. Web Applications
    Web Application is a client and server-side application accessed over a network using HTTP (HyperText Transfer Protocol). It uses a web browser to perform any user request.  In client and Server-side architecture, the client is used to pass the information while the server to store, process and retrieve the information. In today’s world internet mail suffering is very common and internet mail is one of the common examples of web application. We access(read) our mail through the client and can also see a list of our old mails through the server.

    Web languages like HTML, CSS, Javascript, etc are used to develop frontend which is supported by mostly all the web browsers.

    To develop Java-based Web Application servlets, JSP, Struts, Spring, JSF, etc can be used.

  3. Enterprise Application
    Enterprise Applications are application software to handle a lot of transitions, business logic and security etc for an organization to improve productivity and efficiency. Examples of Enterprise applications are Banking Applications, Billing Systems CRMs etc
    In Java, EJBs are used to develop Enterprise Applications.

  4. Mobile Application
    Applications that are developed to run on mobile devices like phones, tablets, smartwatches, etc are called Mobile Applications. Android and Java ME are used for creating mobile applications.

Java Platforms / Editions

There are 4 platforms or editions of Java :

  1. Java SE (Java Standard Edition)
    Java Standard Edition(Java SE) is a platform that allows the development and deployment of Java applications on computer desktops and servers. It provides a lot of user interfaces, security, portability, etc as per today’s required environment.

    Java SE provides general purpose packages like java.lang, java.io, java.net, java.util, java.math etc., Special purpose packages like java.sql, java.rmi, java.awt, java.beans etc OMG packages like org.omg.CORBA, org.omg.PortableInterceptor etc.

  2. Java EE (Java Enterprise Edition)
    Java Standard Edition(Java EE) is a platform to develop and deploy web and enterprise applications with specifications for enterprise features such as distributed computing and web services. It includes features like Servlet, JSP, Web Services, EJB, JPA, Security API, etc.

  3. Java ME (Java Micro Edition)
    Java Micro edition provides a platform to develop and deploy code for embedded and mobile devices like microcontrollers, sensors, gateways, mobile phones, personal digital assistants, TV set-top boxes, printers, etc.

  4. JavaFX
    JavaFX is a collection of graphics and media packages that allows developers to develop and deploy desktop applications as well as rich Internet applications (RIAs)  to run on different types of devices. JavaFX 2.2 and later releases have Java APIs, WebView, Built-in UI controls, and CSS. etc

Prerequisite

To learn Java, It is required to have basic knowledge of computer programming and OOPS concepts.

Audience

This Java programming writeup is prepared to help java beginners.

Problem

This Java writeup is prepared in easy language by referring to good Java books and tutorials. However, if you feel any mistake or doubt please post us in contact form to resolve your query as soon as possible.

This article was written by Renu Singh

14+ Years of experience in various phases of the software development life cycle. Specialties: Java/J2EE, Struts, Hibernate, JSF, JSP, Servlets, AJAX, Oracle, Oracle Knowledge, SQL Server 2000, DB2, EJB3.0. Companies Worked For: 1) Tata Consultancy Services 2) Infogain 3) TS Infotech 4) Daffodil Software Ltd.

Leave a Reply

Your email address will not be published. Required fields are marked *