hi folks,

No More fear of pointers........

Break the old rhythm.Explore the new horizons.

Be a crew member to the new ship......

get easy solutions to solve ur programming issues


Comments in Java Code

@author:surendranadh reddy
* The HelloWorldApp class implements an application that

* simply displays "Hello World!" to the standard output.


class HelloWorldApp


public static void main(String[] args)


System.out.println("Hello World!"); //Display the string.



The Java language supports three kinds of comments:

/* text */

The compiler ignores everything from /* to */.

/** documentation */

This indicates a documentation comment (doc comment, for short). The compilerignores this kind of comment, just like it ignores comments that use /* and */.

// text

The compiler ignores everything from // to the end of the line

Developing the Java Application

A Java application is a standalone Java program-- a program written in the Java language that runs independently of any browser.


@ surendranadh reddy
* The HelloWorldApp class implements an application that

* simply displays "Hello World!" to the standard output.


class HelloWorldApp


public static void main(String[] args)


System.out.println("Hello World!"); //Display the string.




Java Development Kit

The Java Development Kit comes with a collection of tools that are used for developing and running Java programs. They include:

• appletviewer ( for viewing Java applet)

• javac (Java compiler)

• java (Java Interpreter)

• javap (Java disassembler)

• javah (for C header files)

• javadoc (for creating HTML documents)

• jdb (Java debugger)

The below figure depicts a Java program, such as an application or applet, that's running on the Java platform. As the figure shows, the Java API and Virtual Machine insulates the Java program from hardware dependencies.

The Java Platform

A platform is the hardware or software environment in which a program runs. The Java

platform differs from most other platforms in that it's a software-only platform that runs on
top of other, hardware-based platforms. Most other platforms are described as a combination of hardware and operating system.
The Java platform has two components:

 • The Java Virtual Machine (Java VM)
• The Java Application Programming Interface (Java API)

The Java VM is the base for the Java platform and is ported onto various hardware-based platforms.
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 (application programming interface) is grouped into libraries (packages) of related components.


Java is also unusual in that each Java program is both compiled and interpreted.

With a compiler, it translates a Java program into an intermediate language called Java bytecodes--the platform-independent codes interpreted by the Java interpreter.
With an interpreter, each Java bytecode instruction is parsed and run on the computer. Compilation happens just once; interpretation occurs each time the program is executed. This figure show how it works.
The Java bytecodes is the machine code instructions for the Java Virtual Machine (Java VM). Every Java interpreter, whether it's a Java development tool or a Web browser that can run Java applets, is an implementation of the Java VM. The Java VM can also be implemented in hardware.

Java bytecodes help make "write once, run anywhere" possible.
One can compile your Java program into bytecodes on any platform that has a Java compiler. The bytecodes can then be run on any implementation of the Java VM.


To develop and distribute a Java program

1. Programmer codes Java source statements

2. Java compiler converts source statements into bytecode (platform-independent object language)

3. Bytecode is copied to the target platform

 To execute a Java program

1. Platform-dependent Java Virtual Machine (JVM) software must be installed

2. A copy of the JVM is started

3. Each bytecode statement is interpreted (translated) by the JVM into platform-dependent machine language and executed under JVM control.

Benefits of Java over C and C++

• Architecturally neutral. Once written, the same Java program can be run on any

platform computer and operating system) that supports Java.

• Entirely object-oriented. Existing code can be easily re-used and maintained.

• Secure. Dangerous program actions are prohibited.

• Supports Internet programming. Java applets are run by Web browsers.

• Robust. Language features and packaged code support graphical programming,
   exception handling, networking, multi-threading, I/O, and more.


JDBC Introduction

The JDBC API is a Java API that can access any kind of tabular data, especially data stored in a Relational Database.

JDBC helps you to write java applications that manage these three programming activities:

1.Connect to a data source, like a database

2.Send queries and update statements to the database

3.Retrieve and process the results received from the database in answer to your query

The following simple code fragment gives a simple example of these three steps:

Connection con = DriverManager.getConnection

( "jdbc:myDriver:wombat", "myLogin","myPassword");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");

while (rs.next()) {

int x = rs.getInt("a");

String s = rs.getString("b");

float f = rs.getFloat("c");


This short code fragment instantiates a DriverManager object to connect to a database driver and log into the database, instantiates a Statement object that carries your SQL language query to the database; instantiates a ResultSet object that retrieves the results of your query, and executes a simple while loop, which retrieves and displays those results. It's that simple.

JDBC Product Components

JDBC includes four components:


The JDBC™ API provides programmatic access to relational data from the Java™ programming language. Using the JDBC API, applications can execute SQL statements, retrieve results, and propagate changes back to an underlying data source. The JDBC API can also interact with multiple data sources in a distributed, heterogeneous environment.
        The JDBC API is part of the Java platform, which includes the Java™ Standard Edition (Java™ SE ) and the Java™ Enterprise Edition (Java™ EE). The JDBC 4.0 API is divided into two packages: java.sql and javax.sql. Both packages are included in the Java SE and Java EE platforms.

JDBC Driver Manager

The JDBC DriverManager class defines objects which can connect Java applications to a JDBC driver. DriverManager has traditionally been the backbone of the JDBC architecture. It is quite small and simple.
The Standard Extension packages javax.naming and javax.sql let you use a DataSource object registered with a Java Naming and Directory Interface™ (JNDI) naming service to establish a connection with a data source. You can use either connecting mechanism, but using a DataSource object is recommended whenever possible.

JDBC Test Suite

The JDBC driver test suite helps you to determine that JDBC drivers will run your program. These tests are not comprehensive or exhaustive, but they do exercise many of the important features in the JDBC API.


The Java Software bridge provides JDBC access via ODBC drivers. Note that you need to load ODBC binary code onto each client machine that uses this driver. As a result, the ODBC driver is most appropriate on a corporate network where client installations are not a major problem, or for application server code written in Java in a three-tier architecture.

This Trail uses the first two of these these four JDBC components to connect to a database and then build a java program that uses SQL commands to communicate with a test Relational Database. The last two components are used in specialized environments to test web applications, or to communicate with ODBC-aware DBMSs.

JDBC Architecture

Two-tier and Three-tier Processing Models

The JDBC API supports both two-tier and three-tier processing models for database access.

Figure 1: Two-tier Architecture for Data Access.

In the two-tier model, a Java applet or application talks directly to the data source. This requires a JDBC driver that can communicate with the particular data source being accessed. A user's commands are delivered to the database or other data source, and the results of those statements are sent back to the user. The data source may be located on another machine to which the user is connected via a network. This is referred to as a client/server configuration, with the user's machine as the client, and the machine housing the data source as the server. The network can be an intranet, which, for example, connects employees within a corporation, or it can be the Internet.

In the three-tier model, commands are sent to a "middle tier" of services, which then sends the commands to the data source. The data source processes the commands and sends the results back to the middle tier, which then sends them to the user. MIS directors find the three-tier model very attractive because the middle tier makes it possible to maintain control over access and the kinds of updates that can be made to corporate data. Another advantage is that it simplifies the deployment of applications. Finally, in many cases, the three-tier architecture can provide performance advantages.

Figure 2: Three-tier Architecture for Data Access.

Until recently, the middle tier has often been written in languages such as C or C++, which offer fast performance. However, with the introduction of optimizing compilers that translate Java bytecode into efficient machine-specific code and technologies such as Enterprise JavaBeans™, the Java platform is fast becoming the standard platform for middle-tier development. This is a big plus, making it possible to take advantage of Java's robustness, multithreading, and security features.

With enterprises increasingly using the Java programming language for writing server code, the JDBC API is being used more and more in the middle tier of a three-tier architecture. Some of the features that make JDBC a server technology are its support for connection pooling, distributed transactions, and disconnected rowsets. The JDBC API is also what allows access to a data source from a Java middle tier.




Many people seem to have problems with setting the PATH and CLASS PATH variables, and struggle even when they know that this is the cause of their problems in trying to create the well formed command line "set classpath...etc"

I personally went and created the environment variable through Windows, which worked the first time, after struggling for a while at the command line syntax.

The steps I took to do it in Windows XP: Start->Settings->Control Panel->System->Advanced Tab-> Environment Variables

"User variables for username" Box->"New" Button

Variable name:PATH

Varaible value: C:\Program Files\Java\jdk1.6.0_05\bin

Click on OK and select the new tab

Variable name:CLASS PATH

Varaible value: C:\Program Files\Java\jdk1.6.0_05\lib

"Ok" until you close all the windows, and reboot the system. (Technically you only need to end java processes, but a reboot never hurts)

Everything should work now.

I've never been a fan for hand holding, but wasting time on code set up is frustrating and wasteful. Good luck everyone.



              Java is a simple language which can be learned easily,even if you have just started programming,it is also a simplified version of Internet and Object oriented programming language.

                                 Almost everything in java is class,a method or an object.Any cod that you write in java is inside a class.Java is purely object oriented.An object is a software bundle of variable and related methods.

                         Java is designed as a distributed language for creating applications on networks.It has ability to share both data and programs.

                       Interpreting mans actually compiling the program line by line and generates the machine code.Java interpreter generates machine code that can be directly executed which is platform independent.

              Java is a robust language as it provides many safeguards to ensure reliable code.It has strict compile time and run time checking for data types.

              No viruses can affect the java program as java ensures that program cannot gain access to memory locations without proper authorization.Java systems not only verify all memory access but also ensures that no viruses are communicated with an applet.

ARCHITECTURE NEUTRAL:(Platform Independent)
                                              We know that,java compiler produce the byte code.The byte code can be executed  on a variety of computers running on different operating system such as window 98/2000,windows NT,Sun Solaris and Mac OS.The another reason is, the size of primitive data types are machine independent.

                       Java programs can run on multiple platforms.hence,only one version of the application needs to be developed and maintained.Java source code files as ASCII text files.Java source files are compiled to byte cod files.Byte code is standardized,machine independent,low level language.These Byte codes are loaded and interpreted at clients machine  by a special program called Java Virtual Machine(JVM).

                                    Java performance is impressive for an interpreted  language,mainly due to the use of Intermediate byte code.

                         Multithreading is the ability of an application to perform multiple tasks at the same time.The synchronization feature eliminated much of the difficulties of dealing with a multithreaded environments unpredictable nature.

                  Maintaining different versions of an application is very easy in Java.Java is capable of dynamically linking in class libraries,methods and objects.Java supports dynamic memory allocation with automatic garbage collection.


  • Java is a general purpose,object oriented programming language.
  • The fastest growing programming language in the history of computing.
  • Developd by Sun Microsystems of USA in 1991.
  • Originally it is called OAK by James Gosling.
  • Originally designed in 1991 for use in embedded consumer applications.
  • Java team which headed James Gosling developed a web browser called 'Hot Java' to locate and run applet programs on Internet n 1994.
  • OAK was renamed as "Java" in 1995.
  • Redesignd in early 1995 with Internet application capabilities.
  • Introduced in May,1995 and immediately supportd by the Netscape web browswer.
  • Rapidly overtaking c++ in popularity among commercial software developers.
  • Java established itself not only as a leader for internet programming but also as a general purpose ,object-oriented programming language.
  • Java found its home in the heart of the modern programmer.
  • Java is the first programmng language that is not tied to any particular hardware or operating system.
  • Programs dveloped in java can be executed anywhere on any system.
  • Therefore java comes as a revolutionary technology because it has brought in a fundamental shift in how we develop and use programs.

Search This Blog