Escolar Documentos
Profissional Documentos
Cultura Documentos
Programming
Name :
Batch :
Email: knowledge.services@sqlstar.com
No part of this publication may be reproduced (incl. photocopying) in any way, without prior
agreement and written permission of SQL Star International Ltd., Hyderabad. SQL Star
International Ltd., Hyderabad assumes no responsibility for its use, nor for any infringements
of patents or other rights of third parties which could result.
Table of Contents
Chapter Page No
TM
Chapter 03: Explaining Java Technology 01-25
SDLC Process
Understand the features of Java Technology
Major characteristics of Java programming language
Java Technology Product Groups
Java 2 Platform Standard Edition Documentation
Setting up a Java environment
Writing your first java Program
Testing the sample program
Various java tools
Chapter 1
Object-Oriented Programming
Procedural Paradigm Fallbacks
Procedural vs. Object Oriented
Object Oriented Programming
Benefits of Object Oriented Programming
Most common Reasons for Project Failure
Advantages of the OOP Approach
Objective
Introduction
To draw a real world parallel, programming languages are like civilizations. They have
followed the same phenomenon like civilizations – they rose, flourished, and declined. And
yet, like the rise and fall of nations paved the path for mankind to progress, programming
languages have evolved through time. In case of programming languages, whenever a
new language replaced its predecessor, the ongoing refinement of programming
proceeded.
Like other modern programming languages such as C++, Java uses a combination of
techniques developed over the years. Therefore, we will start exploring object-oriented
programming (OOP) by briefly looking at the history of programming languages and their
consequent developments.
Once you understand why OOP was developed, you will know exactly what makes a
programming language object-oriented.
Early days of programming or computing demanded an extremely labored process. Each
and every process had to be thoroughly checked to ensure flawless program. Early
languages were known as machine languages, which later evolved to assembly languages.
Machine language programming required programmers to code CPU instructions to
manipulate individual memory locations to achieve a desired result. Assembly language
programming provided a minimal level of abstraction by combining commonly used
sequences of instructions into higher-level instructions that could be referred by a name.
Assembly languages were easier to work with than machine languages, but programmers
soon saw the need to move beyond CPU instructions and work at a higher level of
abstraction. They achieved this abstraction through “Procedural Languages” helping
programmers to manipulate easily with functions and data types without concerning about
the underlying machine instructions. For instance, you might create a procedure to write
something to the screen, such as writeln in Pascal or printf in C. Initially, with this type
of programming you could always write these functions without any modification to any
data that existed external to them.
But as the complexity grew dramatically with increasing program size, attention focused
on how well code was actually written and how well it could be maintained. This led to the
implementation of structured development practices. “Structured development” didn't
necessarily change the languages that were being used, but rather provided a new method
of designing and writing software. Under a structured development philosophy,
programmers were expected to plan 100% of a program before writing any code. In
addition, the programmers were pushed to pre-design all their code before actually writing
any of it.
functions were introduced to reduce the size of the programs that considerably reduced
the size of the program code. But this was not a permanent solution to the problem.
“Procedural Paradigm” had a critical problem of giving more importance to the function
and treating data as a stepson. In such kind of programming, the original data gets
corrupted easily and any one who does not have the rights, can easily access, as data is
accessible to all the functions.
Try it out:
I am also an Object!
The world consists of many objects like table, cycle, computer, pen, telephone etc. In this
world, even you are an Object! Every object; be it a pen or a chair or ‘You’; has attributes
and behavior. Such objects are shown in Fig.1. All objects have features and each such
feature is called an attribute of that object. For example, ink in a pen is an attribute of
pen. The functionality of an object is called behavior. For example, writing is a behavior of
pen.
Most of the objects manipulate other objects or data. For example, a car is an object that
manipulates its speed and direction to transport people to a different location. This car
object encapsulates all the functions and data that it needs to get its job done. It has a
switch to turn it on, a steering wheel to control its direction of motion, and brakes to slow
it down. These functions directly manipulate the car's data, including direction, position,
and speed.
When you travel in a car, however, you do not have to know the details of how these
operations work. To turn a car, simply revolve the steering wheel. You do not have to
know how the steering wheel turns the car. You simply know that it works.
Seat Wheel
Steering
Objects can be part of other objects. This relationship between objects is known as
aggregation as shown in Fig. 2.
• Re-usability
• Flexibility
• Extensibility
OOP has the following benefits over conventional approaches by bundling code into
individual software objects:
• Modularity: The source code for an object can be written and maintained
independent of the source code for other objects. Once created, an object can be
easily passed around inside the system.
• Information hiding: By interacting only with an object's methods, the details of
its internal implementation remain hidden from the outside world.
• Code reusability: If an object already exists (perhaps written by another software
Try it out:
If a developer has written a code for medicine detail, can another developer
develop codes for patient detail and at the same time using medicine detail
code? What concept is used behind this?
A project may fail because of a number of reasons. Some of these are listed below.
Summary
In this chapter, you learned:
Chapter 2
Objective
At the end of this chapter, you will be able to:
¾ Class
¾ Object
¾ Abstraction
¾ Encapsulation
¾ Inheritance
¾ Polymorphism
Introduction
You have gained introductory knowledge about the “Evolution of OOP as a concept” and its
benefits over other programming models. In this chapter you will delve deeper into the
OOP model and understand what it takes to make an “OOP”.
Class
In real world, you will often find many individual objects, all of the same kind. Take the
example of a car. There may be thousands of other cars in existence, all of the same make
and model. Each car is built from the same set of blueprints and therefore contains the
same components. In object-oriented terms, we say that car is an instance of the class of
objects known as Car. A class is the blueprint from which individual objects are created.
What is a class? It is a template for multiple objects with similar features. All the features
of a particular set of objects are embodied by the class. So, it is the class and not the
actual objects that are defined when a program is written in an object-oriented language.
Object
The key to understand object-oriented technology is to have a clear understanding of
objects. What are the real-world examples of objects? Well, almost anything and
everything – your dog for instance. Or the desk you use, the computer, the bike etc.
Two characteristics shared by the real-world objects are:
1. State and
2. Behavior
A very efficient point to begin thinking in object-oriented programming is identifying the
state and behavior of real-world objects. For instance, the state for dog will be its name,
color, breed or whether it is hungry? It will also have behavior like barking, wagging tail,
fetching things, etc. Your bike will also have state (current speed, current gear, and
current wheel rotation, etc.) and behavior (acceleration, changing gear, changing wheel
rotation, etc.).
Now you can see that conceptually software objects are similar to real-world objects. They
also have state and related behavior. The state of the object is stored in fields (the
variables in some Programming languages). The internal state of an object is operated by
methods and serves as the primary mechanism for object-to-object communication.
Try it out
Abstraction
What is abstraction? It is a process that reduces the information content of a concept. It is
typically done to retain only the information which is relevant for a particular purpose. The
complexity of the program is managed by abstraction. For instance, take the white
Doberman pinscher breed of dog. Abstracting this to a dog retains only the information on
general dog attributes and behaviour.
Abstraction has four major attributes such as Coherence, Conciseness, Identity and
Completeness. These features make ‘Abstraction’ an essential element for Object-Oriented
Programming. In a sense, when someone works on a computer, it is not necessary that
he should know the working of each and every part of the computer. Even without the
hardware knowledge, he can e-mail, type or do other jobs on the computer.
Similarly, people do not think of a computer as a unit made up of hundreds of cards and
chips, but as a well-defined object with its own unique behavior. When you interact with
objects in the world, often you are only concerned with a subset of their properties.
Without this ability to abstract or filter out the extra properties of objects, you would find it
hard to process all the code and concentrate on the task at hand. As a result of
abstraction, when two different people interact with the same object, they often deal with
a different subset of attributes. Fig. 1 gives you a brief idea about abstraction. When you
are driving a car, for example, you need to know the speed of the car and the direction it
is going. Because the car is automatic, you do not need to know the RPMs of the engine.
Hence, you filter this information out. On the other hand, this information would be critical
to a racecar driver, who would not filter it out.
While constructing objects in OOP applications, it is important to incorporate the concept
of abstraction. If you were building a shipping application, you would construct a product
object with attributes, such as size and weight. The color of the item would be extraneous
information and filtered out. On the other hand, when constructing an order-entry
application, the color could be important and would be included as an attribute of the
product object.
Consider a simple “student” object. A real “student” has an identity, a family genealogy, a
medical history, a genetic profile, a credit record, a set of talents, and many more. These
are the student's attributes. Similarly, there is a rich set of actions or behaviors of which
the student is capable (singSong, doDance, getSick, increaseCreditLimit, payBills, etc.). To
know the genetic profile of the student you can abstract it out and avoid other extraneous
information.
Encapsulation
Encapsulation is a process by which you can hide data fields and methods inside the
object. It is needless to say that data fields and methods are the two main elements of an
object in the Java programming language. Encapsulation draws the demarcation line
between conventional structured Programming and object-oriented Programming.
The data of an object is always private to the object in strict object-oriented design. The
data should not be accessible directly outside the object. The access can be controlled if
you use encapsulation as you can force programs to retrieve or modify data only through
the interface of the object.
Can you think of any way in which data hiding is different from an approach of structured
programming? Data can always be hidden inside functions. You only need to keep that
data local to the function. However, soon you face a problem if you want to make the data
of one function to be available to other functions. In a structured program you can do this
by making the data global to the program, so that any function can access it. Seemingly,
you can use another level of scope. One of this is to have your data global to those
functions that need it, but at the same time prevent other functions from gaining access.
This is exactly what is done by Encapsulation. The encapsulated data members in an
object are global to the methods of an object and yet they are not global variables. They
are local to the object.
A well-established use of encapsulation in software design and development is the
separation of an interface from an implementation. Interface is viewed as the visible
external aspect of the software that must be understood to manipulate the software. The
implementation is viewed as the hidden intrinsic aspect of the software that is only
relevant to the implementers.
Inheritance
Inheritance enables you to create a class that is similar to a previously defined class.
Despite being the replica, the new class can possess its own properties.
Vehicle
The Fig. 2 can help you understand inheritance in an easy way. See how Car, Bus and
Truck inherit some characteristics or features from super class ‘Vehicle’.
In other words it is inheritance by which they derive some property from their parent
object.
Take the case of a car-simulation program. Assume that, for a regular car, you have a
class. However, now you want to create a car with a high-speed passing gear. You would
have needed to modify the existing code considerably to do this in a traditional program.
Moreover, this probably would have resulted in bugs into the code. This is where an
object-oriented approach helps, as you can create a new class by inheritance. All the data
and methods from tested base classes are inherited by this new class. The level of
inheritance can be controlled using access modifiers i.e. public, private and protected
keywords. So now, you only need to test the new code that was added to the derived
class.
Polymorphism
Polymorphism is another major feature of object-oriented programming. New objects that
perform the same functions as the base object and also perform with one or more of these
functions in a different way can be created by using polymorphism. Take a close look at
the following figure Fig. 5. Here, you may have a shape class, derived into three different
functionality with the same method draw()
• One draws a circle on the screen.
• One draws triangle on the screen.
• Another draws square on the screen.
All methods have the same name (i.e. draw()) but accomplish the drawing in a different
way.
Try it out
Class
The abstract characteristics of something (object), including its characteristics (its
attributes, fields or properties) and its behaviors (the actions it can perform, or methods,
operations or features) are defined by a ‘Class’. Modularity and structure in an object-
oriented computer program is provided by use of classes. You can identify a class if you
are familiar with the problem domain (characteristics of the class should make sense in the
given context.) Note that, code for a class should be self-contained (using encapsulation).
Properties and methods, defined by a class are collectively called members of that class.
Object
They are basic run-time entities in an object-oriented system. It is a particular instance of
a class. The class of Dog defines all possible dogs by listing the characteristics and
behaviors they can have; the object “Rayne” is one particular dog, with particular
versions of the characteristics. A Dog has fur; Rayne has brown-and-white fur. State
defines the set of values of attributes of a particular object. An object consists of state and
behavior that is defined in its class.
Method
It is an object's ability to perform some task. Rayne, being a Dog, has the ability to bark.
So bark() is one of Rayne’s methods. She may have other methods as well, for example
sit() or shake() or come(). Within the program, using a method usually affects only one
particular object; all Dogs can bark, but you need only one particular dog to do the
barking.
Inheritance
As you have probably observed, the more specialized versions of a class is called
‘subclasses’. ‘Subclasses’ inherit attributes and behaviors from their parent classes. They
are also capable of having their own attributes and behaviors.
For example, the class Dog might have sub-classes called Bulldog, French Spaniel, and
GoldenRetriever(different dog breeds). In this case, Rayne would be an instance of the
GoldenRetriever subclass. Suppose the Dog class defines a method called bark() and a
property called Color. Each of its sub-classes (Bulldog, French Spaniel, and
GoldenRetriever) will inherit these members, meaning that the programmer only needs to
write the code for them once.
Each subclass can alter its inherited features. For example, the GoldenRetriever class
might specify that the default Color for a GoldenRetriever is possibly reddish. The French
Spaniel subclass might specify that the bark() method produces a high pitch by default.
Subclasses can also add new members. The French Spaniel subclass could add a method
called tremble(). So an individual French spaniel instance would use a high-pitched bark()
from the French Spaniel subclass, which in turn inherited the usual bark() from Dog. The
French spaniel object would also have the tremble() method, but “Panther” would not,
because he is a “Bulldog”, not a French Spaniel. In fact, inheritance is an ‘is-a’
relationship: “Panther” is a “Bulldog”. A “Bulldog” is a “Dog”. Thus, Panther inherits the
methods of both Bulldog and Dog.
Encapsulation
Encapsulation conceals the functional details of a class from other objects that send
messages to it. In a strict object-oriented design, an object's data is always private to the
object. Other parts of a program should never have direct access to that data. With
encapsulation, you can control access to data, forcing programs to retrieve or modify data
only through an interface provided by that object.
For example, the Dog class has a bark() method. The code for the bark() method defines
exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and
volume). You, the Panther's master, however, do not need to know exactly how he barks.
Encapsulation is achieved by specifying which classes may use the members of an object.
The result is that each object exposes to any class a certain interface — those members
accessible to that class. Members are often specified as public, protected or private,
determining whether they are available to all classes, sub-classes or only the defining
class(See: Table below).
A well-established use of encapsulation in software design and development is the
separation of an interface from an implementation. Interface is the visible external aspect
of the software that must be understood to manipulate the software.
Abstraction
What is abstraction? Abstraction talks about simplifying complex reality by modeling
classes appropriate to the problem. Appropriation also includes working at the most
appropriate level of inheritance for a given aspect of the problem.
For example, Panther the Dog may be treated as a Dog much of the time, a Bulldog when
necessary to access Bulldog-specific attributes or behaviors, and as an Animal (the parent
class of Dog) when counting Animals in the city.
You can achieve abstraction through Composition. Consider the example of the Car.
Objects like an Engine, a Gearbox, a Steering wheel and other components are used to
build a class Car. Now, you do not need to know how do the different components work
internally. To make a Car class you only need to know how to interface with them. Here
interface provides the way to send and receive messages to and from them, or make
different objects composing the class interact with each other.
Polymorphism
You are allowed by polymorphism to treat derived class members just like the members of
their parent classes. In object-oriented programming, polymorphism is known as the
ability of objects (belonging to different data types) to respond to method calls of the
same name, each one according to an appropriate type-specific behavior. You can
abstractly apply a method or an operator like +, -, or * in many different situations. For
instance, a dog may elicit a bark() if it is commanded to speak(). A pig, if it is commanded
to speak() might elicit an oink(). Both of them inherit speak() from Animal. However, their
derived class methods override the methods of the parent class. This is Overriding
Polymorphism.
The use of one method signature, or one operator such as ‘+’, to perform several different
functions depending on the implementation is called Overloading Polymorphism. You might
use ‘+’ operator to perform integer addition, float addition, list concatenation, or string
concatenation. Then any two subclasses of number, such as integer and double, are
expected to be added together properly in an Object Oriented Programming language. The
concatenation operator, ‘+’, should be overloaded by the language so that it can work in
this way. Code readability is improved in this way. Most OOP languages support at least
some level of overloading polymorphism, though their implementation varies from
language to language. Parametric Polymorphism is supported by many Object Oriented
Programming Languages. Here the code can be used transparently with any number of
new types since it is written without the mention of any specific type. Can you think of any
example? Pointers are examples of simple polymorphic routines, which can be used with
many different types of objects.
identity, specific attributes and behaviors. Note that instance and object
are often used interchangeably.
instantiation Instantiating a class creates a new instance / object of that class.
reference All objects in Java are accessed by reference, as it is a data element
whose value is an address. Note that any object variable will not be the
object itself, but is actually a reference to such an object.
subclass A subclass is derived from and is a specialization of the generalized
superclass. It is derived from an associated superclass in an inheritance
hierarchy.
superclass A superclass (parent class or base class are the other names for this) is
a more generalized class in an inheritance hierarchy. A subclass will be
derived from a superclass.
single Subclass contains single inheritance at the time. It is derived from a
inheritance single superclass.
multiple Java allows multiple-inheritance only through interfaces i.e. A subclass
inheritance that is derived from a superclass can implement an interface
class Also known as static attributes, class attributes of a class are shared by
attribute all instances of the class. Only one copy will exists for each class
attribute in the class and they will be accessible without creation of any
instance of the class.
class method Known also as static method, this method can operate only on class
attributes and is defined in the class. Can be used without the creation of
any instance of the class.
instance Attribute of a class, which is associated with a particular instance of the
attribute class. Each instance has their own copies of instance attributes.
instance The most common type of method defined by a class and operating on
method instance attributes. Note that this method is used only with its
associated instance of the class.
Visibility of Members
The ability of one class to see and use the resources of another class is known as visibility
of members. Various programming language features like Java's public, protected, and
private access specifiers control visibility.
Public As the name suggests, any other class can access the public items of a
Visibility class. Because their attributes and operations are visible to the whole
world.
Private As the name suggests, only the members of the given class can view the
Visibility private attributes and operations.
Protected Only the class and its subclasses can view the Protected attributes and
Visibility operations.
Try it out
A Car inherits the property of Vehicle class. If you have written the code for
Vehicle class in which you want it to be accessed only within Car class, then
what specifier is used?
Summary
Chapter 3
Objective
Introduction
We have discussed various concepts of Object Oriented Programming Structure. The base
of the OOP is an object. We have talked about classes. Then, we have discussed the four
corner stones of Object Oriented Programming Structure such as Abstraction,
Encapsulation, Inheritance, and Polymorphism. We have studied an example to
understand the features of OOP better. We have looked into some of the OOP
terminologies. In this chapter, we will discuss about stages of a Software development life
cycle. We will learn various features of Java technology. We will then proceed with Java
technology products provided by Sun Microsystems.
• What is the new data requirement from the users? Can any redundant
data or useless data be rejected?
Testing is performed on sample data and then with real time data (extracted from the
existing system).
System maintenance plan includes plans for:
¾ User technical support
¾ Handling unanticipated problems
¾ Technical training
Fixing of system bugs:
• Simple
• Robust
• Portable
• Interpreted
• Platform-independent
• Multithreaded
• Secure
• Distributed
• High Performance
• Dynamic
Simple:
The Simplicity of Java is enhanced by its similarities to 'C' and C++. Java has simplified
C++ programming by adding features beyond those found in C++ and by removing some
of the features that make C++ a complicated and difficult language to master.
The Java Programming Language is simple because the designers removed some of the
complex programming constructs found in other popular programming languages like
direct manipulation of memory addresses using Pointers, Operator Overloading, etc.
It consists of only a few primitive data types. It is interpreted. The runtime environment
provides automatic memory allocation.
The Java programming language allows programmers to manipulate objects using object
references.
Java also uses Garbage Collector for automatic memory management, which has following
advantages:
• No Dangling Pointers
• No Memory Leaks
No use of Header Files unlike C and C++.
The language is small, so it is easy to become fluent in. The language is interpreted so the
compile-run-link cycle is much shorter. The runtime environment provides automatic
memory allocation and so there is less for the programmer to think about.
Robust:
Designers of Java anticipated it to be used to solve some very complex programming
problems. Writing a program that can run on a variety of operating systems with a variety
of processors is not a simple task. To do it successfully, you need all the help that your
programming language can offer. With this in mind, data type issues and problems are
resolved at compile time.
Memory management has been simplified in Java in two ways. Firstly, Java does not
support direct pointer manipulation or arithmetic. This makes it impossible for a Java
program to overwrite memory or corrupt data. Secondly, Java uses runtime garbage
collection instead of explicit freeing of memory.
The Java Programming Language is a Robust Language. Robust means all the data type
issues and problems are handled and resolved at compile-time. This reduces possibilities
of runtime errors. Also assignment issues are taken care of at runtime,.
Memory management has been simplified in terms of:
y No support for direct pointer manipulation
y Provided with runtime automatic garbage collection for implicitly freeing memory.
y
Portable:
In addition to being architecture-neutral, Java code is also portable. It was an important
design goal of Java that it be portable so that as new architectures (due to hardware,
operating system, or both) are developed, the Java environment could be ported to them.
In Java, all primitive types (integer, long, float, double, and so on) are of defined sizes,
regardless of the machine or operating system on which the program is run. This is in
direct contrast to languages like C and C++ that leave the sizes of primitive types up to
the compiler and developer.
Additionally, Java is portable because the compiler itself is written in Java.
Following figure, (Fig 6) shows the Java runtime environment portable features:
Interpreted:
Because Java is interpreted, once the Java interpreter has been ported to a specific
machine, that machine can instantly run Java applications. As an example of the
usefulness of this, imagine a hypothetical chip manufacturer, etc. that has just finished its
newest CPU chip. This new chip named the Zintium, serves as the foundation of a new line
of computers. Once Etnal ports the java interpreter to work on the Zintium, the new
machine will be able to run all of the Java development utilities – the compiler, the
debugger, and so on. Contrast this with a traditional language. If Etnal wants to release a
C++ compiler with its new computer it must port, or create from scratch, the compiler, the
debugger, the runtime library, and so on. Another advantage is that the time-consuming
edit-compile-link-test cycle is broken. Without the compile and link steps, working in an
interpreted environment is a much simpler edit-test cycle. Without having to wait for
lengthy compiles and links, Java promotes prototyping and easier debugging.
Moreover, each and every system will be having the Java Virtual Machine, which will be
working like interpreter. The job of the Java Interpreter is to convert the Java Bytecode to
its corresponding platform specific code and execute it to provide the output. The Java
Virtual Machine is also responsible for implementing security using ClassLoader and
SecurityManager classes.
Fig 7. Object-Oriented
Platform Independent:
Programs written in C and C++ create object codes on compilation. The object code keeps
information about the platform in which it is compiled. So object code created in one
platform cannot be executed in another platform; it can be executed only in the platform
where it is created.
Programs written in Java Programming Language, when compiled get converted to a
Bytecode format that can be accessed from any platform that has Java Virtual Machine
(JVM). In order to execute the Bytecode the platform needs a Java Virtual Machine to be
installed which will interpret the Bytecode to its corresponding platform dependent code.
As the Bytecode depends on JVM and not on the platform, it makes Java Language
platform independent.
Multithreaded:
What is multithreaded programming? It is the practice of executing software in a fashion
that enables two or more activities to be performed in parallel within the same application.
This is accomplished by having each activity execute in its own thread.
Threads are separate tasks running within a program and they share memory space and
resources with each other.
For example, if effectively used, they can prevent the user interface from being tied up
while the program is performing a lengthy operation because both these activities will be
running in separate threads.
Writing a computer program that only does a single thing at a time is an artificial
constraint that we have lived with in most programming languages. With Java, we no
longer have to live with this limitation. Support for multiple, synchronized threads is built
directly into the Java language and runtime environment.
Synchronized threads are extremely useful in creating distributed, network-aware
applications. Such an application may be communicating with a remote server in one
thread while interacting with a user in a different thread.
The Java Programming Language supports multithreaded programming i.e. performing
several tasks at a time, such as querying a database on one hand while displaying a user
interface on the other hand. Multithreading allows Java technology program to be very
efficient in its use of system resources. Within a single program of Java we can perform
multiple tasks at a single point of time.
Multithreading is:
Secure:
Closely related to Java's robustness is its focus on security. As Java, does not use pointers
to directly reference memory locations, as seen in C and C++, Java has a great deal of
control over the code that exists within the Java environment.
It was anticipated that Java applications would run on the Internet and that they could
dynamically incorporate or execute code found at remote locations on the Internet.
Because of this, the developers of Java hypothesized the existence of a hostile Java
compiler that would generate Java byte code with the intent of bypassing Java's runtime
security. This led to the concept of a byte-code verifier. The byte-code verifier examines
all incoming code to ensure that the code plays by the rules and is safe to execute. In
addition to other properties, the byte code verifier ensures the following:
Distributed:
Java Programming Language supports Distributed Computing or Distributed Network
Technologies using Remote Method Invocation (RMI), Common Object Request Broker
Architecture (CORBA), and Universal Resource Locator (URL). The application designed
and developed through the said technologies can be distributed among multiple Remote
High Performance:
For all but the simplest or most infrequently used applications, performance is always a
consideration. It is no surprise, then, to discover that achieving high performance was one
of the initial design goals of the Java developers. A Java application will not achieve the
performance of a fully compiled language such as C or C++. However, for most
applications, including graphics-intensive ones commonly found on the World Wide Web,
the performance of Java is more than adequate. For some applications, there may be no
visible difference in performance between C++ and Java.
Many Java Developers have discovered that, although a C program will outperform a Java
program in many cases, the additional development time and effort do not justify the
minimal performance gains. Of course, because we are not all programming in assembly
language, there must be some amount of performance we are willing to trade for faster
development.
Dynamic:
Because it is interpreted, Java is an extremely dynamic language. At runtime, the Java
environment can extend itself by linking classes that may be located on remote servers on
a network (for example, the Internet). This is tremendous advantage over a language like
C++ that links classes prior to runtime.
In C++, every time member variables or functions are added to a class, it is necessary to
recompile that class and then all additional code that references that class. Of course, the
problem is intensified by the fact that you need to remember to recompile the files that
reference the changed class.
Java addresses this problem by deferring it to runtime. At runtime, the Java interpreter
performs name resolution while linking in the necessary classes. The Java interpreter is
also responsible for determining the placement of objects in memory. These are the two
features of definition of a class used by other classes. Because name lookup and resolution
are performed only the first time a name is encountered, only minimal performance
overhead is added.
At runtime, the Java environment can extend itself by linking classes that may be located
on remote servers on a network.
Try it out
2. What is portability?
use the J2ME SDK to create a game that runs on a cellular phone.
The following figure Fig 11 identifies the Java Technology Product groups:
http://java.sun.com/javase/
6/docs/api/ to access the documentation online.
Note that while accessing the documentation, you will be provided access to many
different Java documentation pages. Find the link under "API & Language Documentation"
called Java 2 Platform API Specification. Once you click on it you will be landed on the first
page, which will look like:
Setting up Java
How to set up Java? You will find a host of instructions along with the download installer.
Follow these to install Java (SDK). In windows, the default installation directory of Java
Software is located at "C:\Program Files\Java\jdk1.6.0\” which is often referred as Java
Home(i.e the environment variable JAVA_HOME).
Now, by running the already installed Java executable, you will be able to run the Java
program. It is convenient to add the location of this file to the path variable of the
operating system. If you do not do this, you will need to refer to the absolute location of
Java explicitly.
Setting up JAVA_HOME
• If you are using the Windows 2000/XP, you can set JAVA_HOME easily, as
follows: Right-click ‘My Computer’ icon on your desktop, select
‘Properties’, Click the ‘Advanced’ tab, Click the button ‘Environment
variables'. Refer to ‘System Variables’ area. Click on ‘New’ button. Specify ‘Variable
Name’ as ‘JAVA_HOME’ and its value as path to the folder where you have installed
JDK.
Try it out
Write a simple Java program to display a message “ Good Morning”. Take the help of
the statements shown in the above program.
Program analysis:
Let us analyze this sample program line by line.
Studying this sample program line-by-line will get you started you on the path to learn
Java. Sections that follow after this, will help you analyze the sample program. For now, it
is not important that you understand everything completely. Through constant usage, you
will eventually know what it all means.
Comments in Java
• Comments in Java are used only for the purpose of documentation and are ignored
by the compiler at the time of bytecode generation.
• The following three comments techniques are supported:
• Note that public and class have special meaning and they are Java
keywords. The programmer can decide the class name while staying within
the restrictions of rules defined for Java identifiers.
• The name of the class has to be the same as the name of the source file.
The class, if named App, must reside within a file named App.java
Statement blocks
• Statement blocks begin and end with opening and closing braces - "{" and
"}"
• One statement block can be nested entirely within another statement block.
In the sample program the block for the main method is nested within the
block for the App class.
The main method
• When the Java Virtual Machine starts processing the class, it searches for
this method and executes it.
• This method should have a method header coded like the following:
public static void main(String[] args)
Try it out
Compiler requirements:
• A semicolon ";" suggests end of every Java statement.
• The "white space" characters –i.e. spaces, tabs, and the use of the return key etc
are ignored by the compiler. The "white space" is, however, used liberally
sometimes so that it becomes easier to write, read and maintain the code.
You can use the appletviewer to run and debug applets without a web
appletviewer
browser.
jar jar lets you manage the Java Archive (JAR) files.
javah is the C header and stub generator and is used to write native
javah
methods.
Summary
Exercise
1. ___ is the process of investigating a problem that you want to solve with your
product.
2. Design specifications cover ___ and ____ aspects of the system operation.
3. Layout designs like reports for system output data is called ___ design.
4. The phase that targets a functional system, which meets the system design
specifications with program coding is called ____ .
5. Testing of individual components working and integrated working of the whole
system is called ____ testing.
6. The Java Programming Language originated in the year ___ as part of a research
project to develop a programming language, that would bridge the gap between
many consumer devices, like Video cassette recorders (VCRs) and televisions.
7. Java is portable because the ____ itself is written in Java.
8. ____ group of Java supports development of applets and applications that run
within Web browsers and on desktop computers, respectively.
True/False
1. In Java, all primitive types (integer, long, float, double, and so on) are of
undefined sizes, regardless of the machine or operating system on which the
program is run.
2. Implementing software so that two or more activities can be performed in
parallel within the same application is called Distributing.