Lec-1
Introduction to Java
Overview
• What is Java?
• Features of Java
• Explanation of features of Java
• Tools for running Java
• First Java Program (Print “Hello World”)
• Some exercises on Java programming language
• Comments in Java
Book’s Name
1. Java the Complete Reference (Fully Updated
for JDK 7)
8th Edition
Author : Herbert Schildt
Web Source:
✓ [Link]
Java
•What is Java:
• Java is a high-level programming language originally
developed by Sun Microsystems and released in 1995.
Java runs on a variety of platforms, such as Windows, Mac
OS, and the various versions of UNIX.
Features of Java
1. Simple, Small and Familiar
2. Compiled and Interpreted
3. Object Oriented
4. Platform Independent and portable
5. Robust and Secure
6. Distributed / Network Oriented
7. Multithreaded and Interactive
8. High Performance
9. Dynamic
Simple, Small and Familiar
Similar to C/C++ in syntax
But eliminates several complexities of
No operator overloading
No direct pointer manipulation or pointer arithmetic
No multiple inheritance
No malloc() and free() – handles memory
automatically
Compiled and Interpreted
Java works in two stage
Java compiler translate the source code into byte code.
Java interpreter converts the byte code into machine
level representation.
Byte Code:
A highly optimized set of instructions to be executed by
the java runtime system, known as java virtual machine
(JVM).
Java Virtual Machine (JVM):
Object Oriented
Fundamentally based on OOP
Classes and Objects
Efficient re-use of packages such that the programmer
only cares about the interface and not the
implementation
The object model in java is simple and easy to
extend.
Platform Independent and Portable
“Write-Once Run-Anywhere”
Changes in system resources will not force any
change in the program.
The Java Virtual Machine (JVM) hides the
complexity of working on a particular platform
Convert byte code into machine level representation.
Robust and Secure
Designed with the intention of being secure
No pointer arithmetic or memory management!
Strict compile time and run time checking of data
type.
Exception handling
It verify all memory access
Ensure that no viruses are communicated with an
applet.
Distributed and Network Oriented
• Java grew up in the days of the Internet
• Inherently network friendly
• Original release of Java came with Networking
libraries
• Newer releases contain even more for handling
distributed applications
Multithreaded and Interactive
Handles multiple tasks simultaneously.
Java runtime system contains tools to support
multiprocess synchronization and construct
smoothly running interactive systems.
High Performance
Java performance is slower than C
Provisions are added to reduce overhead at runtime.
Incorporation of multithreading enhance the overall
execution speed.
Just-in-Time (JIT) can compile the byte code into
machine code.
• Can sometimes be even faster than compiled C code!
Dynamic
Capable of dynamically linking a new class libraries,
methods and objects.
Java can use efficient functions available in C/C++.
Installing new version of library automatically
updates all programs
Language of Internet Programming
Java Applets
Security
Portability
1. Applets:
Special java program that can transmitted over the
network and automatically executed by a java-
compatible web browser.
2. Security:
Java compatible web browser can download java applets
without fear of viral infection and malicious agent.
3. Portable:
Java applets can be dynamically downloaded to all the various
types of platforms connected to the internet
Why portable and Secure?
.
The output of java compiler is not executable code.
Once JVM exists for a platform, any java program can run
on it.
The execution of byte code by the JVM makes java
programs portable.
Java program is confined within the java execution
environment and cannot access the other part of the computer.
Basics of Java Environments
Java programs normally undergo five phases
Edit
Programmer writes program (and stores program on
disk)
Compile
Compiler creates bytecodes from program
Load
Class loader stores bytecodes in memory
Verify
Verifier ensures bytecodes do not violate security
requirements
Execute
Interpreter translates bytecodes into machine language
Tools for Running Java Program
• Tools:
• JRE
• JDK
• Java Editors:
• Eclipse/Netbeans
• Online site:
• [Link]
AKS-VmPBfcxr81smj3kX2z2eBIK8ao
First Java Program (Code)
package p1;
public class test1 {
public static void main(String args[])
{
[Link]("Hello World");
}
}
First Java Program (output)
• Hello World
Comments in Java
• The Java comments are the statements that are not executed by the
compiler and interpreter. The comments can be used to provide
information or explanation.
• To comment a single line \\ -this symbol is used before the comment
• Comments are place at the right side of \\
• To comment multiple lines /**/ -this symbol is used.
• Comments are placed within /* and */ -this symbol
Summary
• Introduction to Java
• Features of Java
• Phases of Java
• Tools for running Java code
• Comments in Java