[go: up one dir, main page]

0% found this document useful (0 votes)
19 views63 pages

Sesion 1

The document provides an overview of Java technology, including its history, features, and environment. It discusses the evolution of Java from its inception as Oak to its current status, highlighting its platform independence, object-oriented nature, and various applications. Additionally, it covers the Java Community Process (JCP) and Java Specification Requests (JSRs) that govern the development of Java technologies.

Uploaded by

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

Sesion 1

The document provides an overview of Java technology, including its history, features, and environment. It discusses the evolution of Java from its inception as Oak to its current status, highlighting its platform independence, object-oriented nature, and various applications. Additionally, it covers the Java Community Process (JCP) and Java Specification Requests (JSRs) that govern the development of Java technologies.

Uploaded by

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

UNIT I: FUNDAMENTALS OF JAVA TECHNOLOGY

AND PROGRAMMING

Java platform features,


Java technologies-JSR, JCP.
New features from Java5 to Java 7
Java -Introduction
• Java is a programming language and a platform.

• Java is a high level, robust, secured and object-oriented


programming language.

• Platform: Any hardware or software environment in which a


program runs, is known as a platform. Since Java has its own
runtime environment (JRE) and API, it is called platform.
History of Java
• 1993 Oak project at Sun
– small, robust, architecture independent, Object-Oriented, language to control
interactive TV.
– didn’t go anywhere
• 1995 Oak becomes Java
– Focus on the web
• 1996 Java 1.0 available
• 1997 (March) Java 1.1 - some language changes, much larger library, new event
handling model
• 1997 (September) Java 1.2 beta – huge increase in libraries including Swing, new
collection classes, J2EE
• 1998 (October) Java 1.2 final (Java2!)
• 2000 (April) Java 1.3 final
• 2001 Java 1.4 final (assert)
• 2004 Java 1.5 (parameterized types, enum, …) (Java5!)
• 2005 J2EE 1.5
Java – An Introduction
• Programming language developed by Sun Microsystems in 1991.
• Originally called Oak by James Gosling
• Originally created for consumer electronics ( TV, VCR, Mobile Phone, etc.)
• Internet and Web was just emerging, so Sun turned it into a language of Internet
Programming.
• Pure Object oriented language
• Java is a whole platform, with a huge library, containing lots of reusable code, and
an execution environment that provides services such as
 security
 portability across operating systems
 automatic garbage collection.

4
Need for Java
• Many different types of controllers with different set of CPU are used in electronic
devices.
• The problem with C and C++ is that designed to be compiled for a specific target.
• An attempt to solve these problems, Gosling and others began work on a portable,
platform-independent language that on a variety of CPUs under differing
environments.
• Second force was the introduction of World wide web demand a language that
could useful in creating portable application.

5
Java Environment
JDK - Java Development Kit ( Program enable users to create java applications)

JRE - Java Runtime Environment ( Software to run java programs)


IDE - Eclipse, Jcreator, NetBeans

Setting Path
MyComputer -> Environment Variables ->Advanced -> Path -> C:\Jdk1.7\bin
OR
C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.8.0_51\bin
6
Sample Helloworld application
/* Simple Helloworld Java application */

class test
{
public static void main(String[] args)
{
System.out.println(“Helloworld Java”);
}
}
// save it as test.java

Compile : javac test.java //new class file will be created in the name test.class

Execute : java test


Helloworld Java

7
Sample Java Execution

8
Platform Independency

9
Java Features
• Simple & Familiar
• Object oriented
• Interpreted
• Portable
• Reliable
• Secure
• Multithreaded
• Dynamic
• Platform Independent
• Robust
• architecture-neutral
• Distributed
Java Features
• Simple & Familiar
– fixes some clumsy features of C++
– no pointers
– automatic garbage collection
– rich pre-defined class library
http://java.sun.com/j2se/1.4.2/docs/api/
• Java programming is easy to learn, easy to develop, easy to
execute. Never you will find java hard to master.

• Java is very familiar because it was modelled on C and C++


language. Java uses many features of C and C++, therefore
java code looks like a C++ code. We can say java is
simplified version of C++.
Java Features
• Object oriented
– focus on the data (objects) and methods manipulating the
data
– all functions are associated with objects
– almost all data types are objects (files, strings, etc.)
– potentially better code organization and reuse
Platform Independent
• The output of compilation of a java program is a .class file
(byte code).
• Then JVM take the byte code and convert into machine
instruction.
• So my point is whatever the machine instruction is generated
in windows operating system, same machine instruction will
be generated in Unix and every operating system.
• For this reason Java is platform independent.
Java Features
• Interpreted
– 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 (Java Virtual Machine)
• Portable
– same application runs on all platforms
– the sizes of the primitive data types are always the same
– the libraries define portable interfaces
Java Features
• Reliable
– extensive compile-time and runtime error checking
– no pointers. Memory corruptions or unauthorized memory
accesses are impossible
– automatic garbage collection tracks objects usage over time
• Secure
– usage in networked environments requires more security
– memory allocation model is a major defense
– access restrictions are forced (private, public)
Java Features
• Multithreaded
– multiple concurrent threads of executions can run
simultaneously
– utilizes a sophisticated set of synchronization primitives
(based on monitors and condition variables paradigm) to
achieve this
• Dynamic
– java is designed to adapt to evolving environment
– libraries can freely add new methods and instance variables
without any effect on their clients
– interfaces promote flexibility and reusability in code by
specifying a set of methods an object can perform, but
leaves open how these methods should be implemented
– can check the class type in runtime
Java Features

Robust
• Java has strict compile time and runtime checking for data
types.

• Java have the capability to handle garbage things


automatically. The technique which accomplishes this is
known as garbage collection.

• Java provides exception handling mechanism which is used to


handle exceptions.
Java Features

Architecture-neutral
• Java is architecture-neutral:

• One of the major problem sfacing programmers is that no


guarantee exists that if you write a program today, it will run
tomorrow, even on the same machine.

• The java designer made JVM to alter this situation.

• The goal was "write once run anywhere, anytime forever".


.
Java Features
Distributed:
• Information is distributed on various computers over a
network.

• We can write java programs which is distributed to the clients.

• This is possible because java can handle the protocols like


TCP/IP and UDP
Java Disadvantages

• Slower than compiled language such as C


– an experiment in 1999 showed that Java was 3 or 4 times
slower than C or C++
title of the article: “Comparing Java vs. C/C++ Efficiency
Issues to Interpersonal Issues” (Lutz Prechelt)
– adequate for all but the most time-intensive programs
20
How is Java different from C++

• Java does not support pointers to avoid unauthorized access of


memory locations.
• Java does not include structures , union and enum data types.
• Java does not support operator overloading.
• Preprocessors eliminated in java
• Java does not support multiple inheritance.
New Features Added in JAVA

• Multithreading: that allows two or more pieces of the same


program to execute concurrently.
• In adds packages and interfaces.
• Java supports automatic garbage collection.
Java Applications and Java … lets
• Stand-alone Applications
– Just like any programming language
• Applet
– Run under a Java-Enabled Browser
• Midlet
– Run in a Java-Enabled Mobile Phone
• Servlet
– Run on a Java-Enabled Web Server
Java Developer's Kit (I)
• Java's programming environment
– Core Java API
– compiler
– interpreter
– debugger
– dis-assembler
– profiler
– more...
Java Developer's Kit (II)

Java Java
l e Compiler Interpreter
pi
m

n
Co

Ru
Java Source Java Bytecode

<file>.java <file>.class
Java
Dis-assembler
Prepare and Execute Java

Source Computer

Java Program Compilation Java ByteCode

Internet

Verification
Your computer

Java ByteCode Execution Restricted Env.


Write Once, Run Anywhere
Java Virtual Machine
All language compilers translate source code into machine code for a
specific computer.

How does Java achieve architecture neutrality?


The answer is that the Java compiler produces an intermediate code
known as bytecode for a machine that does not exists.

This machine is called the Java Virtual Machine and it exists only
inside the computer memory.

It is a simulated within the computer and does all major functions of


a real computer.
Java Virtual Machine

Figure illustrates the process of compiling a Java Program into bytecode


which is also referred to as virtual machine code.

The Virtual machine code is not machine specific.


The machine specific code (known as machine code) is generated by the
Java interpreter by acting as an intermediary between the virtual machine
and the real machine as shown in above figure.

Remember that the interpreter is different for different machines.


Java Virtual Machine

Figure shows whole Java works on


a typical computer.
The Java Object framework(Java
API) acts as the intermediary
between the user programs and
the virtual machine which in turn
acts as the intermediary between
the operating system and the Java
object framework.
Java Virtual Machine
JVM can be considered as a processor purely implemented with
software.

The .class file that is generated is the machine code of this


processor.

The interface that the JVM has to the .class file remains the same
irrespective of the underlying platform .

This makes platform independence possible


Byte Code

• For most languages, compilation produces machine code


• Java compilation produces “bytecode”
– Intermediate code readable by the VM
– Transferable across the Internet as applets
• VM interprets BC into instructions
– Partly responsible for performance lag
• ByteCode produced on any platform may be executed on
any other platform which supports a VM
Execution model of Java

source bytecode
(text) compiler (aka. class file)
JVML
dynamic
loading

verifier
virtual machine

JIT compiled
bytecode code
compiler
interpreter

CPU
The JIT

• Just-In-Time compiler
• Translates bytecode into machine code at runtime
– 1-time overhead when run initiated
– Performance increase 10-30 times
• Now the default for most JVM’s
– Can be turned off if desired
– JIT can apply statistical optimizations based on runtime
usage profile
Not just one JVM, but a whole family

• JVM (J2EE & J2SE)


– Well-known Java Virtual Machine.
• CVM, KVM (J2ME)
– Small devices.
– Reduces some VM features to fit resource-constrained
devices.
• JCVM (Java Card)
– Smart cards.
– It has least VM features.

• And there are also lots of other JVMs


Java Platform & VM & Devices
Java VM and API

• Java API and Virtual


Machine insulate the Java
program from hardware
dependencies.
• Java API
Java API

• Collection of ready-made • Core API


software components that – Essentials: Object,
provide many useful String, Input and
capabilities. Output...
• Grouped into libraries – Applets
(packages) of related – Networking
components. – Internationalization
– Security
– Software Components
– Object Serialization
– Java Database
Connectivity (JDBC)
Types of Java

1. Application program
2. Applet program
Application programs are called console program, and
applet program is called web based program.
Difference between Application and Applet
Java technologies-JCP,JSR
What is JCP?
• The Java Community Process (JCP), established in 1998, is
a formalized mechanism that allows interested parties to
develop standard technical specifications for Java technology.

• Anyone can become a JCP Member by filling a form available


at the JCP website. JCP membership for organizations and
commercial entities requires annual fees – but is free for
individuals.[1].
Java technologies-JCP,JSR

• The Java Community Process (JCP) is an


organization of international Java developers
and licensees whose charter is to develop and
revise Java technology specifications,
reference implementations, and technology
compatibility kits.
Java technologies-JCP,JSR
• The JCP involves the use of Java Specification
Requests (JSRs) – the formal documents that describe
proposed specifications and technologies for adding to the
Java platform.

• Formal public reviews of JSRs take place before a JSR


becomes final and the JCP Executive Committee votes on it.

• A final JSR provides a reference implementationthat is a free


implementation of the technology in source code form and a
Technology Compatibility Kit to verify the API specification.
Java technologies-JCP,JSR
MCQS
1.Java Programming was designed by
_________________.
A) Microsoft
B)Mozilla Corporation
C)Sun Microsystems
D) Amazon Inc.
MCQS
2. In the beginning , Java was created in order to

A)Connect many household machines
B)Perform Operations on the Internet
C)Create Strong Programming alternative to C++
D)Create high performance OS
MCQS
3. Earlier name of Java Programming language
was -
A)OAK
B)Netbean
C)D
D)Eclipse
MCQS
4. Which of the following personality is called as
father of Java Programming language -
A)Larry Page
B)None of these
C)Bjarne Stroustrup
D)James Gosling
MCQS
5. Why OAK was renamed to Java ?
A)because there was another language called Oak
B)None of these
C)because the language was unsuccessful , so
they created another version and changed its
name to java.
D)because the name was not relevant to the
language they created
MCQS
7. After first public release java was targeted at
______________________.
A)Search Engine Development
B)Desktop Development
C)Operating System Development
D)Internet development
MCQS
9.which kind of language java is ?
A)Event Driven
B)Procedural
C)Object Oriented
D)None of these
MCQS
11.Java allow , Same java program to be
executed on multiple operating systems.
A)True
B)False
MCQS
12. Following file is human readable in Java
programming language.
A).Java
B).Jar
C).Obj
D).Class
MCQS
13. Which of the following converts human
readable file into platform independent code
file in Java?
A)JVM
B)Applet
C)Compiler
D)JRE
MCQS
14. Platform independent code file created from
Source file is understandable by
_______________.
A)JRE
B)JVM
C)Applet
D)Compiler
MCQS
15. JVM Stands for __________________.
A)Java Virtual Machine
B)Java Virtual Machanism
C)Java Virtual Management
D)Java Virtual Memory
MCQS
16.JRE Stands for ____________.
A)Java Runtime Environment
B)Java Reply Engine
C)Java Running Engine
D)Java Runtime Engine
MCQS
17. JVM is a _____________ .
A)Debugger
B)Compiler
C)Interpreter
D)Assembler
MCQS
18. Bytecode is given as input to
_______________ .
A)JRE
B)JVM
C)Linker
D)Assembler
MCQS
19. Java Source Code is compiled into
______________.
A)Source Code
B).Obj
C).Exe
D)Bytecode
MCQS
20. Which of the tool is used to compile java
code ?
A)jar
B)javac
C)javadoc
D)java
2marks
List out the features of Java?
Why do we say java a platform independent language?
Difference between C++ and java
Difference between C and java
What is the JVM?
Describe the history of Java. Can Java run on any machine? What is needed to
run Java on a computer?
What is meant by abstraction
What is meant by Encapsulation?
What are Encapsulation, Inheritance and Polymorphism?
What are the input and output of a Java compiler?
Difference between Application and Applet
Define JCP and JSR
12 marks:

Describe the features of Java in detail?


Explain in detail about JVM and execution
model of Java

You might also like