Вы находитесь на странице: 1из 3

Chapter 1

What Is the Java™Technology?

• Java technology is:


• A programming language
• A development environment
• An application environment
• A deployment environment
• It is similar in syntax to C++.
• It is used for developing both applets and applications.

Primary Goals of the Java Technology

• Avoiding many pitfalls of other languages


• Being object-oriented
• Enabling users to create streamlined and clear code

• Provides an interpreted environment for:

• Improved speed of development


• Code portability

The following features fulfill these goals:

• The Java Virtual Machine (JVM™)1


• Garbage collection
• The Java Runtime Environment (JRE)
• JVM tool interface

The Java Virtual Machine

• Provides hardware platform specifications


• Reads compiled byte codes that are platform-independent
• Is implemented as software or hardware
• Is implemented in a Java technology development tool or a Web browser
• Class file format
• Fatal error reporting
Garbage Collection

• Allocated memory that is no longer needed should be deallocated.


• In other languages, deallocation is the programmer’s responsibility.
• The Java programming language provides a system-level thread to track memory
allocation.
• Garbage collection has the following characteristics:
• Checks for and frees memory no longer needed
• Is done automatically
• Can vary dramatically across JVM implementations

The Java Runtime Environment

The JVM performs three main tasks:


• Loads code
• Verifies code
• Executes code

Getting Started

In the Java programming language, programs are built from classes. From a class
definition, you can create any number of objects that are known as instances of that class.

A class contains members, the primary kinds being fields and methods. Fields are data
variables belonging either to the class itself or to objects of the class; they make up the
state of the object or class. Methods are collections of statements that operate on the
fields to manipulate the state. Statements define the behavior of the classes.
Example:-
//type this code in notepad
Class MyTest
{
Public static void main(String[] args)
{
System.out.println(“Hello Java”);
}
}
Save this programme with .java extension like MyTest.java
To run this programme :-
Open Command Prompt :- Start – Run – Type CMD and press Enter Key from
keyboard.
Go to specified directory where the file is save. Set the path for JVM
Ex
D:\javatest>path=c:\programmFile\java\jdk1.5\bin
Press Enter
Compile the programme
Ex:-
D:\javaTest>javac MyTest.java
Run the programme
D:\javaTest>Java MyTest
//out put will be given
Now you have a small program that does something, but what does it mean?
The program declares a class called HelloWorld with a single member: a method
called main. Class members appear between curly braces { and } following the class
name.

The main method is a special method: the main method of a class, if declared exactly as
shown, is executed when you run the class as an application. When run, a main method
can create objects, evaluate expressions, invoke other methods, and do anything else
needed to define an application's behavior.

The main method is declared publicso that anyone can invoke it (in this case the Java
virtual machine)and static, meaning that the method belongs to the class and is not
associated with a particular instance of the class.

Preceding the method name is the return type of the method. The main method is
declared void because it doesn't return a value and so has no return type.

Following the method name is the parameter list for the methoda sequence of zero or
more pairs of types and names, separated by commas and enclosed in parentheses ( and
). The main method's only parameter is an array of String objects, referred to by the
name args. Arrays of objects are denoted by the square brackets [] that follow the type
name. In this case args will contain the program's arguments from the command line
with which it was invoked. The name of a method together with its parameter list
constitute the signature of the method. The signature and any modifiers (such as public
and static), the return type, and exception throws list form the method header. A
method declaration consists of the method header followed by the method bodya block of
statements appearing between curly braces.

In this example, the body of main contains a single statement that invokes the println
methodthe semicolon ends the statement. A method is invoked by supplying an object
reference (in this case System.outthe out field of the System class) and a method
name (println) separated by a dot (.).

Вам также может понравиться