Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 99

THE WEB APPLICATION & PROGRAMMING LANGUAGE

JAVA
Programs

Computer programs, known as software, are instructions to the computer.

You tell a computer what to do through programs. Without programs, a computer is an


empty machine. Computers do not understand human languages, so you need to use
computer languages to communicate with them.

Programs are written using programming languages.

2
Programming Languages

Machine Language Assembly Language High-Level Language

Machine language is a set of primitive instructions built


into every computer. The instructions are in the form of
binary code, so you have to enter binary codes for various
instructions. Program with native machine language is a
tedious process. Moreover the programs are highly difficult
to read and modify. For example, to add two numbers, you
might write an instruction in binary like this:
 
1101101010011010
3
Popular High-Level Languages
Language Description

Ada Named for Ada Lovelace, who worked on mechanical general-purpose computers. The Ada
language was developed for the Department of Defense and is used mainly in defense projects.
BASIC Beginner’s All-purpose Symbolic Instruction Code. It was designed to be learned and used easily
by beginners.
C Developed at Bell Laboratories. C combines the power of an assembly language with the ease of
use and portability of a high-level language.
C++ C++ is an object-oriented language, based on C.
C# Pronounced “C Sharp.” It is a hybrid of Java and C++ and was developed by Microsoft.
COBOL COmmon Business Oriented Language. Used for business applications.
FORTRAN FORmula TRANslation. Popular for scientific and mathematical applications.
Java Developed by Sun Microsystems, now part of Oracle. It is widely used for developing platform-
independent Internet applications.
Pascal Named for Blaise Pascal, who pioneered calculating machines in the seventeenth century. It is a
simple, structured, general-purpose language primarily for teaching programming.
Python A simple general-purpose scripting language good for writing short programs.
Visual Visual Basic was developed by Microsoft and it enables the programmers to rapidly develop
Basic graphical user interfaces.

4
Interpreting/Compiling Source Code

A program written in a high-level language is called a source


program or source code. Because a computer cannot understand a
source program, a source program must be translated into machine
code for execution. The translation can be done using another
programming tool called an interpreter or a compiler.

5
Garbage Collection

 Java uses an automatic garbage collector to manage memory in the object lifecycle.


The programmer determines when objects are created, and the Java runtime is
responsible for recovering the memory once objects are no longer in use. Once no
references to an object remain, the unreachable memory becomes eligible to be freed
automatically by the garbage collector.
Interpreting Source Code

An interpreter reads one statement from the source code, translates it to the machine
code or virtual machine code, and
then executes it right away, as shown in the following figure. Note that a statement
from the source code may be translated into several machine instructions.

High-level Source File

… Output
area = 5 * 5 * 3.1415; Interpreter
...

7
Compiling Source Code

A compiler translates the entire source code into a machine-code file, and the machine-code
file is then executed, as shown in the following figure.

High-level Source File Machine-code File

… … Output
area = 5 * 5 * 3.1415; Compiler 0101100011011100 Executor
... 1111100011000100

...

8
Why Java?

The answer is that Java enables users to develop and deploy


applications on the Internet for servers, desktop computers, and small
hand-held devices. The future of computing is being profoundly
influenced by the Internet, and Java promises to remain a big part of
that future. Java is the Internet programming language.

Java is a general purpose programming language.


Java is the Internet programming language.

9
Java, Web, and Beyond

 Java can be used to develop Web applications.


 Java Applets
 Java Web Applications
 Java can also be used to develop applications for hand-held devices such as Palm and
cell phones

10
History of Java

 Its Starting Name is Greentalk(extension is .gt) and then after Oak.


 Sun Microsystems Inc. (US) has conceived a project to develop software for
consumer electronic devices that could be controlled by a remote (set-top boxes,
television etc). This project was called stealth project but later its name was
changed to Green project. 
 Changed the Name of Java-Island on Indonesia called Java.
 Developed Under “Green Project” Team
 Team have a 5 Members(James Gosling, Mike Sheridan, Bill Joy and Patrick
Naughton)
 Development starting in 1991 and Introduced on the year 1995 on market.
 Developed by Sun MicroSystem
 Java is used in internet programming, mobile devices, games, e-business solutions
etc.
Continue………

James Gosling and his team members were consuming a lot


of coffee while developing this language. They felt that they
were able to develop a better language because of the good
quality of coffee they consumed. So the coffee had its own
role in developing this language and good quality of coffee
was exported to the entire world from a place called 'JAVA
ISLAND'. Hence they fixed the name of the place for the
language as JAVA. And the symbol for JAVA Language is
coffee cup and saucer. 
Why Oak name for java language?

Why Oak? Oak is a symbol of strength and choosen as a


national tree of many countries like U.S.A., France,
Germany, Romania etc.
In 1995, Oak was renamed as "Java" because it
was already a trademark by Oak Technologies.

Java is an island of Indonesia where first coffee


was produced (called java coffee).
continue………

1991 James Gosling Develops Oak


1993 World Wide explodes
1995 Java Formally Announced.
1996 Java Development kit(JDK) 1.0 ships
1997 JDK1.1 Version launched
1998 JDK1.2 launched
1998 Sun introduces Community Source “open” licensing
1999-2001 JDK1.3 released
2002 Java Supports Web Services
Features of Java
Features of Java

1) Open Source
Java since its birth, till today, is an open-source product and it has all the public access. programmers are free to post entire source
code for anyone to download, copy, redistribute them. High Performance Java is an Compiler & interpreted language, so it will
never be as fast as a compiled language like C or C++. But, Java enables high performance with the use of the just-in-time
compiler.
2) Multi-Threading
Java multithreading feature makes it possible to write a program that can do many tasks simultaneously. The benefit of
multithreading is that it utilizes the same memory and other resources to execute multiple threads at the same time, like While
typing, grammatical errors are checked along.
3) Secure
When it comes to security, Java is always the first choice. With java secure features it enables us to develop virus-free, temper free
system. Java program always runs in Java runtime environment with almost null interaction with system OS, hence it is more secure.
4) Platform independent Unlike other programming languages such as C, C++ etc which are compiled into platform-specific
machines. Java is guaranteed to be write-once, run-anywhere language. On compilation, Java program is compiled into bytecode.
This bytecode is platform-independent and can be run on any machine, plus this bytecode format also provides security. Any
machine with Java Runtime Environment can run Java Programs.
5) Portability
The cross-platform feature enables the Java code to be highly portable. Programmers can write code in windows and execute the
same code in Linux Operating System.
6) Object-Oriented
In java, everything is an object which has some data and behaviour. Java can be easily extended as it is based on Object Model.
7) Robust
Java makes an effort to eliminate error-prone codes by emphasizing mainly on compile-time error checking and runtime checking.
But the main areas which Java improved were Memory Management and mishandled Exceptions by introducing automatic Garbage
Collector and Exception Handling.
Characteristics of Java

 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
17
Characteristics of Java
 Java Is Simple Java is partially modeled on C++, but greatly
 Java Is Object-Oriented simplified and improved. Some people refer to
Java as "C++--" because it is like C++ but
 Java Is Distributed with more functionality and fewer negative
 Java Is Interpreted aspects.
 Java Is Robust
 Java Is Secure
 Java Is Architecture-Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic

18
Characteristics of Java
 Java Is Simple Java is inherently object-oriented.
 Java Is Object-Oriented Although many object-oriented languages
began strictly as procedural languages,
 Java Is Distributed Java was designed from the start to be
 Java Is Interpreted object-oriented. Object-oriented
programming (OOP) is a popular
 Java Is Robust programming approach that is replacing
 Java Is Secure traditional procedural programming
 Java Is Architecture-Neutral techniques.
 Java Is Portable One of the central issues in software
 Java's Performance development is how to reuse code. Object-
oriented programming provides great
 Java Is Multithreaded flexibility, modularity, clarity, and
 Java Is Dynamic reusability through encapsulation,
inheritance, and polymorphism.

19
Characteristics of Java
 Java Is Simple Distributed computing involves several
 Java Is Object-Oriented computers working together on a network.
Java is designed to make distributed
 Java Is Distributed computing easy. Since networking
 Java Is Interpreted capability is inherently integrated into
Java, writing network programs is like
 Java Is Robust sending and receiving data to and from a
 Java Is Secure file.
 Java Is Architecture-Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic

20
Characteristics of Java
 Java Is Simple You need an interpreter to run Java
 Java Is Object-Oriented programs. The programs are compiled into
the Java Virtual Machine code called
 Java Is Distributed bytecode. The bytecode is machine-
 Java Is Interpreted independent and can run on any machine
that has a Java interpreter, which is part of
 Java Is Robust the Java Virtual Machine (JVM).
 Java Is Secure
 Java Is Architecture-Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic

21
Characteristics of Java
 Java Is Simple Java compilers can detect many problems
 Java Is Object-Oriented that would first show up at execution time
in other languages.
 Java Is Distributed
 Java Is Interpreted Java has eliminated certain types of error-
prone programming constructs found in
 Java Is Robust other languages.
 Java Is Secure
 Java Is Architecture-Neutral Java has a runtime exception-handling
feature to provide programming support
 Java Is Portable for robustness.
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic

22
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust Java implements several security
mechanisms to protect your system against
 Java Is Secure harm caused by stray programs.
 Java Is Architecture-Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic

23
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-Neutral Write once, run anywhere
 Java Is Portable
With a Java Virtual Machine (JVM),
 Java's Performance
you can write one program that will
 Java Is Multithreaded run on any platform.
 Java Is Dynamic

24
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-Neutral
 Java Is Portable
Because Java is architecture neutral,
 Java's Performance Java programs are portable. They can
 Java Is Multithreaded be run on any platform without being
recompiled.
 Java Is Dynamic

25
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-Neutral
 Java Is Portable
Java’s performance Because Java is
 Java's Performance architecture neutral, Java programs
 Java Is Multithreaded are portable. They can be run on any
platform without being recompiled.
 Java Is Dynamic

26
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded Multithread programming is smoothly
integrated in Java, whereas in other
 Java Is Dynamic languages you have to call procedures
specific to the operating system to enable
multithreading.
27
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-Neutral
 Java Is Portable
 Java's Performance Java was designed to adapt to an evolving
 Java Is Multithreaded environment. New code can be loaded on the
fly without recompilation. There is no need for
 Java Is Dynamic developers to create, and for users to install,
major new software versions. New features can
be incorporated transparently as needed.

28
Versions of Java Languages

  JDK Alpha and Beta (1995)


 JDK1.0(January 23, 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 (28th July, 2011)
  Java SE 8 (18th March, 2014)
 Java SE 9 (21th Sept, 2017)
 Java SE 10 (20th March, 2018)
Java Editions

 Java Standard Edition (J2SE)


 J2SE can be used to develop client-side standalone applications or
applets.
 Java Enterprise Edition (J2EE)
 J2EE can be used to develop server-side applications such as Java
servlets, Java ServerPages(JSP), and Java ServerFaces(JSF).

 Java Micro Edition (J2ME)


 J2ME can be used to develop applications for mobile application such
as cell phones.

30
31
Compared with C/C++

 These options are not available in Java:----


 pointers
 typedef
 preprocessor
 struct
 unions
 multiple inheritance
 goto
 operator overloading
 Calloc & Malloc
 Copy Constructor
Popular Java IDEs

 NetBeans

 Eclipse

 Blue-J

 Jcreater

 FreeJava

32
Key Differences Between C++ Vs Java
C++ Java

C++ is a platform dependent language. Java is platform-independent.


The source code written in C++ needs to be compiled on every platform. Once compiled into byte code, it can be executed on any platform.

C++ Java

C++ is a compiled language. Java is a compiled as well as an interpreted language.


The source program written The compiled output of a Java source code is a byte code which is platform-
in C++ is compiled into an object code which can then be executed to independent.
produce an output.

C++ Java

C++ code is not portable. Java, however, translates the code into byte code.
It must be compiled for each platform. This byte code is portable and can be executed on any platform.

C++ Java

Memory management in C++ is manual. In Java the memory management is system-controlled.


We need to allocate/deallocate memory manually using the new/delete
operators.

C++ Java #5) Multiple Inheritance


#6) Overloading
C++ supports various types of inheritances including single and multiple Java, supports only single inheritance.
inheritances. Effects of multiple inheritance can be achieved using the interfaces in Java.
Although there are problems arising from multiple inheritances, C++ uses
the virtual keyword to resolve the problems.
C++ Java

In C++ supports Constructor,methods and operators overloaded. This is static In Java, only method & Constructor overloading is allowed.
polymorphism. It does not allow operator overloading.

C++ Java

C++ is all about pointers. Java has limited support for pointers.
Initially, Java was completely without pointers but later versions started providing limited support
for pointers.
We cannot use pointers in Java.

C++ Java

C++ supports 2 types of comments. Java supports 3 types of comments.

C++ Java

C++ doesn’t have in-built thread support. Java supports threading concepts.
Application

According to Sun, 3 billion devices run Java. There are many devices
where Java is currently used. Some of them are as follows:----

1.Desktop Applications such as acrobat reader, media player,


antivirus, etc.
2.Web Applications such as irctc.co.in etc.
3.Enterprise Applications such as banking applications.
4.Mobile
5.Smart Card
6.Robotics
7.Games, etc.
Types of Java Applications

1) Standalone Application
Standalone applications are also known as desktop applications or
window-based applications. Ex. Media player, antivirus
2) Web Application
An application that runs on the server side and creates a dynamic
page is called a web application.

3) Enterprise Application
An application that is distributed in nature, such as banking
applications, etc. is called enterprise application. It has advantages
of the high-level security, load balancing
4) Mobile Application
An application which is created for mobile devices is called a
mobile application.
Java Identifiers

All Java components require names. Names used for classes, variables, and
methods are called identifiers.

In Java, there are several points to remember about identifiers. They are as
follows −
•All identifiers should begin with a letter (A to Z or a to z), currency character ($)
or an underscore (_).
•After the first character, identifiers can have any combination of characters.
•A key word cannot be used as an identifier.
•Most importantly, identifiers are case sensitive.
•Examples of legal identifiers: age, $salary, _value, __1_value.
•Examples of illegal identifiers: 123abc, -salary.
Access Modifier(Specifier)

Java language has four access modifier to control access levels


for classes, variable methods and constructor:-----

•Default : Default has scope only inside the same package


•Public : Public has scope that is visible everywhere
•Protected : Protected has scope within the package and all
sub classes
•Private : Private has scope only within the classes

Non-access Modifiers − final, abstract, 


Feature of Java Languages

 Simple
 Secure(Its Security is Very tight)
 Pure Object Oriented Language
 Supports Multithreading Concepts
 Supports Error Handling Concepts
 Supports Single & MultiLevel Inheritence
 It’s a Compiler & Iterpreted Language
Advantages

 Platform(OS) Independent Language


 Machine Independent Language
 Mixture of C & C++ Language
 Its supports Html Concepts
 Two types of programming available
 1) Application (for creating a Software)
2) Applet (for creating a WebSite)
Easily Understandable language
Java & WWW

 Basically designed for the web browsing


 It is a famous Web based applications
 Supports different types of Browsers
 Its supports Html formats & pages
 Java programs are plain text files,easily run on Web Browser
C C++
( Oops Concepts )
(loops,statement,array,function )

JAVA
Java ByteCodes

 Java Byte Codes are a instructions created by Java Compiler for the time of
Compilation and this Class file executed(run) by Interpreter.
 Java Byte Codes are in the form of Class files.
 Java Byte Codes are Platform Independent & Machine Independent.
 Java Byte Codes are only run in different OS
 Java Byte code is just like a Machine language(Binary language) equivalent.
44
Java JDK, JRE and JVM

What is JVM?(Interpreter)
JVM (Java Virtual Machine) is an abstract machine that enables your
computer to run a Java program.
When you run the Java program, Java compiler first compiles your Java
code to bytecode. Then, the JVM translates bytecode into native machine
code (set of instructions that a computer's CPU executes directly).
Java is a platform-independent language. It's because when you write Java
code, it's ultimately written for JVM but not your physical machine
(computer). Since, JVM ​executes the Java bytecode which is platform
independent, Java is platform-independent. 
46
Java Virtual Machine(Interpreter)

 It is an interpreter for bytecode. JVM is a platform independent and


converts Java byte code into machine language and executes it. Program
calls compiler to translate the program code into executable code that
computer can understand and execute. The executable code depends upon
the computer operating system that we use to execute our program. It is
machine dependent.

 The Java Virtual Machine(JVM) as it is popularly known, acts as an Interpreter


between Java Byte Code and & Computer’s OS.
 Using JVM you can run Java Code on any Platform such as
Macintosh,Windows,Unix,Linux,Solaries OS.
47
The Java Virtual Machine

 Bytecodes that maintain proper type discipline from the code.


 The majority of type checking is done when the code is compiled.
 Every Sun approved implementation of the JVM must be able to run any
compliant class file.
48
What is JRE?

JRE (Java Runtime Environment) is a software package that


provides Java class libraries, along with
Java Virtual Machine (JVM), and other components to run
applications written in Java programming.
JRE is the superset of JVM.
49
What is JDK?

JDK (Java Development Kit) is a software development kit to develop


applications in Java. When you download JDK,JRE is also downloaded,
and don't need to download it separately. In addition to JRE, JDK also
contains number of development tools (compilers, JavaDoc,
Java Debugger etc).
Here's the relationship between JVM, JRE, and JDK. 50
Java Application Environment

J2SE
51
54
A Picture is Worth…
Write Once, Run Anywhere
57
Java Development Process

.java => .class => JVM execution


58
Java Run-Time Environment

 Performs three main tasks: ---


 Loads code ( through using Class Loader)
 Verifies code (through using ByteCode Verifier)
 Executes code (through using JVM(Interpreter))
59
Class Loader

 Loads all classes necessary for the execution of a program


 Maintains classes of the local file system in separate "namespaces"
 Prevents spoofing
60
Bytecode Verifier

Ensures that: ----


 The code adheres to the JVM specification
 The code does not violate system integrity
 The code causes no operand stack overflows or underflows
 The parameter types for all operational code are correct
 No illegal data conversions (the conversion of integers to pointers) have
occurred
Tools Under Java

 Javac (the Compiler)


 Java (interpreter)
 Appletviewer (interpreter,test or run the Web Page)
 Javadoc ( Java Documentation )
Platform Independent

Java is platform independent because it is different


from other languages like C, C++, etc. which are
compiled into platform specific machines while Java is a
write once, run anywhere language. A platform is the
hardware or software environment in which a program
runs.
There are two types of platforms software-based
and hardware-based. Java provides a software-based
platform.
The Java platform differs from most other platforms in
the sense that it is a software-based platform that runs
on the top of other hardware-based platforms. It has
two components:----
1.Runtime Environment
2.API(Application Programming Interface)
63
Compile .java File into a .class File
(Command Line)
New Feature’s Of Java 2

 Swing (3D Applications)


 Drag & Drop (Java Beans)
 Java Sound
 Remote Method Invokation(RMI) used for Networking
programming
 Server Side Coding (Servlet & JSP)
Datatypes 
public static void main( String [] args )
•public 
This means object users can call this method
•static 
This method belongs to the class. It does not require an object to be called.

•void 
This method does not return a value.
•main 
This method is called main().
•(String [] args) 
This is a parameter list that contains a 1D array of String objects. This is the command line list. We'll still have to explain
what a command line list is, but later on.

public class abc


{
public static void main(String[] args)
{
for(int i = 1; i < args.length; i++)
{
System.out.println(args[i]);
}
}
public static void main( String [] args )
Explanation:-----

class is a keyword in Java and everything is written under the class.


public is an access modifier which provides the accessibility of main method
to all.
static is a keyword and main methods are always declared as static. There is
no need to create an object to invoke the static method.
void shows the main methods that do not return any kind of value.
String args[] is used for command line argument.
System.out.println() is used for printing the statement.
Parameters used in first java program

•Let's see what is the meaning of class, public, static, void, main, String[],
System.out.println():----

•class keyword is used to declare a class in java.


•public keyword is an access modifier which represents visibility, it means it is visible
to all.
•static is a keyword, if we declare any method as static, it is known as static
method. The core advantage of static method is that there is no need to create object
to invoke the static method. The main method is executed by the JVM, so it doesn't
require to create object to invoke the main method. So it saves memory.
•void is the return type of the method, it means it doesn't return any value.
•main represents the starting point of the program.
•String[] args is used for command line argument.
•System.out.println() is used print statement. System----is Class out-----is a
Object    print is a Method statement later.
Valid java main method signature

public static void main(String[] args)  
public static void main(String []args)  
public static void main(String args[])  
public static void main(String... args)  
static public void main(String[] args) 
public static final void main(String[] args)  
final public static void main(String[] args)  
Class Name

Every Java program must have at least one class. Each class has a name. By convention,
class names start with an uppercase letter. In this example, the class name is Welcome.

//This program prints Welcome to Java!


public class Welcome
{
public static void main(String[] args)
{
System.out.println("Welcome to Java!");
}
}

74
Main Method

Line 2 defines the main method. In order to run a class, the class must contain a
method named main. The program is executed from the main method.

//
public class Welcome
{
public static void main(String[] args)
{
System.out.println("Welcome to Java!");
}
}

75
Statement
A statement represents an action or a sequence of actions. The statement
System.out.println("Welcome to Java!")
Program in Listing is a statement to display the greeting "Welcome to Java!“.

//
public class Welcome
{
public static void main(String[] args)
{
System.out.println("Welcome to Java!");
}
}

76
Statement Terminator

Every statement in Java ends with a semicolon (;).

public class Welcome


{
public static void main(String[] args)
{
System.out.println("Welcome to Java!");
}
}
77
Reserved words
Reserved words or keywords are words that have a specific meaning to the compiler
and cannot be used for other purposes in the program. For example, when the
compiler sees the word class, it understands that the word after class is the name for
the class.

public class Welcome


{
public static void main(String[] args)
{
System.out.println("Welcome to Java!");
}
}
78
Blocks

A pair of braces in a program forms a block that groups components of a program.

public class Test {


Class block
public static void main(String[] args) {
System.out.println("Welcome to Java!"); Method block
}
}

79
C style Format Printing in Java
public class format
{
public static void main(String[] args)
{
System.out.println("Integer Value: "+String.format("%d", 125));
System.out.println("String Value: "+String.format("%s", "Hello"));
System.out.println("Float Value: "+String.format("%.2f", 125.00));
System.out.println("Hexadecimal Value: "+String.format("%x", 125));
System.out.println("Char Value: "+String.format("%c", 'a'));
}
}
Static import

The normal import declaration imports classes from packages, so that they can be
used without package reference. Similarly the static import declaration imports
static members only from classes and allowing them to be used without class
reference.
A static import declaration also comes in two flavors: single-static import and
static-import-on-demand. A single-static import declaration imports one static
member from a type. A static-import-on-demand declaration imports all static
members of a type. 
The general syntax of static import declaration is as follows:

//Single-static-import declaration:
import static <<package name>>.<<type name>>.<<static member name>>;
 //Static-import-on-demand declaration:
import static <<package name>>.<<type name>>.*;
Static import example

import static java.lang.System.out;

public class new1


{
public static void main(String[] args)
{
out.println("Hello static import!");
}
}
import static java.lang.System.*;    

class StaticImportExample
{  
  public static void main(String args[])
{  
   out.println("Hello"); //Now no need of System.out  
   out.println("Java");  
  }   
}      
Special Symbols

Character Name Description

{} Opening and closing Denotes a block to enclose statements.


braces
() Opening and closing Used with methods.
parentheses
[] Opening and closing Denotes an array.
brackets
// Double slashes Precedes a comment line.

" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
; Semicolon Marks the end of a statement.

84
85
86
Java Keywords

abstract assert boolean break

byte case catch char

class const continue default

do double else enum

extends final finally float

for goto if implements

import instanceof int interface

long native new package

private protected public return

short static foreach super

switch synchronized this throw

throws transient try void

volatile while
Software Requirements

 Windows 98 or later Version


 Browser (any)
 JDK Version (any)
Hardware’s Reuqirements

 200 Mhz Pentium(Pent-I)


 Atleast 32 or 64 MB RAM
 Display Card supporting 8,16,24,32bit display mode.
 A Sound Blaster (optional)
 A Color Monitor
Java Source
Code(Notepad)

Compilation
Javac

After Compilation

Class File
(Byte Code)

Windows Unix Linux Macintose


Solaries
JAVA
Programming

Application
Applet Programming
Programming
Application Programms

Not required any Package

Run under Java Interpreter

Execution of applications begins with main()


Applications programs are run under user’s OS

Ex. Java <filename> arguments


Applet Programms

Required a Package

Run under Java Appletviewer

Execution of applications begins with init()

Applet programs are run on Browser

Ex. Appletviewer <filename>.java


What is Java Packages

Package is a collection of Predefined classes

Packages are like a header or namespaces.

import command is used to include package in Java program

Classes are grouped together to make packages


Two types of Packages

1) Pre defined Packages or System defined Packages

2) User defined Packages


Mostly Pre defined Popular Package

import java.awt.*;
import java.applet.*;
import java.io.*;

import javax.swing.*;
import java.lang.*;
import java.util.*;

You might also like