HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / Java / Java Basics / Java Introduction

Java Tutorial

In this Java tutorial for beginners, learn how Java is concurrent, object-oriented, and is intended to let application developers “write once, run anywhere” (WORA).

1. What is Java Programming Language

Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers “write once, run anywhere” (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.

For example, you can write and compile a Java program on UNIX and run it on Microsoft Windows, Macintosh, or UNIX machine without any modifications to the source code. WORA is achieved by compiling a Java program into an intermediate language called bytecode. The format of bytecode is platform-independent. A virtual machine, called the Java Virtual Machine (JVM), is used to run the bytecode on each platform.

JDK vs JRE vs JVM
JDK vs JRE vs JVM

2. History of Java

Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and released in 1995 as a core component of Sun Microsystems’ Java platform. The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.

Oracle Corporation is the current owner of the official implementation of the Java SE platform, following their acquisition of Sun Microsystems on January 27, 2010. This implementation is based on the original implementation of Java by Sun. The Oracle implementation is available for Microsoft Windows, Mac OS X, Linux, and Solaris.

The Oracle implementation is packaged into two different distributions:

  1. Java Runtime Environment (JRE) which contains the parts of the Java SE platform required to run Java programs and is intended for end users.
  2. Java Development Kit (JDK) which is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger.

3. Features of Java

Java has multiple features. Some of these are unique to Java and some of these are common among other languages.

  • Object Oriented – In Java, everything is represented as objects. An object is kind of wrapper that encapsulated data and its associated behavior.

    Java provides support for all major object-oriented principles as seen in other object-oriented languages.

  • Platform Independent – The programs written in Java are converted to bytecode first, by Java compiler. This bytecode can be run in any machine having Java runtime environment (JRE). It makes the Java applications platform-independent.

    It is very different to C or C++ applications where programs compiled into binaries specific to OS.

  • Secure – Java applications run in Java runtime environment (JRE) with almost no interaction with system OS. It makes Java more secure than other languages.
  • Multithreaded – Java supports writing applications which can do multiple tasks in separate threads. All tasks progress using the time slicing technique of OS threads.

    For example, a Java application serve a user login form while running background processes also.

  • High-performance – Java is an interpreted language, so it may never be as fast as a compiled language like C or C++. But, Java enables high performance with the use of just-in-time compiler.
  • OS Architecture-neutral – Java compiler generates an OS architecture-neutral class files or bytecode.

    For example, in C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory for 64-bit architecture. However, it occupies 4 bytes of memory for both 32 and 64-bit architectures in Java.

4. Garbage Collection in Java

Java uses an automatic garbage collector to manage memory in the object lifecycle. The programmer determines when objects are created, and the Java runtime is responsible for recovering the memory once objects are no longer in use. Once no references to an object remain, the unreachable memory becomes eligible to be freed automatically by the garbage collector.

Something similar to a memory leak may still occur if a programmer’s code holds a reference to an object that is no longer needed, typically when objects that are no longer needed are stored in containers that are still in use. If methods for a nonexistent object are called, a “NullPointerException” is thrown.

Garbage collection may happen at any time. Ideally, it will occur when a program is idle. It is guaranteed to be triggered if there is insufficient free memory on the heap to allocate a new object; this can cause a program to stall momentarily. Explicit memory management is not possible in Java.

5. Java Hello World Program

The traditional “Hello, world!” program can be written in Java as:

public class HelloWorldApplication 
{
    public static void main(String[] args) 
    {
        System.out.println("Hello World!"); 	// Prints Hello World! to the console.
    }
}
  1. Java source files must be named after the public class they contain, appending the suffix .java, for example, HelloWorldApplication.java.
  2. It must first be compiled into bytecode, using a Java compiler, producing a file named HelloWorldApplication.class. Only then can it be executed, or ‘launched’.
  3. The Java source file may only contain one public class, but it can contain multiple classes with other than public access and any number of public inner classes.
  4. When the source file contains multiple classes, make one class ‘public’ and name the source file with that public class name.

Happy Learning !!

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.

Share this:

  • Twitter
  • Facebook
  • LinkedIn
  • Reddit

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Feedback, Discussion and Comments

  1. Meher

    December 13, 2019

    Why only one class is public ?answar plz

    • Gavin L.

      December 16, 2019

      Ok I answered.

      • Meher

        January 20, 2020

        Thank you so much..God Bless you

    • Vladislav

      April 15, 2020

      That’s how Java is designed. It allows for a better structure of classes in packages and easier file parsing for Java Compiler. Also, the public class name should be the same as the file name where this class is. For example, you have public class Hello and it should be in Hello.java file. Otherwise, you will get an error

  2. Shivakumar

    September 26, 2019

    Very good article , explained each and every concepts in detail with good example

  3. Suraj Das

    July 30, 2019

    Really nice article, add some basic things in this article for better.

  4. Kumar

    May 27, 2019

    I am a new bee to Java learning but with the help of my best friend i am trying to learn the JAVA using your site & am really looking forward to find what all we need to be the Quick learner.

    I am really enthused by reading the last quote @ end of the page “HAPPY LEARNING ” 🙂

  5. Indrajeet UDawant

    May 10, 2019

    Need “Next” and “Previous” buttons in bottom.

    • Indrajeet UDawant

      January 21, 2020

      I raised a issue since 8 months.
      and till now there is no improvement ???
      I am leaving this site for forever..Good Bye

  6. ayushiyer

    December 27, 2018

    Hello, Lokesh Gupta! My name is Ayushiyer from Bangalore. Am just looking to learn java course so I did something related to java and programming. I found your article which is a really amazing article with best examples for java and java programming. From your article, I came to know the basic concepts of java. Thank you for this excellent article. Keep sharing with us… Useful for one who looking to learn java from the scratches.

Comments are closed on this article!

Search Tutorials

Java Basics

  • Java Introduction
  • Java Installation
  • Java Hello World
  • Java JDK, JRE and JVM
  • Java Classes and Objects
  • Java ClassPath
  • Java Operators
  • Java Data Types
  • Java Primitive Types
  • Java Variables
  • Java Comments
  • Java main() Method
  • Java Command Line Args
  • Java Wrapper Classes
  • Java Types of Statements
  • Java Block Statement
  • Java Pass-by-Value
  • Java System Properties
  • Java Static Import
  • Java hashCode() and equals()
  • Java Immutable Class
  • Java 32-bit vs 64-bit
  • Java java.exe vs javaw.exe
  • Java Generate Bytecode
  • Java Naming Conventions
  • Java Little-Endian vs Big-Endian

Java Tutorial

  • Java Introduction
  • Java Keywords
  • Java Flow Control
  • Java OOP
  • Java Inner Class
  • Java String
  • Java Enum
  • Java Collections
  • Java ArrayList
  • Java HashMap
  • Java Array
  • Java Sort
  • Java Clone
  • Java Date Time
  • Java Concurrency
  • Java Generics
  • Java Serialization
  • Java Input Output
  • Java New I/O
  • Java Exceptions
  • Java Annotations
  • Java Reflection
  • Java Garbage collection
  • Java JDBC
  • Java Security
  • Java Regex
  • Java Servlets
  • Java XML
  • Java Puzzles
  • Java Examples
  • Java Libraries
  • Java Resources
  • Java 14
  • Java 12
  • Java 11
  • Java 10
  • Java 9
  • Java 8
  • Java 7

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Java 15 New Features
  • Sealed Classes and Interfaces
  • EdDSA (Ed25519 / Ed448)