Anda di halaman 1dari 52

COMPANY PROFILE

India's Leading IT & Technology Company


Founded in 1976 as one of India's original IT garage start-ups, today the HCL Group has
expanded to four companies in India - HCL Infosystems, HCL Technologies, HCL Healthcare
and HCL TalentCare. The group generates annual revenues of over US$ 6.5 billion with more
than 110,000 employees from 100 nationalities operating across 31 countries, including over 500
points of presence in India. A pioneer of modern computing, HCL has many firsts to its credit
including the introduction of the 8-bit microprocessor-based computer in 1978 well before its
global peers.
HCL's technology solutions cover the entire gamut of services that include infrastructure
management, application development, BPO and technology distribution. A new entrant in
healthcare, HCL aims to provide innovative medical services, products and training to meet the
growing demand for quality healthcare in India. HCL Avitas, in affiliation with Johns Hopkins
Medicine International, is the healthcare delivery arm of HCL Healthcare. HCL TalentCare is
envisioned as an integrated talent solutions company addressing the entire spectrum of
employability needs in India.

HCL Learning Ltd


HCL Learning Ltd. is a 100% owned subsidiary of HCL Infosystems Ltd. HCL Learning covers
the entire spectrum of education and training requirements across schools, colleges, individuals
and enterprises. HCL Learning addresses the education and training needs through 2 business
verticals:
• K-12
• Higher Education & Enterprise Learning

Figure 1. HCL Learning Ltd.


Introduction to Java

With the invention of microprocessors, the world is scientifically developed with sophisticated
equipments, systems, and devices. Microprocessors are used in computers, televisions, and fax
machines. Even the hand-held devices such as pagers, PDAs (Personal Digital Assistant), and
cell phones make use of microprocessors. All these electronic devices are helpful because of
their communication capabilities. With the increasing capabilities and decreasing cost of
information processing and networking technologies, the network is growing rapidly for
transmitting information through electronic systems.

Internet is the network of networks between different types of computers located at


different places to transmit information. Information can reach to any place in the world quickly
at a cheaper rate through the Internet. Thus, the Internet has made the world a global village for
information exchange. The emerging infrastructure of electronic devices and interconnected
computer networks create an environment that presents new challenges to software industries.
for this emerging computing environment, Java process to be a well – suited programming
language. it is found suitable for networked environments involving a great variety of computer
and devices.

Java has many characteristics that have contributed to its popularity:

 Platform independence - Many languages are compatible with only one platform. Java
was specifically designed so that it would run on any computer, regardless if it was
running Windows, Linux, Mac, Unix or any of the other operating systems.
 Simple and easy to use - Java's creators tried to design it so code could be written
efficiently and easily.
 Multi-functional - Java can produce many applications from command-line programs to
applets to Swing windows (basically, sophisticated graphical user interfaces).

Java does have some drawbacks. Since it has automated garbage collection, it can tend to use
more memory than other similar languages. There are often implementation differences on
different platforms, which have led to Java being described as a "write once, test everywhere"
system. Lastly, since it uses an abstract "virtual machine", a generic Java program doesn't have
access to the Native API's on a system directly. None of these issues are fatal, but it can mean
that Java isn't an appropriate choice for a particular piece of software.

-2-|Page
The Java Platform
JAVA PROGRAMMING LANGUAGE

The Java programming language is a high-level language that can be characterized by all of the
following buzzwords:

 Simple Architecture
 Neutral
 Object oriented
 Portable
 Distributed
 High performance
 Interpreted
 Multithreaded
 Robust
 DynamicSecure

With most programming languages, you either compile or interpret a program so that you
can run it on your computer. The Java programming language is unusual in that a program is
both compiled and interpreted. With the compiler, first you translate a program into an
intermediate language called Java byte codes —the platform-independent codes interpreted by
the interpreter on the Java platform. The interpreter parses and runs each Java byte code
instruction on the computer. Compilation happens just once; interpretation occurs each time the
program is executed. The following figure illustrates how this works.

Figure 2. Java is Platform Independent

-3-|Page
JAVA INTERRETER & COMPLILER

You can think of Java byte codes as the machine code instructions for the Java Virtual Machine
(Java VM). Every Java interpreter, whether it’s a development tool or a Web browser that can
run applets, is an implementation of the Java VM. Java byte codes help make “write once, run
anywhere” possible. You can compile your program into byte codes on any platform that has a
Java compiler. The byte codes can then be run on any implementation of the Java VM. That
means that as long as a computer has a Java VM, the same program written in the Java
programming language can run on Windows 2000, a Solaris workstation, or on an iMac.

Figure 3. Java is Compiled as well as Interperated

JAVA BYTECODE

 The Java Platform


A platform is the hardware or software environment in which a program runs.
We’ve already mentioned some of the most popular platforms like Windows 2000,
Linux, Solaris, and MacOS.
The Java platform has two components:
 The Java Virtual Machine (Java VM)
 The Java Application Programming Interface (Java API)

The Java API is a large collection of ready-made software components that provide
many useful capabilities, such as graphical user interface (GUI) widgets. The Java API is

-4-|Page
grouped into libraries of related classes and interfaces; these libraries are known as
packages.

The following figure depicts a program that’s running on the Java platform. As the
figure shows, the Java API and the virtual machine insulate the program from the
hardware.

Figure 4 : Java program that’s running on the Java platform


Native code is code that after you compile it, the compiled code runs on a specific
hardware platform. As a platform-independent environment, the Java platform can be a
bit slower than native code. However, smart compilers, well-tuned interpreters, and just-
in-time byte code compilers can bring performance close to that of native code without
threatening portability.

 What Can Java Technology Do?


The most common types of programs written in the Java programming language are
applets and applications. If you’ve surfed the Web, you’re probably already familiar with
applets. An applet is a program that adheres to certain conventions that allow it to run
within a Java-enabled browser.
However, the Java programming language is not just for writing cute, entertaining applets
for the Web. The general-purpose, high-level Java programming language is also a
powerful software platform. Using the generous API, you can write many types of
programs.

An application is a standalone program that runs directly on the Java platform. A special
kind of application known as a server serves and supports clients on a network. Examples
of servers are Web servers, proxy servers, mail servers, and print servers. Another
specialized program is a servlet. A servlet can almost be thought of as an applet that runs
on the server side. Java Servlets are a popular choice for building interactive web

-5-|Page
applications, replacing the use of CGI scripts. Servlets are similar to applets in that they
are runtime extensions of applications. Instead of working in browsers, though, servlets
run within Java Web servers, configuring or tailoring the server.

Java platform gives you the following features:

 The essentials: Objects, strings, threads, numbers, input and output, data
structures, system properties, date and time, and so on.
 Applets: The set of conventions used by applets.
 Networking: URLs, TCP (Transmission Control Protocol), UDP (User Data gram
Protocol) sockets, and IP (Internet Protocol) addresses.
 Internationalization: Help for writing programs that can be localized for users
worldwide. Programs can automatically adapt to specific locales and be displayed
in the appropriate language.
 Security: Both low level and high level, including electronic signatures, public
and private key management, access control, and certificates.
 Software components: Known as JavaBeansTM, can plug into existing
component architectures.
 Object serialization: Allows lightweight persistence and communication via
Remote Method Invocation (RMI).
 Java Database Connectivity (JDBCTM): Provides uniform access to a wide
range of relational databases.
The Java platform also has APIs for 2D and 3D graphics, accessibility, servers,
collaboration, telephony, speech, animation, and more.

-6-|Page
Figure 5: Java SDK

 Benefits of Java:

 Get started quickly: Although the Java programming language is a powerful


object-oriented language, it’s easy to learn, especially for programmers already
familiar with C or C++.

 Write less code: Comparisons of program metrics (class counts, method counts,
and so on) suggest that a program written in the Java programming language can
be four times smaller than the same program in C++.

 Write better code: The Java programming language encourages good coding
practices, and its garbage collection helps you avoid memory leaks. Its object
orientation, its JavaBeans component architecture, and its wide-ranging, easily
extendible API let you reuse other people’s tested code and introduce fewer bugs.

 Develop programs more quickly: Your development time may be as much as


twice as fast versus writing the same program in C++. Why? You write fewer
lines of code and it is a simpler programming language than C++.

-7-|Page
 Avoid platform dependencies with 100% Pure Java: You can keep your
program portable by avoiding the use of libraries written in other languages. The
100% Pure JavaTM Product Certification Program has a repository of historical
process manuals, white papers, brochures, and similar materials online.

 Write once, run anywhere: Because 100% Pure Java programs are compiled into
machine-independent byte codes, they run consistently on any Java platform.

 Distribute software more easily: You can upgrade applets easily from a central
server. Applets take advantage of the feature of allowing new classes to be loaded
“on the fly,” without recompiling the entire program.

INHERITANCE

■ Contrary to the conventional interpretation, a subclass is not a subset of its superclass. In fact,
a subclass usually contains more information and methods than its superclass.

■ Private data fields in a superclass are not accessible outside the class. Therefore, they
cannot be used directly in a subclass. They can, however, be accessed/mutated through public
accessors/mutators if defined in the superclass.

■ Not all is-a relationships should be modeled using inheritance. For example, a square is a
rectangle, but you should not extend a Square class from a Rectangle class, because the width
and height properties are not appropriate for a square. Instead, you should define a Square class
to extend the GeometricObject class and define the side property for the side of a square.

■ Inheritance is used to model the is-a relationship. Do not blindly extend a class just for the
sake of reusing methods. For example, it makes no sense for a Tree class to extend a Person
class, even though they share common properties such as height and weight. A subclass and its
superclass must have the is-a relationship.

-8-|Page
■ Some programming languages allow you to derive a subclass from several classes. This
capability is known as multiple inheritance. Java, however, does not allow multiple inheritance.
A Java class may inherit directly from only one superclass. This restriction is known as single
inheritance. If you use the extends keyword to define a subclass, it allows only one parent class

Figure 5: ILLUSTRATION OF INHERITANCE IN JAVA

-9-|Page
1.3.1.2 POLYMORPHISM

Polymorphism means that a variable of a supertype can refer to a subtype object.

For example:
public class PolymorphismDemo {

public static void main(String[] args) {


// Display circle and rectangle properties
/** Display geometric object properties */
public static void {
System.out.println("Created on " + object.getDateCreated() + ". Color is " +
object.getColor());
}
}

Output:
Created on Mon Mar 09 19:25:20 EDT 2011. Color is white
Created on Mon Mar 09 19:25:20 EDT 2011. Color is black

The method displayObject takes a parameter of the GeometricObject type. You can invoke
displayObject by passing any instance of GeometricObject (e.g., new
CircleFromSimpleGeometricObject(1, "red", false) and new Rectangle-
FromSimpleGeometricObject(1, 1, "black", false) in lines 5–8). An object of a subclass can
be used wherever its superclass object is used. This is commonly known as polymorphism (from
a Greek word meaning “many forms”). In simple terms, polymorphism means that a variable of a
supertype can refer to a subtype object.

- 10 - | P a g e
1.3.1.3 EVENT HANDLING
To respond to a button click, you need to write the code to process the button-clicking action.
The button is an event source object—where the action originates. You need to create an object
capable of handling the action event on a button. This object is called an event listener.

Figure 6: FIRING OF AN EVENT

Not all objects can be listeners for an action event. To be a listener of an action event, two
requirements must be met:

1. The object must be an instance of the ActionListener interface. This interface defines the
common behavior for all action listeners.

2. The ActionListener object listener must be registered with the event source
object using the method source.addActionListener(listener).

- 11 - | P a g e
1.3.1.3.1 EVENTS & EVENT SOURCES

When you run a Java GUI program, the program interacts with the user, and the events drive its
execution. This is called event-driven programming. An event can be defined as a signal to the
program that something has happened. Events are triggered either by external user actions, such
as mouse movements, button clicks, and keystrokes, or by internal program activities, such as a
timer. The program can choose to respond to or ignore an event.

The component that creates an event and fires it is called the event source object, or simply
source object or source component. For example, a button is the source object for a
buttonclicking action event. An event is an instance of an event class. The root class of the event
classes is java.util.EventObject.

Figure 7: EVENT HIERARCHY

- 12 - | P a g e
LISTENERS, REGISTRATIONS & HANDLING EVENTS

Figure 8: REGISTERING & HANDLING EVENT

- 13 - | P a g e
Figure 9: addActionListener ILLUSTRATION

- 14 - | P a g e
1.3.1.4 INNER CLASSES

Figure 10: INNER CLASS ILLUSTRATION

The class InnerClass defined inside OuterClass is another example of an inner class. An inner
class may be used just like a regular class. Normally, you define a class as an inner class if it is
used only by its outer class. An inner class has the following features:

■ An inner class is compiled into a class named OuterClassName$InnerClassName.class. For


example, the inner class A in Test is compiled into Test$A.class .

■ An inner class can reference the data and methods defined in the outer class in which it nests,
so you need not pass the reference of an object of the outer class to the constructor of the inner
class. For this reason, inner classes can make programs simple and concise.

- 15 - | P a g e
An inner class can be defined with a visibility modifier subject to the same visibility rules
applied to a member of the class.

■ An inner class can be defined as static. A static inner class can be accessed using the outer
class name. A static inner class cannot access nonstatic members of the outer class.

■ Objects of an inner class are often created in the outer class. But you can also create an object
of an inner class from another class. If the inner class is nonstatic, you must first create an
instance of the outer class, then use the following syntax to create an object for the inner class:
OuterClass.InnerClass innerObject = outerObject.new InnerClass();

■ If the inner class is static, use the following syntax to create an object for it:
OuterClass.InnerClass innerObject = new OuterClass.InnerClass();

A simple use of inner classes is to combine dependent classes into a primary class. This reduces
the number of source files. It also makes class files easy to organize, since they are all named wit
the primary class as the prefix. For example, rather than creating the two source files Test.java
and A.java, you can merge class A into class Test and create just one source file, Test.java. The
resulting class files are Test.class and Test$A.class.

- 16 - | P a g e
1.3.1.5 ANONYMOUS CLASSES

An anonymous inner class is an inner class without a name. It combines defining an


inner class and creating an instance of the class into one step.

Figure 11. ANONYMOUS CLASSES ILLUSTRATION

- 17 - | P a g e
JAVA EXCEPTION HANDLING
Exception is an error event that can happen during the execution of a program and disrupts its
normal flow. Java provides a robust and object oriented way to handle exception scenarios,
known as Java Exception Handling. We will look into following topics in this tutorial.

Java being an object oriented programming language, whenever an error occurs while
executing a statement, creates an exception object and then the normal flow of the program halts
and JRE tries to find someone that can handle the raised exception. The exception object
contains a lot of debugging information such as method hierarchy, line number where the
exception occurred, type of exception etc. When the exception occurs in a method, the process of
creating the exception object and handing it over to runtime environment is called “throwing the
exception”.

Once runtime receives the exception object, it tries to find the handler for the exception.
Exception Handler is the block of code that can process the exception object. The logic to find
the exception handler is simple – starting the search in the method where error occurred, if no
appropriate handler found, then move to the caller method and so on. So if methods call stack is
A->B->C and exception is raised in method C, then the search for appropriate handler will move
from C->B->A. If appropriate exception handler is found, exception object is passed to the
handler to process it. The handler is said to be “catching the exception”. If there are no
appropriate exception handler found then program terminates printing information about the
exception.

- 18 - | P a g e
Exception Handling Keywords

Java provides specific keywords for exception handling purposes, we will look after them
first and then we will write a simple program showing how to use them for exception
handling.

 throw – We know that if any exception occurs, an exception object is getting created and
then Java runtime starts processing to handle them. Sometime we might want to generate
exception explicitly in our code, for example in a user authentication program we should
throw exception to client if the password is null. throw keyword is used to throw
exception to the runtime to handle it.

 throws – When we are throwing any exception in a method and not handling it, then we
need to use throws keyword in method signature to let caller program know the
exceptions that might be thrown by the method. The caller method might handle these
exceptions or propagate it to it’s caller method using throws keyword. We can provide
multiple exceptions in the throws clause and it can be used with main() method also.

 try-catch – We use try-catch block for exception handling in our code. try is the start of
the block and catch is at the end of try block to handle the exceptions. We can have
multiple catch blocks with a try and try-catch block can be nested also. catch block
requires a parameter that should be of type Exception.

 finally – finally block is optional and can be used only with try-catch block. Since
exception halts the process of execution, we might have some resources open that will

- 19 - | P a g e
not get closed, so we can use finally block. finally block gets executed always, whether
exception occurred or not.

For instance:

class Exceptions {
public static void main(String[] args) {

String languages[] = { "C", "C++", "Java", "Perl", "Python" };

try {
for (int c = 1; c <= 5; c++) {
System.out.println(languages[c]);
}
}
catch (Exception e) {
System.out.println(e);
}
}
}

Output of program:

C++
Java
Perl
Python
java.lang.ArrayIndexOutOfBoundsException: 5

- 20 - | P a g e
Checked vs. Unchecked Exception in Java

 What is Checked Exception in Java?

Checked Exception in Java is all those Exception which requires being cought and
handled during compile time. If Compiler doesn’t see try or catch block handling a Checked
Exception, it throws Compilation error. Now Which Exception is checked Exception and Why
Checked Exception are introduced in first place? All the Exception which are direct sub Class of
Exception but not inherit Run-time Exception are Checked Exception.

While doing File Programming in C++ I found that most of the time programmer
forgets to close file descriptors , which often result in locking of file on OS level. Since Java is
introduced after C++, designers of Java thought to ensure such mistakes are not allowed and
resources opened are closed properly. To ensure this they introduced Checked Exception. If you
see most of File IO related operation comes under IO Exception which is checked one. Though is
a special scenario related to Checked Exception but you can generalize this as, where Java sees
an opportunity of failure more, they ensure that programmer provide recovery strategy or at least
handle those scenario gracefully.

Figure 12: CHECKED vs. UNCHECKED EXCEPTION

- 21 - | P a g e
 When to use Checked Exception in Java

Knowing Checked Exception is not that useful until you know how to use
Checked Exception in Java. Java has often been criticized for its Checked Exception strategy,
arguments given are that checked Exception adds lot of boiler plate code and makes whole class
or function unreadable.

Following are some scenarios where it is preferred to use Checked Exception to ensure that
Code is Robust and stable.

1) All Operation where chances of failure is more e.g. IO Operation, Database Access or
Networking operation can be handled with Checked Exception.
2) When you know what to do (i.e. you have alternative) when an Exception occurs, may be as
part of Business Process.
3) Checked Exception is a reminder by compiler to programmer to handle failure scenario.

Following are some Examples of Checked Exception in Java library:

IOException
SQLException
DataAccessException
ClassNotFoundException
InvocationTargetException

 What is Unchecked Exception in Java?

Unchecked Exception in Java is those Exceptions whose handling is not verified


during Compile time. Unchecked Exceptions mostly arise due to programming errors like
accessing method of a null object, accessing element outside an array bonding or invoking

- 22 - | P a g e
method with illegal arguments. In Java, Unchecked Exception is direct sub Class of Runtime
Exception. The major benefit of Unchecked Exception is that it doesn't reduce code readability
and keeps the client code clean.

 When to use UnChecked Exception in Java ?

A good strategy of Exception handling in Java is wrapping a checked Exception into


UnChecked Exception. Since most of Database operation throws SQL Exception but it’s not
good to let SQL Exception propagate from your DAO layer to up higher on business layer and
client code provide exception handling you can handle SQL Exception in DAO layer and you
can wrap the cause in a Runtime Exception to propagate through client code. Also as I said
earlier unchecked exceptions are mostly programming errors and to catch them is real hard until
you do a load test with all possible input and scenario.

 Difference between Checked and Unchecked Exception in Java

1) Checked Exception is required to be handled by compile time while Unchecked Exception


doesn't.
2) Checked Exception is direct sub-Class of Exception while Unchecked Exception are of
Runtime Exception.
3) Checked Exception represent scenario with higher failure rate while UnCheckedException are
mostly programming mistakes.

- 23 - | P a g e
Figure 13: TYPES OF EXCEPTIONS

Here are few examples of Unchecked Exception in Java library:


NullPointerException
ArrayIndexOutOfBound
IllegalArgumentException
IllegalStateException

Summary:
1. Both Checked and Unchecked Exception are handled using keyword try, catch and finally.
2. In terms of Functionality Checked and Unchecked Exception are same.
3. Checked Exception handling verified during compile time.
4. Unchecked Exception are mostly programming errors.
5. JDK7 provides improved Exception handling code with catching multiple Exception in one
catch block and reduce amount of boiler plate code required for exception handling in Java.

- 24 - | P a g e
Figure 14: ERRORS vs. EXCEPTIONS

ODBC

Microsoft Open Database Connectivity (ODBC) is a standard programming interface for


application developers and database systems providers. Before ODBC became a de facto
standard for Windows programs to interface with database systems, programmers had to use
proprietary languages for each database they wanted to connect to. Now, ODBC has made the
choice of the database system almost irrelevant from a coding perspective, which is as it should
be. Application developers have much more important things to worry about than the syntax that
is needed to port their program from one database to another when business needs suddenly
change.

- 25 - | P a g e
Through the ODBC Administrator in Control Panel, you can specify the particular
database that is associated with a data source that an ODBC application program is written to
use. Think of an ODBC data source as a door with a name on it. Each door will lead you to a
particular database. For example, the data source named Sales Figures might be a SQL Server
database, whereas the Accounts Payable data source could refer to an Access database. The
physical database referred to by a data source can reside anywhere on the LAN.
From a programming perspective, the beauty of ODBC is that the application can be
written to use the same set of function calls to interface with any data source, regardless of the
database vendor. The source code of the application doesn’t change whether it talks to Oracle or
SQL Server. We only mention these two as an example. There are ODBC drivers available for
several dozen popular database systems. Even Excel spreadsheets and plain text files can be
turned into data sources. The operating system uses the Registry information written by ODBC
Administrator to determine which low-level ODBC drivers are needed to talk to the data source
(such as the interface to Oracle or SQL Server). The loading of the ODBC drivers is transparent
to the ODBC application program. In a client/server environment, the ODBC API even handles
many of the network issues for the application programmer.
The advantages of this scheme are so numerous that you are probably thinking there must
be some catch. The only disadvantage of ODBC is that it isn’t as efficient as talking directly to
the native database interface. The availability of good ODBC drivers has improved a great deal
recently. And anyway, the criticism about performance is somewhat analogous to those who said
that compilers would never match the speed of pure assembly language. Maybe not, but the
compiler (or ODBC) gives you the opportunity to write cleaner programs, which means you
finish sooner. Meanwhile, computers get faster every year.
JDBC

In an effort to set an independent database standard API for Java; Sun Microsystems
developed Java Database Connectivity, or JDBC. JDBC offers a generic SQL database access
mechanism that provides a consistent interface to a variety of RDBMSs. This consistent interface
is achieved through the use of “plug-in” database connectivity modules, or drivers. If a database
vendor wishes to have JDBC support, he or she must provide the driver for each platform that the
database and Java run on.

- 26 - | P a g e
To gain a wider acceptance of JDBC, Sun based JDBC’s framework on ODBC. As you
discovered earlier in this chapter, ODBC has widespread support on a variety of platforms.
Basing JDBC on ODBC will allow vendors to bring JDBC drivers to market much faster than
developing a completely new connectivity solution.
JDBC was announced in March of 1996. It was released for a 90 day public review that
ended June 8, 1996. Because of user input, the final JDBC v1.0 specification was released soon
after.
 JDBC Goals
Few software packages are designed without goals in mind. JDBC is one that, because of
its many goals, drove the development of the API. These goals, in conjunction with early
reviewer feedback, have finalized the JDBC class library into a solid framework for building
database applications in Java.
The goals that were set for JDBC are important. They will give you some insight as to why
certain classes and functionalities behave the way they do. The eight design goals for JDBC are
as follows:

1. SQL Level API


The designers felt that their main goal was to define a SQL interface for Java. Although
not the lowest database interface level possible, it is at a low enough level for higher-level
tools and APIs to be created. Conversely, it is at a high enough level for application
programmers to use it confidently. Attaining this goal allows for future tool vendors to
“generate” JDBC code and to hide many of JDBC’s complexities from the end user.

2. SQL Conformance
SQL syntax varies as you move from database vendor to database vendor. In an effort to
support a wide variety of vendors, JDBC will allow any query statement to be passed through
it to the underlying database driver. This allows the connectivity module to handle non-
standard functionality in a manner that is suitable for its users.
3. JDBC must be implemental on top of common database interfaces
The JDBC SQL API must “sit” on top of other common SQL level APIs. This goal

- 27 - | P a g e
allows JDBC to use existing ODBC level drivers by the use of a software interface. This
interface would translate JDBC calls to ODBC and vice versa.

4. Provide a Java interface that is consistent with the rest of the Java system
Because of Java’s acceptance in the user community thus far, the designers feel that they
should not stray from the current design of the core Java system.
5. Keep it simple
This goal probably appears in all software design goal listings. JDBC is no exception.
Sun felt that the design of JDBC should be very simple, allowing for only one method of
completing a task per mechanism. Allowing duplicate functionality only serves to confuse
the users of the API.
6. Use strong, static typing wherever possible
Strong typing allows for more error checking to be done at compile time; also, less error
appear at runtime.
7. Keep the common cases simple
Because more often than not, the usual SQL calls used by the programmer are simple
SELECT’s, INSERT’s, DELETE’s and UPDATE’s, these queries should be simple to perform with
JDBC. However, more complex SQL statements should also be possible.

NetBeans IDE (WorkBench)


NetBeans IDE is a free, open source, popular (with approximately 1 million
downloads), integrated development environment used by many developers. Out of the
box, it provides built-in support for developing in Java, C, C++, XML, and HTML. And
this author especially likes the support for editing JSPs, including syntax highlighting,
HTML tag completion, JSP tag completion, and Java code completion.
Following are step-by-step instructions to help NetBeans IDE greenhorns to get started
developing Java applications with NetBeans IDE. The basic steps described are as
follows.

1. Create a new project


2. Add a new class to the project
3. Compile and execute the code.

- 28 - | P a g e
Table 1.1 Component-to-model mapping for Swing.

Component Model Interface Model Type

JButton ButtonModel GUI

JToggleButton ButtonModel GUI/data

JCheckBox ButtonModel GUI/data

JRadioButton ButtonModel GUI/data

JMenu ButtonModel GUI

JMenuItem ButtonModel GUI

JCheckBoxMenuItem ButtonModel GUI/data

JRadioButtonMenuItem ButtonModel GUI/data

JComboBox ComboBoxModel data

JProgressBar BoundedRangeModel GUI/data

JScrollBar BoundedRangeModel GUI/data

JSlider BoundedRangeModel GUI/data

SingleSelectionMod
JTabbedPane GUI
el

JList ListModel data

- 29 - | P a g e
JList ListSelectionModel GUI

JTable TableModel data

JTable TableColumnModel GUI

JTree TreeModel data

JTree TreeSelectionModel GUI

JEditorPane Document data

JTextPane Document data

JTextArea Document data

JTextField Document data

JPasswordField Document data

Table 1: GUI Components

Working with Swing Application in Net Beans


The NetBeans IDE is a free, open-source Integrated Development Environment for software
developers. We will get all the tools we need to create professional desktop, enterprise, web
and mobile applications, in Java, C/C++ and even Ruby. The IDE runs on many platforms
including Windows, Linux, Mac OS X and Solaris; it is easy to install and use straight out of
the box. The 6.0 release includes significant enhancements and new features, including a
completely rewritten editor infrastructure, support for additional languages, new productivity
features, and a simplified installation process that allows you to easily install and configure the
IDE to meet our exact needs.
The IDE's GUI Builder makes it possible to build professional-looking GUIs without an
intimate understanding of layout Accelerators. You can lay out your forms by simply placing
components where you want them.

- 30 - | P a g e
Steps to create a GUI application

1. Use the GUI Builder Interface


2. Create a GUI Container
3. Add Components
4. Resize Components
5. Align Components
6. Adjust Component Anchoring
7. Set Component Auto-Resizing Behavior
8. Edit Component Properties

Figure 13: The above screen shot shows NetBeans IDE view.

- 31 - | P a g e
Figure 14: The above Screen shot shows the properties dialog for JFrame window.

- 32 - | P a g e
Creating a GUI container

After creating the new application, you may have noticed that the Source Packages folder in the
Projects window contains an empty <default package> node. To proceed with building our
interface, we need to create a Java container within which we will place the other required GUI
components. In this step we'll create a container using the JFrame component and place the
container in a new package.

We can use the GUI builder to prototype GUIs applications. Designing of Swing GUIs by
dragging and positioning GUI components from a palette onto a canvas. The GUI builder
automatically takes care of the correct spacing and alignment. Click into JLabels, JButtons,
JTextFields and edit their properties directly in place.

The new help bar displays context-sensitive hints about what can be done with the selected
component and which shortcuts can speed up the work . The NetBeans IDE comes with built-in
support for GUI localization and accessibility.

 Standard and Custom GUI Components

The extensible Component Palette comes with pre-installed Swing and AWT
components and includes a visual menu designer. Use the Component Inspector to view a
component's tree and properties

 Swing Application FrameWork

The Swing Application Framework simplifies the handling of the application life cycle,
actions and resources. Take advantage of the provided code-generation tools and building
blocks, and develop small to medium-sized desktop applications faster than ever. Create menus
fast and intuitively by dragging and dropping menu items onto the canvas; you can add
mnemonics and rename menu items inline by clicking and typing in the Design view.

- 33 - | P a g e
 Introduction to Applets:

In this Section you will learn about the lifecycle of an applet and different methods of an
applet. Applet runs in the browser and its lifecycle method are called by JVM when it is loaded
and destroyed.

Here are the lifecycle methods of an Applet:

init(): This method is called to initialized an applet

start(): This method is called after the initialization of the applet.

stop(): This method can be called multiple times in the life cycle of an Applet.

destroy(): This method is called only once in the life cycle of the applet when applet is
destroyed.

 init () method: The life cycle of an applet is begin on that time when the applet is first
loaded into the browser and called the init() method. The init() method is called only
one time in the life cycle on an applet. The init() method is basically called to read the
PARAM tag in the html file. The init () method retrieve the passed parameter through
the PARAM tag of html file using get Parameter() method All the initialization such as
initialization of variables and the objects like image, sound file are loaded in the init ()
method .After the initialization of the init() method user can interact with the Applet
and mostly applet contains the init() method.

 start () method: The start method of an applet is called after the initialization method
init(). This method may be called multiples time when the Applet needs to be started or
restarted. For Example if the user wants to return to the Applet, in this situation the start
Method() of an Applet will be called by the web browser and the user will be back on
the applet. In the start method user can interact within the applet.

- 34 - | P a g e
 stop () method: The stop() method can be called multiple times in the life cycle of
applet like the start () method. Or should be called at least one time. There is only miner
difference between the start() method and stop () method. For example the stop()
method is called by the web browser on that time When the user leaves one applet to go
another applet and the start() method is called on that time when the user wants to go
back into the first program or Applet.

 destroy() method: The destroy() method is called only one time in the life cycle of
Applet like init() method. This method is called only on that time when the browser
needs to Shut down.

IDE USED IN JAVA TRAINING

NetBeans IDE Features:-

 Best Support for Latest Java Technologies


 Easy & Efficient Project Management
 Rapid User Interface Development
 Write Bug Free Code

NetBeans IDE Java Quick Start Tutorial


Welcome to NetBeans IDE!
This tutorial provides a very simple and quick introduction to the NetBeans IDE workflow by walking you through the
creation of a simple "Hello World" Java console application. Once you are done with this tutorial, you will have a
general knowledge of how to create and run applications in the IDE.
This tutorial takes less than 10 minutes to complete.
After you finish this tutorial, you can move on to the learning trails, which are linked from the Documentation, Training
& Support page. The learning trails provide comprehensive tutorials that highlight a wider range of IDE features and
programming techniques for a variety of application types. If you do not want to do a "Hello World" application, you
can skip this tutorial and jump straight to the learning trails.
Contents

- 35 - | P a g e
 Setting Up the Project
 Adding Code to the Generated Source File
 Compiling and Running the Application
 Building and Deploying the Application
 Next Steps
To complete this tutorial, you need the following software and resources.

Software or Resource Version Required

NetBeans IDE version 7.2, 7.3, 7.4, or 8.0

Java Development Kit (JDK) version 6, 7, or 8

Setting Up the Project


To create an IDE project:
1. Start NetBeans IDE.

2. In the IDE, choose File > New Project, as shown in the figure below.

Figure 15:- New Project NetBeans

- 36 - | P a g e
3. In the New Project wizard, expand the Java category and select Java Application as shown in the figure
below. Then click Next.

Figure 16: New Project Wizard


4. In the Name and Location page of the wizard, do the following (as shown in the figure below):

 In the Project Name field, type HelloWorldApp.

 Leave the Use Dedicated Folder for Storing Libraries checkbox unselected.

 In the Create Main Class field, type helloworldapp.HelloWorldApp.

Figure 17: New Java Application Name & Location


5. Click Finish.

The project is created and opened in the IDE. You should see the following components:

- 37 - | P a g e
 The Projects window, which contains a tree view of the components of the project, including source files, libraries that
your code depends on, and so on.

 The Source Editor window with a file called HelloWorldApp open.

 The Navigator window, which you can use to quickly navigate between elements within the selected class.

Figure 18: Navigator Window (NetBeans)

Adding Code to the Generated Source File


Because you have left the Create Main Class checkbox selected in the New Project wizard, the IDE has created a
skeleton main class for you. You can add the "Hello World!" message to the skeleton code by replacing the line:
// TODO code application logic here

with the line:


System.out.println("Hello World!");

Save the change by choosing File > Save.


The file should look something like the following code sample.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package helloworldapp;

/**
*
* @author <your name>
*/
public class HelloWorldApp {

- 38 - | P a g e
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Hello World!");
}

Compiling and Running the Program


Because of the IDE's Compile on Save feature, you do not have to manually compile your project in order to run it in
the IDE. When you save a Java source file, the IDE automatically compiles it.
The Compile on Save feature can be turned off in the Project Properties window. Right-click your project, select
Properties. In the Properties window, choose the Compiling tab. The Compile on Save checkbox is right at the top.
Note that in the Project Properties window you can configure numerous settings for your project: project libraries,
packaging, building, running, etc.
To run the program:
 Choose Run > Run Project.

The next figure shows what you should now see.

Figure 19: Output of HelloWorldApp

Congratulations! Your program works!


If there are compilation errors, they are marked with red glyphs in the left and right margins of the Source Editor. The
glyphs in the left margin indicate errors for the corresponding lines. The glyphs in the right margin show all of the
areas of the file that have errors, including errors in lines that are not visible. You can mouse over an error mark to
get a description of the error. You can click a glyph in the right margin to jump to the line with the error.

Building and Deploying the Application


Once you have written and test run your application, you can use the Clean and Build command to build your
application for deployment. When you use the Clean and Build command, the IDE runs a build script that performs
the following tasks:
 Deletes any previously compiled files and other build outputs.

- 39 - | P a g e
 Recompiles the application and builds a JAR file containing the compiled files.

To build your application:


 Choose Run > Clean and Build Project.

You can view the build outputs by opening the Files window and expanding the HelloWorldApp node. The
compiled bytecode file HelloWorldApp.class is within the build/classes/helloworldapp subnode. A
deployable JAR file that contains the HelloWorldApp.class is within the dist node.

Figure 19: Deploy Project

jGRASP:
jGRASP is a lightweight development environment, created specifically to provide automatic
generation of software visualizations to improve the comprehensibility of software. jGRASP is
implemented in Java, and runs on all platforms with a Java Virtual Machine (Java version 1.5 or
higher). jGRASP produces Control Structure Diagrams (CSDs) for Java, C, C++, Objective-C,
Python, Ada, and VHDL; Complexity Profile Graphs (CPGs) for Java and Ada; UML class
diagrams for Java; and has dynamic object viewers and a viewer canvas that work in conjunction
with an integrated debugger and workbench for Java. The viewers include a data structure
identifier mechanism which recognizes objects that represent traditional data structures such as
stacks, queues, linked lists, binary trees, and hash tables, and then displays them in an intuitive
textbook-like presentation view.

Installing Java SE JDK.

1. Download the JDK installation package. The latest version can be either
downloaded from the Sun website or from the local

- 40 - | P a g e
cache http://cs.unc.edu/~zhangjd/comp110/software/jdk-6u1-windows-i586-p.exe

2. Run the file.

3. Accept the agreement and click next.

Figure 20: JDK Installation

4. Click Next

Figure 21: Selecting Installation Location

- 41 - | P a g e
5. After some installation, following window will popup. Click cancel and the
installation if complete.

Installing jGrasp

1. Download the jGrasp from the official website or from the local
cache http://cs.unc.edu/~zhangjd/comp110/software/jgrasp186_01.exe and run it.

- 42 - | P a g e
2.

- 43 - | P a g e
- 44 - | P a g e
- 45 - | P a g e
Check only the followings and click install.

- 46 - | P a g e
Project Work:-

TITLE
General Billing System

INTRODUCTION SYSTEM

The project “Billing system” is an application to automate the process of ordering and
billing of a “General store” .This desktop application is designed considering the chain of
general stores which is located in various cities. This application also administrates its
users and customers.

SCOPE OF SYSTEM

1 This project will help the store keeper in fast billing


2 This project enable store keeper to maintain a great database of all customers
visited and purchase product from store.
3 Project will enable to see report regarding product and category.
4 Easy to maintain in future prospect.

PROPOSED SYSTEM

1. Easiness in modification of data: The proposed system provides managing of huge


data effectively and efficiently for efficient results, storing the details of the customers,
employees etc. in such a way that the database can be modified.

2. User friendly: The proposed system is user friendly because the retrieval and storing
of data is fast and data is maintained efficiently.
Moreover the graphical user interface is provided in the proposed system, which
provides user to deal with the system very easily.

- 47 - | P a g e
3. Reports are easily generated: Reports can be easily generated in a proposed
system. So any type of reports can be generated in a proposed system, which helps the
managers in a decisions-making activity.

4. Sharing the data is possible: Data can be shared in proposed system.


This means that two or more persons can use the same data in existing system
provided that they have right to access that data. Also the two or more departments in
an organization can easily interact with each other without the actual movement of data.

5. No or very few paperwork: The proposed system either does not require paper
work or very few paper works is required. All the data is feted into the computer
immediately and various bills and reports can be generated through computers. Since
all the data is kept in a database no data of the organization can be destroyed.
Moreover work becomes very easy because there is no need to keep data on papers.

6. Support strategic competitive advantage: Proposed system supports strategic


competitive advantages. Since the proposed systems provide easiness in reports
generating it will provide strategic advantages among competitors.

7. Computer operator control: Computer operator control will be there no errors.


Moreover storing and retrieving of information is easy. So work can be done speedily
and in time.

HARDWARE AND SOFTWARE REQUIREMENT


CPU configuration

- Any Intel/AMD Processor


- RAM 513 MB DDR2

Monitor

-17” color

Operating System

-Windows XP with service pack 2 or higher

Additional Hardware

-Printer

- 48 - | P a g e
SYSTEM DESIGN

E-R Diagram

Stax no

Add2 Add1 make


name name Rate

Add3 Cust.no Item no


Ratio

Cst no. Customer Master Item Master

unit
Tin no

has purchas sale


e
total
Po.no
Bill Info contain Item_Sold quantity
c.name
Tax % Unit price

fldate
Sub total Sr no.
Bill no
Po.date

Item name
Item make
total Bill no Item no

- 49 - | P a g e
APPENDICES

JVM:
Java code can run on any platform by using JVM. JVM normally reads and executes Java
statements one at a time.

JRE:
JRE provides run time environment, any program will not execute in java without JRE.

JDK:
Contains the software and tools needed to compile, debug and execute applets and applications.

MYSQL:
MYSQL is a database that is used to store all the internal data of the project, here
tables are created to store the collection or information about the project.

ER Dia.:
ER Diagrams are used to show the entities, attributes, relationship of the project. This shows how
1 entity is related to other entity and what are the relationship among these entities.

DFD:
Data Flow Diagram shows the complete running process of data, i.e. how data is transfer from
one stage to another, what is the process of flow of data, the initial stage the final stage all the
steps are shown by Data Flow Diagram.

Tables:
It stores all the collection of the data used in the project , different tables are created for the
collection of data, in tables there are two parts row and column, each new entity is add in row,
and attributes are added in the form of columns, these attributes are also termed as Tupples.

- 50 - | P a g e
Tools:
JDK 1.7.
Netbeans 7/8 & jGrasp
Gif images.
Hardware-
Laptop or P.C. -Intel Core 2 duo, i3 or i5 processor

- 51 - | P a g e
REFERENCES

Books:
Complete Reference,
E.Balaguru Swami.
Black Book of JAVA.
Websites:
www.javaprogram.com
www.aptecheducation.com
tutorials.jenkov.com/java-collections/list.html
https://www.java.com/en/download/faq/exception_sitelist.xml

- 52 - | P a g e

Anda mungkin juga menyukai