This document provides an overview of the Java programming language. It discusses Java as both a programming language and platform. Key points include:
- Java is an object-oriented, platform-independent language that is compiled to bytecode that runs on a Java Virtual Machine.
- Java applications, applets, and servlets can be developed. Applets run in web browsers while applications and servlets run on servers.
- Java's features include simplicity, security, reliability, portability and multi-threading capabilities.
- The history of Java's development at Sun Microsystems in the 1990s is summarized, along with its growth in popularity for internet programming.
2. Overview of Java Technology
Java as a programming language
Java as a platform
Short history of the development of java
Java as a new paradigm in programming
Features of Java
Comparing java and other languages
Applications and Applets
CHAPTER-2
Introduction to Java Programming
2
3. A program is a series of instructions that are carried out by a computer.
Application programming is a programming process that is aimed at
developing an application.(e.g banking, railway .,etc)
Systems programming- is the activity of writing, amending or extending
the operating system, which is a program that runs on the computer
hardware in order to allow other applications to be run.
Introduction 3
4. Java is a general-purpose high-level object oriented programming language that
provides the following characteristics:
Simple
Object oriented
Interpreted•
Architecture-neutral
Platform independent
Multithread
Dynamic
High-performance
Distributed
Robust
Secure.
Java as a programming language
4
5. A programming language requires either a compiler or an interpreter to
translate a code written in high-level programming language (source code)
into its machine language (objectcode) equivalent.
But, to run a Java program, Java uses a combination of compiler and
interpreter.
The Java compiler translates the Java program into an intermediate code called
Java byte code.
A Java interpreter is used to run the compiled Java byte code. This allows Java
programs to run on different platforms.
A compiled Java byte code can be executed on any computer platform on
which the Java interpreter is installed.
For each type of computer, a different Java interpreter is required to interpret
the Java byte code.
5
6. Java is a strongly typed language. That means that every variable
(or expression) has a type associated with it and the type is
known at the time of compilation.
In Java, data type conversions do not take place
implicitly.
There are three kinds of Java program:
Applications These are stand-alone programs that run on a
computer.
Applets These are programs that run on a web browser.
Appletviewer is provided to ensure that these programs run
without a web browser.
Servlets These are programs that run at the server side
6
7. JAVA as a compiler and Interpreter
Object code
Java Byte
code
interpreter
Java Source
code
Compiler
7
8. A software and hardware environment in which a program runs is referred
to as a platform.
Java platform that is compatible and executes on platforms based on
different hardwares.
Java platform consists of
Java Virtual Machine(JVM)
Receives bytecode files and translates them into machine language(object code)
instructions.
E.g Unix, linux & windows
Java Applications Programming Interface(JavaAPI)
Collection of software components
API grouped in the form of packages
Java as a platform 8
9. Java is a result of efforts of programmers in the early 1990s to develop a portable,
secure and scalable language to be used for communication between electronic
devices.
A team of programmers led by James Gosling of Sun microsystems developed the first
version of Java called OAK.
Java language was meant for programming the embedded systems in consumer
electronic devices
Since the Oak trademark was already registered with some other organization, Sun
Microsystems renamed the language Java, in January 1995.
During the period when Oak was being developed, the computer world witnessed the
emergence of the Internet. As Internet usage became widespread, the need for a
portable,secure programming language increased.
Java fit the bill perfectly. Initially developed for use on different electronic devices, the
language was later adapted for Internet programming, Java met all the requirements
specified for web-based applications as it can be used to writeplatform-independent
code.
History of development of Java 9
10. In 1995, Sun Microsystems released the first version of the Java Development Kit (JDK)and HotJava, a
Java-enabled browser.
HotJava was capable of running Java applicationsin the form of Java Applets embedded in web pages, a
feature since taken up by browsers from Microsoft and Netscape. Java is often described as the World
Wide Web (www) programming language.
From the second half of the 1990s, the popularity of Java increased considerably. An important
consequence of the evolution of Java is that it has grown into a full-scale development system.
capable of being used for developing large applications that exist outside of the web (Internet)
environment that is, all kinds of program that run on a PC), including those that make extensive use of
networking to enable communication between programs.
Sun Microsystems are now working to further refine and develop Java language.
In addition,they are also working on other Java tools and applications, Prominent among these are
thefollowing:
Java Beans--the Java object component technology
JavaServer-a complete web server application written in Java, supporting serviets.•
JDBC-Java Database Connectivity, providing a Java-based interface to SQL databases.
Java Workshop a Java programming environment for developing Java programs which isitself
written in Java.
To get the latest updates on other Java tools and applications, readers can refer to the website of
Sun Microsystems-http://www.sun.com.
10
11. There are a number of other factors that are attributed to the rise in popularity of Java.
These include the following
Familiarity of Java as a programming language to users of other popular languages,
notably C++ and Smalltalk: due to this factor, users find it simple and easy to relate
and comprehend.
The Java development kit is offered free of cost
This factor allows potential users to try out language with minimal start-up cost
Its availability: Java is offered as freely downloadable software from the Sun
Microsystems website
The software is also available on other websites
Finally, its timing: Java gained popularity as it emerged at the right time when the
Internet was in its nascent stage and was all set to grow in popularity
Java as a new paradigm in programming
11
12. Features of Java
It is simple, it is highly robust, platform independent and portable
Java is simple and Object Oriented Language
Java is highly secure
Allows to develop highly reliable software applications.
Provides compile time checking and run time checking.
Java makes memory management extremely simple
12
13. Java compiler generates a byte code.
Bytecode-special format
Java byte code written in hexadecimal characters
Byte code is completely platform- independent, only the interpreter and a few
native libraries need to be ported to get java run on a new computer or OS.
The architectural –neutral and portable language platform of java is known as JVM-
Java Virtual Machine.
Java shows a high performance
Java is interpreted, threaded and dynamic
Providing multi threading capability
Multithreading in Java is a process of executing multiple
threads simultaneously.
A thread is a lightweight sub-process, the smallest unit of processing.
Multiprocessing and multithreading, both are used to achieve multitasking.
13
14. Java is dynamically linked
Does not have an explicit link space.
Java source code is divided into .java files
Compiler complies these into .class files
Other features of java – no pointers, all memory access is trusted
automatic memory allocation and deallocation
14
15. Comparing Java and other Languages
Java is similar to C and C++, but is strongly typed
Java is dynamically linked
Java is case sensitive
Java does not support pointer
Java allows single inheritance
Multiple inheritance can be achieved in java through interfaces
Java is compiled and interpreted language
15
16. Applications and Applets
Java program are compiled into applet or application
Application are stand-alone program executed by virtual machine
Applets are intended to be loaded into and interpreted by a browser, such
as Netscape or Internet explorer
A byte code cannot be modified by a programmer
16
17. Java Applet
Applet is a special type of program that is embedded in the webpage to generate the
dynamic content. It runs inside the browser and works at client side.
Advantage of Applet
There are many advantages of applet. They are as follows:
It works at client side so less response time.
Secured
It can be executed by browsers running under many platforms, including Linux, Windows,
Mac Os etc.
Drawback of Applet
Plugin is required at client browser to execute applet.
How to run an Applet?
There are two ways to run an applet
By html file.
By appletViewer tool (for testing purpose).
17
18. example of Applet by html file:
To execute the applet by html file, create an applet and compile it. After that create an
html file and place the applet code in html file. Now click the html file.
//First.java
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{
public void paint(Graphics g){
g.drawString("welcome",150,150);
}
}
Note: class must be public because its object is created by Java Plugin software that
resides on the browser.
18
19. myapplet.html
<html>
<body>
<applet code="First.class" width="300" height="300">
</applet>
</body>
</html>
To execute the applet by html file, create an applet and compile it. After that create an html
file and place the applet code in html file. Now click the html file.
19
20. Simple example of Applet by appletviewer tool:
To execute the applet by appletviewer tool, create an applet that contains applet tag in comment and
compile it. After that run it by: appletviewer First.java. Now Html file is not required but it is for testing
purpose only.
//First.java
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{
public void paint(Graphics g){
g.drawString("welcome to applet",150,150);
}
}
/*
<applet code="First.class" width="300" height="300">
</applet>
*/
20
21. To execute the applet by appletviewer tool, write in command prompt:
c:>javac First.java
c:>appletviewer First.java
21
22. Special features of java program
Access specifier
Constructors
Static
The method main()
The signature of the main method is
Public staticvoid main(String args[])
22
23. Step 1:
Write a program on the notepad and save it with .java (for
example, DemoFile.java) extension.
class Demofile
{
public static void main(String args[]) {
System.out.println("Hello!");
System.out.println("Java");
}
}
23
24. Step 2:
Open Command Prompt.
Step 3:
Set the directory in which the .java file is saved. In our case, the .java
is saved in C:demo.
Step 4:
Use the javac command to compile the Java program. It generates a
.class file in the same folder. It also shows an error if any.
javac Demofile.java
step 5:
Use the following command to run the Java program:
c:> cd demo
c:> demo> javac Demofile.Java
c:> java Demofile
output:
Hello! Java
24