0% found this document useful (0 votes)
21 views5 pages

Java Introduction

The document discusses Java, including its history as a programming language created by James Gosling in 1991 to be portable across different operating systems. It also covers Java syntax, the Java virtual machine, and how to install and run a basic Java program.

Uploaded by

Dr. Vidyalatha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

Java Introduction

The document discusses Java, including its history as a programming language created by James Gosling in 1991 to be portable across different operating systems. It also covers Java syntax, the Java virtual machine, and how to install and run a basic Java program.

Uploaded by

Dr. Vidyalatha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

https://www.vogella.com/tutorials/JavaIntroduction/article.

html#installation-of-java

Introduction to Java programming:

history of Java:

Java is a programming language created by James Gosling from Sun Microsystems (Sun) in
1991. The target of Java is to write a program once and then run this program on multiple
operating systems. The first publicly available version of Java (Java 1.0) was released in
1995. Sun Microsystems was acquired by the Oracle Corporation in 2010. Oracle has now the
steermanship for Java. In 2006 Sun started to make Java available under the GNU General
Public License (GPL). Oracle continues this project called OpenJDK.

Over time new enhanced versions of Java have been released. The current version of Java is
Java 1.8 which is also known as Java 8.

Java is defined by a specification and consists of a programming language, a compiler, core


libraries and a runtime (Java virtual machine) The Java runtime allows software developers
to write program code in other languages than the Java programming language which still
runs on the Java virtual machine. The Java platform is usually associated with the Java
virtual machine and the Java core libraries.

The Java language was designed with the following properties:

 Platform independent: Java programs use the Java virtual machine as abstraction
and do not access the operating system directly. This makes Java programs
highly portable. A Java program (which is standard-compliant and follows certain
rules) can run unmodified on all supported platforms, e.g., Windows or Linux.
 Object-orientated programming language: Except the primitive data types, all
elements in Java are objects.
 Strongly-typed programming language: Java is strongly-typed, e.g., the types of
the used variables must be pre-defined and conversion to other objects is
relatively strict, e.g., must be done in most cases by the programmer.
 Interpreted and compiled language: Java source code is transferred into the
bytecode format which does not depend on the target platform. These bytecode
instructions will be interpreted by the Java Virtual machine (JVM). The JVM
contains a so-called Hotspot-Compiler which translates performance critical
bytecode instructions into native code instructions.
 Automatic memory management: Java manages the memory allocation and de-
allocation for creating new objects. The program does not have direct access to
the memory. The so-called garbage collector automatically deletes objects to
which no active pointer exists.

The Java syntax is similar to C++. Java is case-sensitive, e.g., variables


called myValue and myvalue are treated as different variables.

Hello world Java program

public class HelloWorld


{

public static void main(String[] args)

System.out.println("Hello World");

 Java virtual machine

The Java virtual machine (JVM) is a software implementation of a computer that executes
programs like a real machine.

The Java virtual machine is written specifically for a specific operating system, e.g., for
Linux a special implementation is required as well as for Windows.

Java programs are compiled by the Java compiler into bytecode. The Java virtual machine
interprets this bytecode and executes the Java program.

 Java Runtime Environment vs. Java Development Kit

A Java distribution typically comes in two flavors, the Java Runtime Environment (JRE) and
the Java Development Kit (JDK).

The JRE consists of the JVM and the Java class libraries. Those contain the necessary
functionality to start Java programs.
The JDK additionally contains the development tools necessary to create Java programs. The JDK
therefore consists of a Java compiler, the Java virtual machine and the Java class libraries.

1.5. Development Process with Java


Java source files are written as plain text documents. The programmer typically writes Java source
code in an Integrated Development Environment (IDE) for programming. An IDE supports the
programmer in the task of writing code, e.g., it provides auto-formating of the source code,
highlighting of the important keywords, etc.

At some point the programmer (or the IDE) calls the Java compiler ( javac ). The Java compiler
creates the bytecode instructions. These instructions are stored in .class files and can be
executed by the Java Virtual Machine.

1.6. Garbage collector


The JVM automatically re-collects the memory which is not referred to by other objects. The
Java garbage collector checks all object references and finds the objects which can be
automatically released.

While the garbage collector relieves the programmer from the need to explicitly manage memory,
the programmer still need to ensure that he does not keep unneeded object references, otherwise
the garbage collector cannot release the associated memory. Keeping unneeded object references
are typically called memory leaks.

1.7. Classpath
The classpath defines where the Java compiler and Java runtime look for .class files to load.
These instructions can be used in the Java program.

For example, if you want to use an external Java library you have to add this library to your
classpath to use it in your program.

2. Installation of Java
For the following exercises you need to use at least Java 11. Later versions of Java are also fine to
use.
2.1. Check installation
To run Java programs, you:

 must have the Java runtime environment (JRE) installed


 the Java executables must be available in your path environment

You can test if the JRE is correctly installed via a console. To open a console on Windows:
Win+R, enter cmd and press Enter). Now type in the following command:

java -version

If the JRE is correctly installed, this commands prints information about your Java installation. In
this case you can skip the Java installation description.

If the command line returns the information that the program could not be found, you have to
install Java.

2.2. Install Java


A Java runtime is provided by multiple suppliers, one source of a Java runtime
is https://adoptium.net/. It contains instructions how to install Java for all supported platforms. For
the Windows and Mac platform you find also native installer softare.

2.3. Installation problems and other operating


systems
If you have problems installing Java on your system, search via Google for How to install Java
runtime on YOUR OS. Of course, replace YOUR OS with your operating system, e.g., Windows,
Ubuntu, Mac OS X, etc. This should result in helpful links.
3. Exercise: Write, compile and run a
Java program
3.1. Write source code
The following Java program is developed under Linux using a text editor and the command line.
The process on other operating system should be similar, but is not covered in this description.

Select or create a new directory which will be used for your Java development. In this description
the path \home\vogella\javastarter is used. On Microsoft Windows you might want to
use c:\temp\javastarter. This path is called javadir in the following description.

You might also like