You are on page 1of 3

Lab # 1

Introduction to Java
INTRODUCTION:
Object-oriented programming is a programming paradigm that uses abstraction to create models
based on the real world. Object-oriented programming is intended to promote greater flexibility
and maintainability in programming, and is widely popular in large-scale software engineering.
By virtue of its strong emphasis on modularity, object-oriented code is intended to be simpler to
develop and easier to understand later on, lending itself to more direct analysis, coding, and
understanding of complex situations and procedures than less modular programming methods

Each lab session includes many sample programs and programming problems to promote
learning and aid students in developing new and useful programming skills.

THEORY:
Introduction to 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. In 2006 Sun started to make Java available under the 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 machineand 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.
A Sample Java Program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}

class This marks the starting of java code. It is a key word of java.
public This specify the main ( ) is accessible from outside of the class
static This specify that to execute main ( ) even no class objects have been
created
void This specify that method does not return value
main JVM is responsible to execute main method
String args [] String Array data type, species that main takes some arguments
when executed (Note that is no argument specified then Sting array takes null as
the argument, hence no error occurs).
System This is name of the class that contains the object
out It is static data member of System class
println This is the method which prints the output in the dos command.
Jvm, jre and jdk

• JVM (Java Virtual Machine) is an abstract machine. It is a specification


that provides runtime environment in which java bytecode can be executed.
• JRE (Java Runtime Environment) is used to provide runtime
environment.It is the implementation of JVM.It physically exists.It contains
set of libraries + other files that JVM uses at runtime.
• JDK (Java Development Kit) it physically exists. And contains JRE +
development tools.

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.

LAB TASK:
Q1) Write a simple program to print “hello world”.
Q2) Write a program to print your name, roll no. and class.

You might also like