Sie sind auf Seite 1von 29

JAVA

By
Vagish Kirubaharan
COL/A-051935
Java is a general purpose computer programming
language that is concurrent class based object oriented
and specifically designed to have a few implementation
developments and dependencies as possible.
It is intended to let application developers "write once,
run anywhere" (WORA), meaning that compiled Java
code can run on all platforms that support Java without
the need for recompilationJava applications are
typically compiled to bytecode that can run on any Java
virtual machine (JVM) regardless of computer
architecture. As of 2016, Java is one of the most popular
programming languages in useparticularly for client-
server web applications, with a reported 9 million
developersJava was originally developed by James
Gosling at Sun Microsystems (which has since been
acquired by Oracle Corporation) and released in 1995 as
a core component of Sun Microsystems' Java platform.
The language derives much of its syntax from C and C++,
but it has fewer low-level facilities than either of them.
Writing in the Java programming language is the
primary way to produce code that will be deployed as
byte code in a Java virtual machine (JVM); byte code
compilers are also available for other languages,
including Ada, JavaScript, Python, and Ruby. In addition,
several languages have been designed to run natively
on the JVM, including Scala, Clojure and Apache Groovy.
Java syntax borrows heavily from C and C++, but object-
oriented features are modeled after Smalltalk and
Objective-CJava eschews certain low-level constructs
such as pointers and has a very simple memory model
where every object is allocated on the heap and all
variables of object types are references. Memory
management is handled through integrated automatic
garbage collection performed by the JVM.

The Java Platform


The Java platform is a suite of programs that facilitate
developing and running programs written in the Java
programming language. A Java platform will include an
execution engine (called a virtual machine), a compiler
and a set of libraries; there may also be additional
servers and alternative libraries that depend on the
requirements. Java is not specific to any processor or
operating system as Java platforms have been
implemented for a wide variety of hardware and
operating systems with a view to enable Java programs
to run identically on all of them. Different platforms
target different classes of device and application
domains.
Java Card : A technology that allows small based
applications to run on smart cards and similar small
memory devices
Java ME(Micro Edition) This Micro Edition Specifies
Several (known as profiles) for devices with limited
storage, display, and power capacities. It is often
used to develop applications for mobile devices,
PDAs, TV set-top boxes, and printers.
Java SE((Standard Edition): For general-purpose use
on desktop PCs, servers and similar devices
Java EE (Enterprise Edition): Java SE plus various
APIs which are useful for multi-tier clientserver
enterprise applications.
The Java platform consists of several programs,
each of which provides a portion of its overall
capabilities. For example, the Java compiler, which
converts Java source code into Java bytecode (an
intermediate language for the JVM), is provided as
part of the Java Development Kit (JDK). The Java
Runtime Environment (JRE), complementing the
JVM with a just-in-time (JIT) compiler, converts
intermediate bytecode into native machine code on
the fly. The Java platform also includes an extensive
set of libraries.

The essential components in the platform are the


Java language compiler, the libraries, and the
runtime environment in which Java intermediate
bytecode executes according to the rules laid out in
the virtual machine specification.
The JAVA Virtual Machine

The heart of the Java platform is the concept of a


"virtual machine" that executes Java bytecode
programs. This bytecode is the same no matter what
hardware or operating system the program is
running under. There is a JIT (Just In Time) compiler
within the Java Virtual Machine, or JVM. The JIT
compiler translates the Java bytecode into native
processor instructions at run-time and caches the
native code in memory during execution.
The Java Class Libraries

In most modern operating systems (OSs), a large


body of reusable code is provided to simplify the
programmer's job. This code is typically provided as
a set of dynamically loadable libraries that
applications can call at runtime. Because the Java
platform is not dependent on any specific operating
system, applications cannot rely on any of the pre-
existing OS libraries. Instead, the Java platform
provides a comprehensive set of its own standard
class libraries containing many of the same
reusable functions commonly found in modern
operating systems. Most of the system library is
also written in Java. For instance, the Swing library
paints the user interface and handles the events
itself, eliminating many subtle differences between
how different platforms handle components.

The Java class libraries serve three purposes within


the Java platform. First, like other standard code
libraries, the Java libraries provide the programmer
a well-known set of functions to perform common
tasks, such as maintaining lists of items or
performing complex string parsing. Second, the
class libraries provide an abstract interface to tasks
that would normally depend heavily on the
hardware and operating system. Tasks such as
network access and file access are often heavily
intertwined with the distinctive implementations of
each platform. The java.net and java.io libraries
implement an abstraction layer in native OS code,
then provide a standard interface for the Java
applications to perform those tasks. Finally, when
some underlying platform does not support all of
the features a Java application expects, the class
libraries work to gracefully handle the absent
components, either by emulation to provide a
substitute, or at least by providing a consistent way
to check for the presence of a specific feature.

The languages of Java

The word "Java", alone, usually refers to Java


programming language that was designed for use
with the Java platform. Programming languages are
typically outside of the scope of the phrase
"platform", although the Java programming
language was listed as a core part of the Java
platform before Java 7. The language and runtime
were therefore commonly considered a single unit.
However, an effort was made with the Java 7
specification to more clearly treat the Java
language and the Java virtual machine as separate
entities, so that they are no longer considered a
single unit.

Third parties have produced many compilers or


interpreters that target the JVM. Some of these are
for existing languages, while others are for
extensions to the Java language. These include.

BeanShell : A lightweight scripting language for Java


Clojure A dialect of the Lisp programming
language
Groovy A dynamic language with features similar
to those of Python, Ruby, Perl, and Smalltalk
JRuby A Ruby interpreter
Jython A Python interpreter
Kotlin An industrial programming language for
JVM with full Java interoperability
Rhino A JavaScript interpreter
Scala A multi-paradigm programming language
designed as a "better Java"
Gosu A general-purpose Java Virtual Machine-
based programming language released under the
Apache License 2.0.

The JAVA Syntax


The syntax of Java is largely influenced by C++. Unlike
C++, which combines the syntax for structured, generic,
and object-oriented programming, Java was built
almost exclusively as an object-oriented language.
All code is written inside classes and every data item
an object, with the exception of the primitive data
types, (i.e. integers, floating-point numbers, boolean
values, and characters), which are not objects for
performance reasons. Java reuses some popular aspects
of C++ (such as printf() method).
// This is an example of a single line comment using two
slashes

/* This is an example of a multiple line comment using


the slash and asterisk.
This type of comment can be used to hold a lot of
information or deactivate
code, but it is very important to remember to close the
comment. */

package fibsandlies;
import java.util.HashMap;

/**
* This is an example of a Javadoc comment; Javadoc
can compile documentation
* from this text. Javadoc comments must immediately
precede the class, method, or field being documented.
*/
public class FibCalculator extends Fibonacci implements
Calculator {
private static Map<Integer, Integer> memoized = new
HashMap<Integer, Integer>();

/*
* The main method written as follows is used by the
JVM as a starting point for the program.
*/
public static void main(String[] args) {
memoized.put(1, 1);
memoized.put(2, 1);
System.out.println(fibonacci(12)); //Get the 12th
Fibonacci number and print to console
}
/**
* An example of a method written in Java, wrapped
in a class.
* Given a non-negative number FIBINDEX, returns
* the Nth Fibonacci number, where N equals
FIBINDEX.
* @param fibIndex The index of the Fibonacci
number
* @return The Fibonacci number
*/
public static int fibonacci(int fibIndex) {
if (memoized.containsKey(fibIndex)) {
return memoized.get(fibIndex);
} else {
int answer = fibonacci(fibIndex - 1) +
fibonacci(fibIndex - 2);
memoized.put(fibIndex, answer);
return answer;
}
}
}

The Five Principles of Java Programme


These are the Five Principles
1. 1.It must be "simple, object-oriented, and familiar
2. 2.It must be "robust and secure
3. 3.It must be "architecture-neutral and portable".
4. 4.It must execute with "high performance".
5. 5.It must be "interpreted, threaded, and dynamic
The Versions of Java
As of 2017 both Java 8 and 9 are officially supported.
Major release versions of Java, along with their release
dates.
JDK 1.0 (January 23, 1996)[40]
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 (July 28, 2011)
Java SE 8 (March 18, 2014)
Java SE 9 (September 21, 2017)

Java Class Library


The Java Class Library is the standard library, developed
to support application development in Java. It is
controlled by Sun Microsystems in cooperation with
others through the Java Community Process program.
Companies or individuals participating in this process
can influence the design and development of the APIs.
This process has been a subject of controversy.

The Core features of The Java Class Library


IO/NIO
Networking
Reflection
Concurrency
Generics
Scripting/Compiler
Functional programming (Lambda, Streaming)
Collection libraries that implement data structures
such as lists, dictionaries, trees, sets, queues and
double-ended queue, or stacks[66]
XML Processing (Parsing, Transforming, Validating)
libraries
Security[67]
Internationalization and localization libraries

The integration libraries, which allow the application


writer to communicate with external systems. These
libraries include:
The Java Database Connectivity (JDBC) API for database
access
Java Naming and Directory Interface (JNDI) for lookup
and discovery
RMI and CORBA for distributed application
development
JMX for managing and monitoring applications.
JavaScript
JavaScript (/dvskrpt) often abbreviated as JS,
is a high-level, dynamic, weakly typed, prototype-
based, multi-paradigm, and interpreted
programming language. Alongside HTML and CSS,
JavaScript is one of the three core technologies of
World Wide Web content production. It is used to
make webpages interactive and provide online
programs, including video games. The majority of
websites employ it, and all modern web browsers
support it without the need for plug-ins by means
of a built-in JavaScript engine. Each of the many
JavaScript engines represent a different
implementation of JavaScript, all based on the
ECMAScript specification, with some engines not
supporting the spec fully, and with many engines
supporting additional features beyond ECMA.

Examples of JavaScript

var x; // defines the variable x and assigns to it the


special value "undefined" (not to be confused with
an undefined value)
var y = 2; // defines the variable y and assigns to it
the value 2
var z = "Hello, World!"; // defines the variable z and
assigns to it a string entitled "Hello, World.

There is no built-in I/O functionality in JavaScript;


the run-time environment provides that. The
ECMAScript specification in edition 5.1
mentions:[47]

indeed, there are no provisions in this


specification for input of external data or output of
computed results.

However, most runtime environments have a


console object that can be used to print output.
Here is a minimalist Hello World program in
JavaScript.

console.log("Hello World!");

A simple recursive function


function factorial(n) {
if (n === 0 || n === 1) {
return 1; // 0! = 1! = 1
}
return n * factorial(n - 1);
}

factorial(3); // returns 6

An anonymous function (or lambda)

function counter() {
var count = 0;
return function() {
return ++count;
};
}

var closure = counter();


closure(); // returns 1
closure(); // returns 2
closure(); // returns 3
This example shows that, in JavaScript, function
closures capture their non-local variables by
reference.

In JavaScript, objects are created in the same way


as functions, this is known as a function object.

Object example

function sum() {
var x = 0;
for (var i = 0; i < arguments.length; ++i) {
x += arguments[i];
}
return x;
}
sum(1, 2); // returns 3
sum(1, 2, 3); // returns 6

Immediately-invoked function expressions are


often used to create modules, as before
ECMAScript 2015 there was not built-in construct in
the language. Modules allow gathering properties
and methods in a namespace and making some of
them private:

var counter = (function () {


var i = 0; // private property

return { // public methods


get: function () {
alert(i);
},
set: function (value) {
i = value;
},
increment: function () {
alert(++i);
}
};
})(); // module

counter.get(); // shows 0
counter.set(6);
counter.increment(); // shows 7
counter.increment(); // shows 8

The Classes of Java

Applet
Java applets are programs that are embedded in
other applications, typically in a Web page
displayed in a web browser.

// Hello.java
import javax.swing.JApplet;
import java.awt.Graphics;

public class Hello extends JApplet {


public void paintComponent(final Graphics g) {
g.drawString("Hello, world!", 65, 95);
}
}

The Import Statements import and direct the Java


compiler to direct the javax.swing.JApplet and the
other java cooperation classes .The important
statement allows these classes to be referenced in
the source code using the simple class name (i.e.
JApplet) instead of the fully qualified class name
(FQCN, i.e. javax.swing.JApplet).

The Hello class extends (subclasses) the JApplet


(Java Applet) class; the JApplet class provides the
framework for the host application to display and
control the lifecycle of the applet. The JApplet class
is a JComponent (Java Graphical Component) which
provides the applet with the capability to display a
graphical user interface (GUI) and respond to user
events.

The Hello class overrides the


paintComponent(Graphics) method (additionally
indicated with the annotation, supported as of JDK
1.5, Override) inherited from the Container
superclass to provide the code to display the
applet. The paintComponent() method is passed a
Graphics object that contains the graphic context
used to display the applet. The paintComponent()
method calls the graphic context drawString(String,
int, int) method to display the "Hello, world!" string
at a pixel offset of (65, 95) from the upper-left
corner in the applet's display.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML


4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<!-- Hello.html -->
<html>
<head>
<title>Hello World Applet</title>
</head>
<body>
<applet code="Hello.class" width="200"
height="200">
</applet>
</body>
</html>

An applet is placed in an HTML document using the


<applet> HTML element. The applet tag has three
attributes set: code="Hello.class" specifies the
name of the JApplet class and width="200"
height="200" sets the pixel width and height of the
applet. Applets may also be embedded in HTML
using either the object or embed element,[54]
although support for these elements by web
browsers is inconsistent.[55] However, the applet
tag is deprecated, so the object tag is preferred
where supported.

The host application, typically a Web browser,


instantiates the Hello applet and creates an
initialized itself, it is added to the AWT display
hierarchy. The PaintComponent() method is called
by the AWT event dispatching thread whenever the
display needs the applet to draw itself.

The Conclusion of Java

Sun has defined and supports four editions of Java


targeting different application environments and
segmented many of its APIs so that they belong to
one of the platforms. The platforms are:
Java Card for smartcards.[70]
Java Platform, Micro Edition (Java ME) targeting
environments with limited resources.[71]
Java Platform, Standard Edition (Java SE)
targeting workstation environments.[72]
Java Platform, Enterprise Edition (Java EE)
targeting large distributed enterprise or Internet
environments.[73]

The classes in the Java APIs are organized into


separate groups called packages. Each package
contains a set of related interfaces, classes, and
exceptions. Refer to the separate platforms for a
description of the packages available.

THE END
Vagish Kirubharan
COL/A 051935

Das könnte Ihnen auch gefallen