Introduction to Java
Introduction to Java
Engineering
Course Code: E2UC304C Course Name:Java & Java Script
1
Faculty Name: Programe Name: B.Tech (CSE,AI &ML)
Prerequisites, Objectives and Outcomes
Prerequisite of topic: Basic concepts related to java programming
Objective: To make students aware about the different types of exceptions
along with numerous handling mechanisms available.
Outcome : 1. Student will be able to know about types of exceptions in
Java.
2. Students will be able to understand various exception handling
mechanisms.
3. Students will be able to implement in practical applications.
2
History of Java
Java technology was created as a computer programming tool in a small,
secret effort called "the Green Project" at Sun Microsystems in 1991.
They were trying to anticipate and plan for the "next wave" in computing. Their initial
conclusion was that at least one significant trend would be the convergence of digitally
controlled consumer devices and computers.
Objects are the basic units of object-oriented programming. A simple example of an object would be a
person. Logically, you would expect a person to have a name. This would be considered a property of the
person.
You would also expect a person to be able to do something, such as walking. This would be considered a
method of the person.
4
Salient Features of Java
Your Java programming language is object oriented, yet it's still dead simple.
Your development cycle is much faster because Java technology is interpreted. The compile-
link-load-test-crash-debug cycle is obsolete--now you just compile and run.
Your applications are portable across multiple platforms. Write your applications once, and you
never need to port them--they will run without modification on multiple operating systems and
hardware architectures.
Your applications are robust because the Java runtime environment manages memory for you.
5
Salient Features of Java (Cond..)
Your interactive graphical applications have high performance because
multiple concurrent threads of activity in your application are supported by
the multithreading built into the Java programming language and runtime
platform.
Your end users can trust that your applications are secure, even though
they're downloading code from all over the Internet; the Java runtime
environment has built-in protection against viruses and tampering.
6
Java Language or Platform ?
Java is one of the world's most widely used computer language. Java is a simple,
general-purpose, object-oriented, interpreted, robust, secure, architecture-neutral,
portable, high-performance, multithreaded computer language.
It is intended to let application developers "write once, run anywhere"
(WORA), meaning that code that runs on one platform does not need to be
recompiled to run on another.
Java technology is both a programming language and a platform.
Java is a high level, robust, secured and object-oriented programming language.
And any hardware or software environment in which a program runs, is known
as a platform.
Since Java has its own runtime environment (JRE) and API, it is called platform.
7
Where Java is used?
There are many devices where java is currently used.
Some of them are as follows:
Desktop Applications
Web Applications
Mobile
Embedded System
Robotics
Games etc
8
Getting Started with Java
Programming
9
Requirement of Software in Java
Programming
Download Free software Java Development Kit (JDK 1.5 or above)
One Editor to write Source code
Notepad
Edit plus
Java supporting IDE
10
JDK VERSIONS
Major release versions of Java, along with their release dates:
JDK 1.0 (January 21, 1996)
JDK 1.1 (February 19, 1997)
J2SE 1.2 (December 8, 1998)
J2SE 1.3 (May 8, 2000)
J2SE 1.4 (February 6, 2002)
J2SE 5.0 (September 30, 2004)
Java SE 6 (December 11, 2006)
Java SE 7 (July 28, 2011)
Java SE 8 (March 18, 2014)
11
JDK VERSIONS (Contd..)
JDK VERSIONS (Contd..)
3. Open an editor -> write java code -> save file with .java extension
4. Open command prompt -> To compile: - C>javac Abc.java
To run > C> java Abc
13
Life Cycle of Java Program
Life Cycle of Java Program
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 Machine1 (Java VM).
The java launcher tool then runs your application with an instance of the Java Virtual
Machine.
14
Getting Started with Java Programming
//This application program prints Welcome to Java!
public class Welcome
{
public static void main(String args[ ])
{
System.out.println("Welcome to Java!");
}
}
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Create one directory say AMIT in D drive
Save this file with name “Welcome.java” in Amit directory
15
Creating and Compiling Programs
D:\Amit>
Compile Source Code
• D:\Amit> i.e. javac Welcome.java
Result
17
Execution of Java Program
Execution of Java Program
On command line
java Filename
Bytecode
18
Write & Execute Java Program
Open Notepad
Write java program
Compile your program
D:Amit>javac Welcome.java
19
The Byte code
Compiled or interpreted?
Both.
Compiled into byte code.
Byte code is in then interpreted by the java virtual machine.
Each platform has it’s own java virtual machine on it.
There are three ways of handing the byte code.
There could be a byte-code interpreter.
There could be a byte-code compiler for the machine that is it actually
run on.
There could be a java chip (which is underdevelopment).
o The byte code is the chips actual machine language.
20
The Java Execution Model
Java source code
Platform
Java compiler
independent
Java byte-code
Java chip
Byte-code Byte-code
interpreter compiler
Java machine
22
Avoid platform dependencies: You can keep your program portable by
avoiding the use of libraries written in other languages.
Distribute software more easily: With Java Web Start software, users will
be able to launch your applications with a single click of the mouse.
An automatic version check at startup ensures that users are always up to
date with the latest version of your software. If an update is available, the
Java Web Start software will automatically update their installation.
23
Get started quickly: Although the Java programming language is a
powerful object-oriented language, it's easy to learn, especially for
programmers already familiar with C or C++.
Write less code: Comparisons of program metrics (class counts, method
counts, and so on) suggest that a program written in the Java programming
language can be four times smaller than the same program written in C++.
Write better code: The Java programming language encourages good
coding practices, and automatic garbage collection helps you avoid memory
leaks. Its object orientation, its JavaBeans™ component architecture, and its
wide-ranging, easily extendible API let you reuse existing, tested code and
introduce fewer bugs.
Develop programs more quickly: The Java programming language is
simpler than C++, and as such, your development time could be up to twice
as fast when writing in it. Your programs will also require fewer lines of code
24
References:
https://www.geeksforgeeks.org/
https://www.javatpoint.com/exception-handling-in-java
https://www.tutorialspoint.com/java/java_exceptions.htm
The complete reference, eleventh edition, available at:
https://gfgc.kar.nic.in/sirmv-science/GenericDocHandler/1
38-a2973dc6-c024-4d81-be6d-5c3344f232ce.pdf
25
Thank you
26