JAVA Tutorial

JAVA Tutorial

Last updated on 08th Oct 2020, Blog, Tutorials

About author

Ramesh ( (Sr Project Manager ) )

Highly Expertise in Respective Industry Domain with 7+ Years of Experience Also, He is a Technical Blog Writer for Past 4 Years to Renders A Kind Of Informative Knowledge for JOB Seeker

(5.0) | 14547 Ratings 1947

Java is a popular programming language developed by Sun Microsystems (later merged with Oracle) in 1991. Java was developed by James Gosling and Patrick Naughton.

In our day to day life from morning to evening, we are using many Java programmed applications and devices which include the smartphone in your hand to secure ATM backing transactions.

An explicit sequence of Java tutorials is compiled in this series to give you a better understanding of the concept of Java.

Initially, it was named as “Oak” but was renamed subsequently in 1995 as “Java” since Oak was already a registered trademark.

The first edition of Java was known as “Java 1.0”. Over the years, Java language has evolved considerably and lots of features have been added to Java. As a result, lots of new versions have been released. The latest edition of Java is JDK (Java Development Kit) 13 or Java 13, which was released on September 10, 2019.

So, what is Java?

In simple terms, Java is an object-oriented programming language that derives both from C and C++. From C, Java takes its format while it takes the object-oriented programming from C++. So in order to learn Java from scratch, an individual with C/C++ knowledge would find it easy to grasp.

So, we can define Java as a

  • Simple
  • Highly robust
  • Object-oriented
  • Secure programming language.

Any hardware component or a software environment in which a program runs is called a “platform”. Java has a Java Runtime Environment (JRE) running on it. Thus Java is also a platform.

We will learn more about Java as a platform in our subsequent tutorials.

As of today, Java programming language is the most popular programming language for developing client-server web applications for the internet with an estimated 9 million developers working on and using Java.

Subscribe For Free Demo

Error: Contact form not found.

Java Features

Let’s discuss some of the distinguishing features of the Java programming language.

  • Simple: Java syntax is quite simple and easy to understand. Java is also easy to learn. Most of the features of C++ that were either difficult to understand or ambiguous are simplified in Java and some are omitted. For Example, pointers are absent in Java.
  • Secure: A Java program runs in Java Runtime Environment (JRE) that makes it secure. The JRE does not have interaction with system OS, so java programs do not interfere with the system. Additionally, the Java language has security features that allow us to develop virus-free, secure applications. This is why many banking applications are built on Java.
  • Robust: Java introduces automatic garbage collection and exception handling that helps to prevent any potential errors. Java also emphasizes on compile time and run time error checking. All these features make programs/applications developed in Java more robust.
  • Portable: The Java program compiled into Byte code can be run on any platform. It is implementation-independent and everything required to run the code like storage, data types, etc. are predefined.
  • Object-oriented: Java is a pure object-oriented programming language. Everything in Java is an object. The language features are easily extendible as there is a solid object-based model for programming. Java language supports all the major features of Object-oriented programming.
  • Platform independent: Java is a “write once, run anywhere” code. Unlike other programming languages that compile into machine-specific code, Java is compiled into a byte code that can run on any machine independent of the operating system. Any machine that runs Java Runtime Environment (JRE) can run this byte code.
  • Multithreaded: Java’s multithreading feature allows Java applications to perform multiple tasks simultaneously. Moreover, multiple threads utilize the same memory and other resources and carry out tasks simultaneously.
  • Distributed: Using Java we can develop distributed applications using advanced Java concepts like Remote Method Invocation (RMI) and Enterprise Java Beans (EJB).

So we can distribute the Java program on various machines connected through the internet i.e. an object on one machine can execute remote procedures on another remote machine.

These are the major features of Java that make it a popular and most sought after programming language today.

Let’s discuss the various application types that we can develop using Java programming language.

Java Application Types

Java programming language can be used to create the following types of applications.

1) Standalone Applications

These are also known as Windows-based or desktop applications. These are basically independent software that can install on the desktop.

Applications like media player, antivirus software, desktop editors, etc. are some of the applications that are standalone. Java features like AWT and Swing are typically used to develop these types of applications.

2) Enterprise Applications

Enterprise applications are usually distributed applications and have features like high security, load balancing, and clustering.

Java provides these features through enterprise Java Beans (EJB) and as such EJB can be used to develop enterprise applications. Banking applications are enterprise applications that are most popular.

3) Web Applications

Web applications run on the server-side and create dynamic web pages. These applications need to be highly dynamic and should be able to develop web pages on the go. Java features like JSP, servlets, struts, spring, hibernate, etc. are used for developing web applications.

4) Mobile Applications

A mobile application is an application developed to run on mobile. Currently, Java ME and Android are used for developing mobile applications.

From this, we see that Java allows us to develop a range of applications using its various features. This makes Java the most popular language that is still on top even after so many years since its development. As a programmer, we need not switch technologies to develop different kinds of applications. We can do almost everything using Java.

Java Versions

VERSIONSRELEASE YEAR
JDK 1.01996
JDK 1.11997
J2SE 1.21998
J2SE 1.32000
J2SE 1.42002
J2SE 5.02004
Java SE 62006
Java SE 72011
Java SE 82014
Java SE 92017

Overview of Java Programming

  • Java program can be written in any plain text file and can be named as myprogram.java
  • This code will be compiled by the JDK (Java Development Kit) and this “.java” file will be converted into bytecode as “myprogram.class” file.
  • Again, that will be converted into 0’s and 1’s by JVM (Java Virtual Machine). It can be run on any platform as JVM is available for several operating systems.
  • So, to create a Java project, you need JDK installed on your machine. If you download JDK, it will contain JRE (Java Runtime Environment) and development tools.
  • JRE is the Java Runtime environment that is required to run the Java application and it consists of JVM, package classes and runtime libraries.
  • Click here to download JDK.

Java Program Compilation And Execution Flow

 Java- Program -Compilation- And -Execution- Flow
Course Curriculum

Enroll in Java Training to Build Your Skills & Advance Your Career

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

Java Integrated Development Environment (IDE)

Java IDE is a software that helps the users to write and debug the program easily. It can highlight syntax and errors. One of the famous IDE is Eclipse. Download Eclipse from this link.

Key points to be noted:

  • Java is platform-independent as Java program can be run in any OS or any hardware.
  • To compile the Java program we need JDK.
  • JRE provides a runtime environment.
  • Many amazing applications have been developed by the Java platform. For Example, NASA World Wind has been fully developed in Java. It is similar to google earth. And Blu-Ray BD J has been developed in Java.
  • Eclipse is a popular and open-source IDE to develop Java projects.

Install Java

Step 1: Verify that it is already installed or not

Check whether Java is already installed on the system or not. In my case, it is not installed therefore I need to install JDK 1.8 on my computer.

Step 2: Download JDK

  • Click the below link to download jdk 1.8 for you windows 64 bit system.
  • Download JDK For Windows
  • There are available releases for Linux and mac operating systems. You can visit the official link for JDK distributions i.e.
  • JDK Downloads

Step 3: Install JDK

  • Open the executable file which you have just downloaded and follow the steps.
  • Click Next to continue
  • Just Choose Development Tools and click Next.
  • Set up is being ready.
  • Choose the Destination folder in which you want to install JDK. Click Next to continue with the installation.
  • Set up is installing Java to the computer.
  • We have successfully installed Java SE development kit 8. Close the installation set up.

Step 4 : Set the Permanent Path

To execute Java applications from command line, we need to set Java Path. To set the path, follow the following steps.

  • Right click on “this PC”. It can be named as “My Computer” in some systems. Choose “properties” from the options.
  • The screen look alike the above image will open. Click on “Advanced system settings” to continue.
  • Above window will open. Click on “Environment Variables” to continue.
  • Enter “path” in variable name and enter the path to the bin folder inside your JDK in the variable value. Click OK.
  • Now Java Path has been set up. Open the Command prompt and type “javac” In case you have already open up the command prompt, I suggest you to close the existing window and reopen it again.
  • We will get javac executed as shown in the image below.
  • The Java has been installed on our system. Now, we need to configure IDEs like NetBeans or Eclipse in order to execute JavaFX applications.

Java Program Examples

Let try Java program example. This simple example compiled using jGRASP.

Suppose that

  • You get a monthly pay (before tax) with an amount of monthlyPay
  • Your tax rate is taxRate
  • Your expense a year has an amount of expense
Java Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

Write a Java program to:

  • calculate your annualPayAfterTax
  • calculate your netIncome
  • print out your monthlyPay in the first line
  • print out your taxRate in the second line
  • print out your annualPayAfterTax in the third line
  • print out you expense in the fourth line.
  • print out your netIncome in the fifth line.

A Sample output will look something like this:

  • My monthly pay is $2555
  • My tax rate is 0.33
  • My annual pay after tax is $20542.2
  • My expense a year is $5000
  • My net income a year is $15542.2

Remark:

  • taxRate is not an integer! You should declare its type as double.
  • annualPayAfterTax = monthlyPay * (1-taxRate)*12.
  • netIncome = annualPayAfterTax – expense.
  • Since taxRate is not integer, annualPayafterTax and netIncome are also have to be declared as double; otherwise, you will get error message from compiler.

Answer:

  • import java.util.Scanner;
  •  * @author Mikerisan
  • public class MyIncome
  • // Calculates and prints my yearly income and related items
  • public static void main(String[] args)
  • final double taxRate = 0.33;
  • double monthlyPay, expense, annualPayBeforeTax, annualPayAfterTax, netIncome;
  • Scanner readmonthlypay = new Scanner(System.in);
  • // prompt user for input
  • System.out.println(“Enter your monthly pay: “);
  • // read and store input
  • monthlyPay = readmonthlypay.nextDouble();
  •  Scanner myexpense = new Scanner(System.in);
  •  // prompt user for input
  •  System.out.println(“Enter your yearly estimate expenses: “);
  • // read and store input
  • expense = myexpense.nextDouble();
  • // prints monthly pay
  • System.out.println(“My monthly pay is USD” + monthlyPay);
  •  // prints tax rate
  • System.out.println(“My tax rate is ” + taxRate);
  • // calculate yearly income
  • annualPayBeforeTax = (monthlyPay * 12);
  •  // prints annual pay before tax
  • System.out.println(“My annual pay before tax is USD” + annualPayBeforeTax);
  •  // calculate yearly income after tax
  •  annualPayAfterTax = annualPayBeforeTax *(1-taxRate);
  •  // prints annual pay after tax
  •  System.out.println(“My annual pay after tax is USD” + annualPayAfterTax);
  •  // prints yearly expense
  • System.out.println(“My expense a year is USD” + expense);
  • // calculate yearly net income
  • netIncome = annualPayAfterTax – expense;
  •  // prints yearly net income
  • System.out.println(“My net income a year is USD” + netIncome);

A Sample Output:

Enter your monthly pay: 6000
  • Enter your yearly estimate expenses:20000
  • My monthly pay is RM6000.0
  • My tax rate is 0.33
  • My annual pay before tax is RM72000.0
  • My annual pay after tax is RM48239.99999999999
  • My expense a year is RM20000.0
  • My net income a year is RM28239.999999999993

    The following Figures show the steps using Java command line. Firstly we compile the source code that will generate a bytecode. Make sure there is no error.

  • After the MyIncome.class bytecode has been generated, we can run the bytecode by specifying the classpath to the file.

  • Conclusion

    This tutorial outlined the very basic information on Java language from its history of development to its various features and types of applications that we can develop using this language.

    Java language is easy to learn and has a very simple syntax. Any novice programmer can learn the java basics but the learning becomes easier if a programmer has prior knowledge of C and C++ languages. This is because Java derives its format from C and takes its OOP features from C++.

    Are you looking training with Right Jobs?

    Contact Us

    Popular Courses