1 - Java Basics
1 - Java Basics
Activity Grade
Midterm Exam 10%
Projects, Assignments &
Student participations 10%
What is Java ?
Developed by Sun Microsystems (now acquired by ORACLE
in 2010).
A general-purpose object-oriented language. Can be used to
develop all kinds of software so it is called as programming
suite
Based on C/C++ (Due to the similarities with C++ it is called
“Internet version of C++”)
Designed for easy Web/Internet applications
Widespread acceptance
Write Once Run Anywhere (WORA).
Java Basics
Java Editions
Java 2 Standard Edition (J2SE)
By using j2se the standalone applications
“two-tier applications”.
Standalone applications (notepad, WordPad, paint, …..etc )
are developed :
Applicable for the only one desktop hence it is called desktop
applications or window based applications.
No needs for internet connections.
It is a local application it doesn’t need any other external
application support.
Can be launched by using the command line.
Java Basics
Java Editions
Java 2 Standard Edition (J2SE)
Two-tier application (Client server application)
1. It is client-server architecture.
2. Easy to maintain and modification.
3. Exist in one or two computers
4. Direct communication.
5. Run faster
Example: communication between:
1. The desktop application to
database server.
2. The browser to web server.
3. The FTP client to FTP server.
Java Basics
Java Editions
Java 2 Enterprise Edition (J2EE)
For business applications, web services, mission-critical
systems (multi-tier applications).
By using j2ee we are able to develop the web based
applications (Gmail, banks, hotels, …).
Web-applications:-
java applications which needs client and server concept.
Java Editions
Java 2 Enterprise Edition (J2EE)
Three-tier architecture
Java Basics
Java Editions
Java 2 Enterprise Edition (J2EE)
Host Server Network Windows
Tier #2 (myshop.com Browser
Tier #1
Tier #3 Tier #4
VISA Bank
Application Network Application
Java Basics
Java Editions
Java 2 Micro Edition (J2ME)
Characteristics of Java
Java is a high-level programming language that can be characterized by
all of the following advantages:
Simple, Dynamic
High
Small and
performance
Familiar
Multithreaded
Portable
Features
of java
OOP
Robust
Language of
Secure internet Java API’s
Java Basics
Characteristics of Java
Simple, Small and Familiar
No operator overloading
Characteristics of Java
Portable (Platform independence)
If a program yields the same result on every machine, then
that program is called portable.
Java programs are portable. This is the result on java’s
independent nature
Java Basics
Characteristics of Java
Portable (Platform independence)
Java compiler generate byte-codes, not native machine code.
The compiled byte-codes are platform-independent.
Java byte-codes are translated on the fly to machine readable instructions
in runtime .
Source code Machine code Machine code
Compiler Interpreter
All computation in the JVM centers on the stack. Because the JVM has no registers
for storing values, everything must be pushed onto the stack before it can be used in a
calculation.
Byte-code instructions therefore operate primarily on the stack.
The JVM was designed as a stack-based machine rather than a register-based machine
Java Basics
Characteristics of Java
Portable (Platform independence)
Changes in system
resources will not
force any change in the
program.
Java Basics
Characteristics of Java
Secure
Characteristics of Java
Robust
Robust means Strong.
Java programs are strong and they don’t crash easily like
C and C++.
Memory allocation made by JVM not by the program.
Garbage collection de allocate the memory. [Java (and
JVM in particular) uses automatic garbage collection]
No pointer arithmetic or manual memory management.
Java Basics
Characteristics of Java
High Performance
Java performance is slower than C, because it handles
more complicated task than C language.
Characteristics of Java
Language of Internet Programming
Java Applets:
Java Applets are small java programmes created to be transmitted over internet
and downloaded by the uses on their machine.
An applet is designed to be embedded in a Web page, and run by a browser.
Applets run in a sandbox with numerous restrictions; for example, they can’t read
files and then use the network.
Java compatible web browser can download java applets without fear of viral
infection and malicious agent.
<HTML>
<HEAD>
</HEAD>
<BODY>
<div >
<APPLET CODE = "Main.class" WIDTH = "800" HEIGHT = "500"></APPLET>
</div>
</BODY> import java.applet.*;
</HTML> import java.awt.*;
public class Main extends Applet {
public void paint(Graphics g) {
g.drawString("Welcome in Java Applet.",40,20);
}}
Java Basics
Characteristics of Java
Language of Internet Programming
Java Servlet
A servlet is designed to be run by a web server
Java Basics
Characteristics of Java
Dynamic
Capable of dynamically linking a new class libraries,
methods and objects, with the OOPS pillar ‘Modularity’.
Characteristics of Java
Dynamic
Java Basics
Characteristics of Java
Multithreaded OS Review: Batch / Uni-programming
The earlier days the computer’s memory is occupied only one
program after completion of one program it is possible to
execute another program
Whenever one program execution is completed then only
second program execution will be started . This execution we
are having lot of disadvantages:
Most of the times memory will be wasted
CPU utilization will be reduced because only program allow
executing at a time.
To overcome above problems a new programming style
introduced is called “multiprogramming “
Java Basics
Characteristics of Java
Multithreaded OS Review: Multiprogramming
There are one or more programs loaded in main memory which are ready
to execute
Since there is one processor , there can be no true simultaneous
execution of different programs. Instead, the operating system
executes part of one program, then part of another, and so on. To the
user it appears that all programs are executing at the same time.
Is a simple form of parallel processing in which several programs are run
at the same time on a single processor .
Multiprogramming mainly focuses on the number of programs.
Advantages of Multiprogramming:
CPU utilization will be increased.
Execution speed will be increased and response time will be
decreased.
CPU resources are not wasted.
Java Basics
Characteristics of Java
Multithreaded OS Review: Multiprocessing
Multiprocessing refers to the hardware (i.e., the CPU units) rather than
the software (i.e., running processes)
Several variations on the basic scheme exist, e.g., multiple cores on one
CPU multiple CPU in one Computer or multiple Computers in one system.
Characteristics of Java
Multithreaded OS Review: Multitasking
in an operating system, is allowing a user to perform more than one
computer task (such as the operation of an application program) at a
time.
The operating system is able to keep track of where you are in these
tasks and go from one to the other without losing information.
Almost all of the today’s operating system are multitasking. When you
open your web browser and then open word at the same time , you are
causing the operating system to do multitasking.
Java Basics
Characteristics of Java
Multithreaded
Multithreading, the management of multiple execution paths
through the computer or of multiple users sharing the same copy
of a program.
Executing more than one thread a time is called multithreading.
Thread is nothing but separate path of sequential execution.
The thread is light weight process because whenever we are
creating thread it is not occupying the separate memory it uses
the same memory. Whenever the memory is shared means it is
not consuming more memory.
Whenever different parts of the program executed
simultaneously that each and every part is called thread.
Java Basics
Characteristics of Java
Multithreaded
Handles multiple tasks simultaneously.
Java runtime system contains tools to support
multiprocessing synchronization and construct smoothly
running interactive systems.
Java supports Threading to modulate the task and is
capable of handling it.
The main important application areas of the
multithreading are :
Developing video games
Implementing multimedia graphics.
Developing animations
Java Basics
Characteristics of Java
Object Oriented Language
Fundamentally based on OOP
Classes and Objects
Characteristics of Java
The Java API’s
Contains hundreds of classes and methods grouped into
several functional packages.
Also known as a “library”.
Contains predefined java code that we can use to develop
java programs
Faster and easier development process.
No need to write everything from scratch.
Java Basics
Primary Memory
JVM
Phase 3 Class Loader Class loader reads .class files
containing bytecodes from disk and
puts those bytecodes in memory.
Disk
Primary Memory
JVM
Phase 4 Bytecode Verifier Bytecode verifier confirms that all
bytecodes are valid and do not violate
Java’s security restrictions.
Java Environment
Java Environment called Java Development Kit (JDK) which
includes a large number of development tools and hundreds
of classes and methods. Components of JDK :
Library of classes and methods is known as the
Application Programming Interface (API).
Development tools includes :
Appletviewer (for viewing applets)
Javac (Compiler)
Java (Interpreter)
Javah (for C header files)
Javadoc (for creating HTML description)
If we run java application (no development) no need to install
JDK, we need to download and install JRE
Java Basics
Java Environment
Application Programming Interface (API)
Java = small core + extensive collection of packages
(API)
A package consists of some related Java classes:
Swing: a GUI (graphical user interface) package
AWT: Application Window Toolkit (more GUI)
util: utility data structures