0% found this document useful (0 votes)
3 views19 pages

java notes 3

Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1991, designed for portability and security, allowing code to run on multiple platforms without recompilation. It was initially named Oak and has evolved to include features like multithreading, dynamic linking, and a robust runtime environment through the Java Development Kit (JDK) and Java Runtime Environment (JRE). Java's architecture and features have made it a leading language for internet applications and general-purpose software development.

Uploaded by

Dhana Sekaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views19 pages

java notes 3

Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1991, designed for portability and security, allowing code to run on multiple platforms without recompilation. It was initially named Oak and has evolved to include features like multithreading, dynamic linking, and a robust runtime environment through the Java Development Kit (JDK) and Java Runtime Environment (JRE). Java's architecture and features have made it a leading language for internet applications and general-purpose software development.

Uploaded by

Dhana Sekaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Unit – I

1
Introduction to Java?
 Java is a high level, robust, secured, object-oriented programming language and platform
developed and by James Gosling and others at Sun Microsystems in 1991.
 It is a combination of features of C and C++ with some essential additional concepts.

 Java code that runs on one platform does not need to be recompiled to run on another
platform; it's called write once, run anywhere (WORA).
 It was first introduced to the public in 1995 and is widely used to
create Internet applications and other software programs.
 Today, Java (JDK) is maintained and owned by Oracle.
 Originally name known as OAK (Object Application Kernel) or Greentalk.
 Java can be used to create two types of programs.

Application Applets

An application is a program that runs on An Applet is a small window based


the user’s computers under the operating program that runs on HTML page using a
system java enabled web browser
like internet Explorer, Netscape
Navigator or an Applet Viewer.
.

Fig (a)

Java Program

2
Compiler (Byte code)

Java Virtual Machine (JVM) [Interpreter]

Execute Execute Execute

Linux OS Windows Mac OS


Fig (b)
Fig (a) and (b): Java Execution

There were five primary goals in the creation of the Java language:
1. It should use the object-oriented programming methodology.
2. It should allow the same program to be executed on multiple operating systems.
3. It should contain built-in support for using computer networks.
4. It should be designed to execute code from remote sources securely.
5. It should be easy to use by selecting what was considered the good parts of other object-
oriented languages.

Computer and its Languages:


Stage:

3
 By the end of the 1980s and the early 1990s, object-oriented programming using C++
took hold.
 Indeed, for a brief moment it seemed as if programmers had finally found the perfect
language. Because C++ blended the high efficiency and stylistic elements of C with the
object-oriented paradigm, it was a language that could be used to create a wide range of
programs.
 However, just as in the past, forces were brewing that would, once again, drive computer
language evolution forward. Within a few years, the World Wide Web and the Internet
would reach critical mass. This event would precipitate another revolution in
programming.

Origin:
 Java is a general-purpose, object-oriented programming language developed by Sun
Microsystems of USA in 1991.
 Originally called Oak by James Gosling, one of the inventors of the language, Java was
designed for the development of software for consumer electronic devices like TVs,
VCRs, toasters and such other electronic machines.
 This goal had a strong impact on the development team to make the language simple,
portable and highly reliable.
 The Java team which included Patrick Naughton discovered that the existing languages
like C and C+ + had limitations in terms of both reliability and portability.
 However, they modeled their new language Java on C and C++ but removed a number of
features of C and C++ that were considered as sources of problems and thus made Java a
really simple, reliable, portable, and powerful language.
 Below Table lists some important milestones in the development of Java.

Year Development
1990 Sun Microsystems decided to develop special software that could be used to
manipulate consumer electronic devices.
A team of Sun Micro systems programmers headed by James Gosling was formed to
undertake this task.
After exploring the possibility of using the most popular object-oriented language
1991
C+ +, the team announced a new language named "Oak".
The team, known as Green Project team by Sun, demonstrated the application of their
1992
new language to control a list of home appliances using a hand-held device with a
tiny touch sensitive screen.
The World Wide Web CNWWJ appeared on the Internet and transformed the text-
1993
based Internet into a graphical-rich environment.
The Green Project team came up with the idea of developing Web applets (tiny

4
programs) using the new language that could run on all types of computers connected
to Internet
The team developed a Web browser called "Hot Java" to locate and run applet
1994
programs on Internet.
Hot Java demonstrated the power of the new language, thus making it instantly
popular among the Internet users.
Oak was renamed "Java", due to some legal snags.
1995
Java is just a name and is not an acronym.
Many popular companies including Netscape and Microsoft announced their support
to Java.
Java established itself not only as a leader for Internet programming but also as a
1996
general purpose, object-oriented programming language.
Java found its home. Sun releases Java Development Kit 1.0
Sun releases Java Development Kit 1.1 (JDK 1.1)
1997
Sun releases Java 2 with version 1.2 of the Software Development Kit (SDK 1.2)
1998
Sun releases Java 2 Platform, Standard Edition (J2SE) and Enterprise Edition (J2EE)
1999
J2SE with JDK 1.3 was released.
2000
J2SE with JDK 1.4 was released.
2002
J2SE with JDK 5.0 (instead of JDK 1.5) was released. This is known as J2SE 5.0
2004
Java SE 6
2006
Java SE 7
2011
Java SE 8
2014
Java SE 9
2017

Table: - Java Milestone


 The most striking feature of the language is that it is a platform-neutral language.
 Java is' the first programming language that is not tied to any particular hardware or
operating system.
 Programs developed in Java can be executed anywhere on any system.

5
 We can call Java as a revolutionary technology because it has brought in a fundamental
shift in how we develop and use programs. Nothing like this has happened to the software
industry before.

(Oak is a symbol of strength and chosen as a national tree of many countries like U.S.A., France,
Germany, Romania etc.)
Features for Java:-
The inventors of Java wanted to design a language which could offer solutions to some of
the problems encountered in modern programming. They wanted the language to be not only
reliable, portable and distributed but also simple, compact and interactive.

Sun Microsystems officially describes Java with the following attributes:

Platform-Independent
and Portable
Compiled and Object-
Interpreted

Robust and Secure Distributed

Familiar, Simple and


Small High Performance

Multithreaded and Interactive Dynamic and Extensible


Although the above appears to be a list of buzzwords, they aptly describe the full
potential of the language. These features have made Java the first application language of the

6
World Wide Web. Java will also become the premier language for general purpose stand-alone
applications.

Compiled and Interpreted


 Usually a computer language is either compiled or interpreted.
 Java combines both these approaches thus making Java a two-stage system.
 First, Java compiler translates source code into what is known as bytecode instructions.
 Bytecodes are' not machine instructions and therefore, in the second stage, Java
interpreter generates machine code that can be directly executed by the machine that is
running the Java program.
 We can thus say that Java is both a compiled and an interpreted language.

Fig: Compiled and Interpreted

Platform-Independent and Portable

Fig (a) Platform-Independent

7
Fig (b) Portable
 The most significant contribution of Java over other languages is its portability.
 Java programs can be easily moved from one computer system to another, anywhere and
anytime.
 Changes and upgrades in operating systems, processors and system resources will not
force any changes in Java programs. This is the reason why Java has become a popular
language for programming on Internet which interconnects different kinds of systems
worldwide.
 We can download a Java applet from a remote computer onto our local system via
Internet and execute it locally. This makes the, Internet an extension of the user's basic
system providing practically unlimited number of accessible applets and applications.
 Java ensures portability in two ways. First, Java compiler generates bytecode instructions
that can be implemented on any machine. Secondly, the sizes of the primitive data types
are machine-independent '.

Object-Oriented
 Java is a true object-oriented language. Almost everything in Java is an object. All
program code and data reside within objects and classes.
 Java comes with an extensive set of classes, arranged in packages that we can use in our
programs by inheritance.
 The object model in Java is simple and easy to extend.

Fig: Object = Data + Methods

Robust and Secure


 Java is a robust language.
 It provides many safeguards to ensure reliable code.

8
 It has strict compile time and run time checking for data types.
 It is designed as a garbage-collected language relieving the programmers virtually all
memory management problems.
 Java also incorporates the concept of exception handling which captures series errors and
eliminates any risk of crashing the system.
 Security becomes an important issue for a language that is used for programming on
Internet.
 Threat of viruses and abuse of resources is everywhere.
 Java systems not only verify all memory access but also ensure that no viruses are
communicated with an applet.
 The absence of pointers in Java ensures that programs cannot gain access to memory
locations without proper authorization.

Fig: Secure
Distributed
 Java is designed as a distributed language for creating applications on networks.
 It has the ability to share both data and programs.
 Java applications can open and access remote objects on Internet as easily as they can do
in a local system. This enables multiple programmers at multiple remote locations to
collaborate and work together on a single project.

9
Fig: Distributed
Simple, Small and Familiar
 Java is a small and simple language.
 Many features of C and C+ + that are either redundant or sources of unreliable code are
not part of Java. For example, Java does not use pointer, preprocessor header files, goto
statement and many others.
 It also eliminates· operator overloading and multiple inheritance.
 Familiarity is another striking feature of Java.
 To make the language look familiar to the existing programmers, it was modeled on C
and C++ languages.
 Java uses many constructs of C and C++ and therefore, Java code "looks like a C++"
code. In fact, Java is a simplified version of C++.

Fig: Simple, Small and Familiar


Multithreaded and Interactive
 Multithreaded means handling multiple tasks simultaneously.
 Java supports multithreaded programs. This means that we need not wait for the
application to finish one task before beginning another.
 For example, we can listen to an audio clip while scrolling a page and at the same time
download an applet from a distant computer. This feature greatly improves the interactive
performance of graphical applications.
 The Java runtime comes with tools that support multi process synchronization and
construct smoothly running interactive systems.

10
High Performance
 Java is impressive for an interpreted language, mainly due to the use of intermediate
bytecode. According to Sun, Java speed is comparable to the native C/C++.
 Java architecture is also designed to reduce overheads during runtime.
 Further, the incorporation of multithreading enhances the overall execution speed of Java
programs.

Fig: High Performance


 Java uses Just-in-Time compiler to enable performance.
 Just-In-Time compiler is a program that turns Java bytecode into instructions that can be
sent directly to the processor

Dynamic and Extensible


 Java is a dynamic language.
 Java is capable of dynamically linking in new class libraries, methods, and objects.

11
 Java can also determine the type of class through a query, making it possible to either
dynamically link or abort the program, depending on the response.
 Java programs support functions written in other languages such as C and C+ +. These
functions are known as native methods. This facility enables the programmers to use the
efficient functions available in these languages. Native methods are linked dynamically at
runtime.

Fig: Dynamic and Extensible

JDK (Java Development Kit)

JRE
12
 JRE is an acronym for Java Runtime Environment.
 It is used to provide runtime environment.
 It is the implementation of JVM. It physically exists.
 It contains set of libraries + other files that JVM uses at runtime.
 Implementations of JVMs are also actively released by other companies besides Sun
Micro Systems.

JVM

 JVM (Java Virtual Machine) is an abstract machine.


 It is a specification that provides runtime environment in which java bytecode can be
executed.
 JVMs are available for many hardware and software platforms.
 JVM, JRE and JDK are platform dependent because configuration of each OS differs.
But, Java is platform independent. There are three notions of the JVM: specification,
implementation, and instance.

The JVM performs following main tasks:

 Loads code
 Verifies code
 Executes code
 Provides runtime environment

JDK

13
JDK is an acronym for Java Development Kit. It physically exists. It contains JRE +
development tools.

 The Java Development Kit (JDK) is a software development environment used for
developing Java applications and applets.
 It includes the Java Runtime Environment (JRE), an interpreter/loader (Java), a compiler
(javac), an archiver (jar), a documentation generator (Javadoc) and other tools needed in
Java development.
Java Development Kit is the official development kit for the Java programming language.
Java Development Kit contains the software and tools that you need to compile, debug, and run
applets and applications written using the Java programming language.
JDK has a collection of programming tools, including javac, jar, and the archiver, which
packages related class libraries into a single JAR file. This tool also helps manage JAR files,
javadoc - the documentation generator, which automatically generates documentation from
source code comments, jdb - the debugger, jps - the process status tool, which displays process
information for current Java processes, javap - the class file disassembler, and other components
are also included.

Key Contents include:

14
 Development Tools (In the bin/ subdirectory) Tools and utilities that will help you
develop, execute, debug, and document programs written in the JavaTM programming
language.

 Runtime Environment (In the jre/ subdirectory) An implementation of the Java Runtime
[

Environment (JRE) for use by the JDK. The JRE includes a Java Virtual Machine (JVM),
class libraries, and other files that support the execution of programs written in the Java
programming language.

 Additional Libraries (In the lib/ subdirectory) Additional class libraries and support
files required by the development tools.

 Demo Applets and Applications (In the demo/ subdirectory) Examples, with source
code, of programming for the Java platform. These include examples that use Swing and
other Java Foundation Classes, and the Java Platform Debugger Architecture.

 Sample Code (In the sample subdirectory) Samples, with source code, of programming
for certain Java API's.

 C header Files (In the include/ subdirectory) Header files that support native-code
programming using the Java Native Interface, the JVM Tool Interface, and other
functionality of the Java platform.

 Source Code (In src.zip) Java programming language source files for all classes that
make up the Java core API (that is, sources files for the java.*, javax.* and some org.*
packages, but not for com.sun.* packages). This source code is provided for
informational purposes only, to help developers learn and use the Java programming
language. These files do not include platform-specific implementation code and cannot
be used to rebuild the class libraries. To extract these file, use any common zip utility. Or,
you may use the Jar utility in the JDK's bin/ directory: jar xvf src.zip.

The JDK also comes with a complete Java Runtime Environment. This consists of a Java
Virtual Machine and all of the class libraries present in the production environment, as well as
additional libraries, internationalization libraries and the IDL libraries.

15
Fig: JDK

OOP

16
Comparison chart of C++ and Java

S. JAVA
C++
NO

C++ was developed by Bjarne


Java was developed by James Gosling and his
1. Stroustrup. Development began in
team. Development began in 1991.
1979.

2. C++ is a compiled language. Java is both compiled and interpreted.

C++ supports conditional


3. Java does not support conditional compilation.
compilation and inclusion.

Java programs are platform independent. Java


C++ programs are platform dependent.
programs are written for Java Virtual Machine
4. They need to be compiled for a
(JVM) and wherever a JVM is installed, Java
particular platform.
program will run without needing recompilation.

C++ does support operator


Java does not support operator overloading.
5. overloading. Function overloading is
However, function overloading is possible.
also available.

6. C++ fully support pointers. Java has restricted support for pointers. Pointers
are supported internally you can not writer pointer

17
S. JAVA
C++
NO

programs.

7. C++ supports structures. Java does not support structures.

8. C++ supports unions. Java does not support unions.

C++ does not have built-in support


9. Java fully supports threads.
for threads.

C++ supports manual object


Java relies on automatic garbage collection. It
10. management through newand delete ke
does not support destructors the way C++ does.
ywords.

C++ supports goto statement (however


Java does not support goto statement
11. the use of goto is discouraged as not
(although gotois a reserved keyword in Java)
considered a good practice)

Java does not really support multiple inheritance.


12. C++ supports multiple inheritance. But similar results can be achieved through the
use of interfaces.

C++ provides support both for call by


13. Java supports only call by value.
value and call by reference.

C++ does not support comments within In Java programs, you can write comments
14.
source code. using /** … */

C++ has no support for the unsigned Java supports the unsigned right shift >>>
15.
right shift operator ( >>> ). operator.

Java does not support virtual keyword. All the


C++ provides virtual keyword to
16. non-static Java functions are by default virtual in
support function overriding.
nature, and therefore, can be overridden.

18
19

You might also like