Java Programming Language Basics - Yash-777/LearnJava GitHub Wiki

Java is a platform independent programming language.It means that program is written once and the program is executed irrespective of the operating system.

"Write once, run anywhere" (WORA), or sometimes "write once, run everywhere" (WORE), was a slogan created by Sun Microsystems to illustrate the cross-platform benefits of the Java language.


Java Downloads for All Operating Systems « installation process

Java Programming Language

Java is a programming language and computing platform first released by Sun Microsystems in 1995. It is the underlying technology that powers Java programs including utilities, games, and business applications. Java runs on more than 850 million personal computers worldwide, and on billions of devices worldwide, including mobile and TV devices. Java is composed of a number of key components that, as a whole, create the Java platform.


Oracle provides two principal software products in the Java Platform, Standard Edition (Java SE) family:

Java SE Runtime Environment (JRE) The JRE provides the libraries, Java virtual machine, and other components necessary for you to run applets and applications written in the Java programming language. This runtime environment can be redistributed with applications to make them free-standing.

Java SE Development Kit (JDK) The JDK includes the JRE plus command-line development tools such as compilers and debuggers that are necessary or useful for developing applets and applications.

Both the Java SE Development Kit (JDK) and Java SE Runtime Environment (JRE) require at minimum a Pentium 2 266 MHz processor.

Java System PATH variable?

The PATH is the system variable that your operating system uses to locate needed executables from the command line or Terminal window.

SET PATH	= 	%JAVA_HOME%\bin		[OS to find java, javac, javap… commands]
SET JAVA_HOME	=	C:\Program Files (x86)\Java\jdk1.8.0_66 [location of a JDK home dir]

Java Update: The directory Program Files\Common Files\Java\Java Update, or Program Files (x86)\Common Files\Java\Java Update on 64-bit operating systems, contains Java Update, which enables you to keep your computer up-to-date automatically with the latest JRE releases.

Temporary Internet Files: Java SE uses the directory %APPDATA% to store temporary files. To determine the location of this directory, go to the Java Control Panel (from the Windows Control Panel). Select the General tab. In the Temporary Internet Files panel, click Settings. Note that only advanced users should modify the settings for temporary files.

In addition to the disk space required for the installed images, there must be sufficient disk space for Java Update. The following tables give the disk space requirements for the JRE and JDK, respectively:

JDK JRE Installed Image
Development Tools, including JavaFX SDK 245 MB
Source Code 27 MB
Java Runtime Environment, including JavaFX Runtime 124 MB
Java Update 2 MB

Java Runtime Edition
When you download Java, you get the Java Runtime Environment (JRE). The JRE consists of the Java Virtual Machine (JVM), Java platform core classes, and supporting Java platform libraries. All three are required to run Java applications on your computer. With Java 7, Java applications run as desktop applications from the operating system, as a desktop application but installed from the Web using Java Web Start, or as a Web Embedded application in a browser (using JavaFX).

Java Programming Language

  • Java is an object-oriented programming language that includes the following features.
  • Platform Independence - Java applications are compiled into bytecode which is stored in class files and loaded in a JVM. Since applications run in a JVM, they can be run on many different operating systems and devices.
  • Object-Oriented - Java is an object-oriented language that take many of the features of C and C++ and improves upon them.
  • Automatic Garbage Collection - Java automatically allocates and deallocates memory so programs are not burdened with that task.
  • Rich Standard Library - Java includes a vast number of premade objects that can be used to perform such tasks as input/output, networking, and date manipulation.

The Java Development Kit (JDK) is a collection of tools for developing Java applications. With the JDK, you can compile programs written in the Java Programming language and run them in a JVM. In addition, the JDK provides tools for packaging and distributing your applications.

The JDK and the JRE share the Java Application Programming Interfaces (Java API). The Java API is a collection of prepackaged libraries developers use to create Java applications. The Java API makes development easier by providing the tools to complete many common programming tasks including string manipulation, date/time processing, networking, and implementing data structures (e.g., lists, maps, stacks, and queues).

Get started with Java Technology

In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes — the machine language of the Java Virtual Machine (JVM). The java launcher tool then runs your application with an instance of the Java Virtual Machine.

Figure showing MyProgram.java, compiler, MyProgram.class, Java VM, and My Program running on a computer.
MyProgram.java

Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, the Solaris™ Operating System (Solaris OS), Linux, or Mac OS.

Figure showing source code, compiler, and Java VM's for Win32, Solaris OS/Linux, and Mac OS
Figure showing source code, compiler, and Java VM's for Win32, Solaris OS/Linux, and Mac OS

The Java Platform

A platform is the hardware or software environment in which a program runs. We've already mentioned some of the most popular platforms like Microsoft Windows, Linux, Solaris OS, and Mac OS. Most platforms can be described as a combination of the operating system and underlying hardware. The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms.

The Java platform has two components:

  • The Java Virtual Machine
  • The Java Application Programming Interface (API)

You've already been introduced to the Java Virtual Machine; it's the base for the Java platform and is ported onto various hardware-based platforms.

The API is a large collection of ready-made software components that provide many useful capabilities. It is grouped into libraries of related classes and interfaces; these libraries are known as packages. The next section, What Can Java Technology Do? highlights some of the functionality provided by the API.

Figure showing MyProgram.java, API, Java Virtual Machine, and Hardware-Based Platform
JVM

As a platform-independent environment, the Java platform can be a bit slower than native code. However, advances in compiler and virtual machine technologies are bringing performance close to that of native code without threatening portability.

The terms"Java Virtual Machine" and "JVM" mean a Virtual Machine for the Java platform.


The Java VM requires that the class you execute with it have a main method at which to begin execution of your application.
A Closer Look at the "Hello World!" Application discusses the main method in detail.

/**
 * The HelloWorldApp class implements an application that
 * simply displays "Hello World!" to the standard output.
 */
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); //Display the string.
    }
}

Java is a platform independent and object-oriented language. Being an object-oriented language, it supports OOPS concepts. All four object-oriented features including abstraction, encapsulation, inheritance, and polymorphism all are supported by Java. Java program works on the class and object concepts in order to support OOPS concepts.

Wikipedia: Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data, in the form of fields (often known as attributes), and code, in the form of procedures (often known as methods).

If you've never used an object-oriented programming language before, you'll need to learn a few basic concepts before you can begin writing any code. This lesson will introduce you to objects, classes, inheritance, interfaces, and packages. Each discussion focuses on how these concepts relate to the real world, while simultaneously providing an introduction to the syntax of the Java programming language.

An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. This lesson explains how state and behavior are represented within an object, introduces the concept of data encapsulation, and explains the benefits of designing your software in this manner.

A software object A bicycle modeled as a software object
Object Bundle Object Data

A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior.

AAA BBB
class and object Class and Object

An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. This section defines a simple interface and explains the necessary changes for any class that implements it.

Extends Class and Implements Interface together in Java Programming Hindi
Interface

If you need to inherit properties from more than one source, then Java provides the concept of interfaces.
Example: JDBC Interface common to all vendors <<Driver>> « MySQLDriver | OracleDriver

Interfaces are similar to classes. However, they define only the signature of the methods and not their implementations. The methods that are declared in the interface are implemented in the classes.

The process of binding/wrapping Data members (variable) and Member functions (methods) as a single entity/Unit.

Encapsulation in Java is a process of wrapping code and data together into a single unit, for example, a capsule which is mixed of several medicines. We can create a fully encapsulated class in Java by making all the data members of the class private.

Class - Final build, you can extend their features.
Abstract class - partial build, Some one needs to complete work to use it.
Interface - It is a contract|agreement|Imaginary build.

Abstraction

Abstraction in Java allows the user to hide non-essential details relevant to user.

Inheritance provides a powerful and natural mechanism for organizing and structuring your software. This section explains how classes inherit state and behavior from their superclasses, and explains how to derive one class from another using the simple syntax provided by the Java programming language.

Is a Relation - C1 extends C2
Has a Relation - In C2 create C1's object inorder to get access of C1's class members

Inheritance form parent to child
Inheritance

The ability of a reference variable to change the behaviour according to what object instance it is holding.
The @overriden methods behaves differently on different objcet calls.

Polymorphism allows you define one interface and have multiple implementtations.

There are two types of Polymorphism in Java

  1. Compile time polymorphism (Static binding) – Method overloading
  2. Runtime polymorphism (Dynamic binding) – Method overriding

Method Overloading and Overriding


A package is a namespace for organizing classes and interfaces in a logical manner. Placing your code into packages makes large software projects easier to manage. This section explains why this is useful, and introduces you to the Application Programming Interface (API) provided by the Java platform.

Java Language Specification

Application Programming Interface

  • Real-world objects contain state and behavior. A software object's state is stored in fields, behavior is exposed through methods.
  • Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data encapsulation.
  • A blueprint for a software object is called a class.
  • Common behavior can be defined in a superclass and inherited into a subclass using the extends keyword.
  • A collection of methods with no implementation is called an interface.
  • A namespace that organizes classes and interfaces by functionality is called a package.

Java Platform Overview https://docs.oracle.com/javase/8/docs/technotes/guides/

⚠️ **GitHub.com Fallback** ⚠️