Introduction to JAVA
Dr. M H B Ariyaratne
What is java
Programming Language: Java is an object-oriented, high-
level language designed to be simple, secure, and platform-
independent.
Computing Platform: Java includes the runtime
environment (JRE), the Java Virtual Machine (JVM), and
associated libraries that allow programs to run on different
hardware and operating systems.
Application Programming Interfaces (APIs): Java
provides a rich set of built-in APIs for tasks ranging from basic
input/output to networking and graphical user interfaces.
History of java
By Sun Microsystems
Initiated in 1991 as OAK
Released in 1995
Oracle acquired Sun Microsystems and took ownership in 2009
JVM
An abstract computing machine that enables a computer to run
a Java program
Java bytecode can be executed
platform dependent
Notations
Specification
Implementation
Instance
JRE
Java Runtime Environment
Provide the runtime environment.
An implementation of JVM + set of libraries + other files
JDK
Java Development Kit
JVM + few other resources such as
interpreter/loader
a compiler (javac)
an archiver (jar)
a documentation generator (Javadoc)
Java as a Language
High Level Language
Object oriented
Platform Independent - “Write once - run anywhere”
Simple
Secure
Multi-threaded
Robust
Java Editions
Java SE
Java ME
Java EE
Java FX
Tools Needed For Java
Linux/Windows Operating System
Java Development Kit
Text-editor
Optionally an IDE - Ex. Netbeans
Setting up Environment for Java
Download JDK
Set Variables
JAVA_HOME
PATH
ClassPath
Download Java Editor
Notepad
Netbeans
Eclipse
Hello World Example
In Notepad write
public class HelloWorld{
public static void main(String args[]){
System.out.print("Hello World");
save as HelloWorld.java
javac HelloWorld.java
java HelloWorld
Identifiers
to name programming entities as variables, constants, methods, classes, and packages
sequence of characters that consist of letters, digits, underscores(_), and dollar signs ($).
must start with a letter, an underscore (_), or a dollar sign ($)
Cannot start with a digit.
cannot be a reserved word
Variables
used to store data in a program
representing data of a certain type
variable declaration - the name of the variable and the type of data it represents
Declaration instructs the compiler to allocate appropriate memory space for the variable
based on its data type
Ex: double height;
Int gcs;
Assignment
After declaration of a variable
Variable name must be on the left of assignment operator
Example assignment statement - height = 1.65;
Example assignment expression - gcs = mr + vr + er;
Thank you