Qureshi University, Advanced courses, via cutting edge technology, News, Breaking News | Latest News And Media | Current News
admin@qureshiuniversity.com

Apply for Academic Admission | Academic Guide | Aircraft | Aviation World | Ambassadors | Accreditation | A to Z Degree Fields | Books | Blog | Catalog | Calendar | Collaboration | Colleges | Complaint | Contact Us | Continents/States | Construction | Contracts | Courses | Doctor Consultation | Distance Education | Equipment | Emergency | Emergency call centers | Economy and Budget | Examinations | English Editing Service | Forms | Faculty | Facilities | Governor | Glossary | Grants | Hostels | Honorary Doctorate degree | Human Services | Human Resources | Internet Education | Inspections | Internet | Investment | Instructors | Internship | Job Openings | Login | Lecture | Librarians | Languages | License/Permit/Registration | Medical Emergency | Manufacturing | Materials | Mentor | Movies | Money transfer(Pay Now) | Membership | North America | Non-Emergency Services | Observers | Planet Earth | Proposals | Publication | Professional Examinations | Programs | Professions | Paraprofessional | Profile | Progress Report | Recommendations | Ration food and supplies | Research Grants | Research | State Directories | Students login | School | Search | Software | Seminar | Study Center/Centre | Sponsorship | Submit an Issue | Team | Tutoring | Thesis | Universities | Universe & Space | Vehicles | Work counseling

How Java Works
What is Java technology and why do I need it?
Is Java free to download?
Why should I upgrade to the latest Java version?
What will I get when I download Java software?
What is Java Plug-in software?
I have heard the terms Java Virtual Machine and JVM. Is this Java software?
Have you ever wondered how computer programs work?
Have you ever wanted to learn how to write your own computer programs?
What other functions are available besides drawLine?
What Can Java Technology Do?
How Will Java Technology Change My Life?
What Can You Do With PHP Java & Javascript?
What is Java technology and why do I need it?
Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!

Is Java free to download?
Yes, Java is free to download. Get the latest version at java.com.

If you are building an embedded or consumer device and would like to include Java, please contact Oracle for more information on including Java in your device.

Why should I upgrade to the latest Java version?
The latest Java version contains important enhancements to improve performance, stability and security of the Java applications that run on your machine. Installing this free update will ensure that your Java applications continue to run safely and efficiently.

What will I get when I download Java software?
The Java Runtime Environment (JRE) is what you get when you download Java software. The JRE consists of the Java Virtual Machine (JVM), Java platform core classes, and supporting Java platform libraries. The JRE is the runtime portion of Java software, which is all you need to run it in your Web browser.

What is Java Plug-in software?
The Java Plug-in software is a component of the Java Runtime Environment (JRE). The JRE allows applets written in the Java programming language to run inside various browsers. The Java Plug-in software is not a standalone program and cannot be installed separately.

I have heard the terms Java Virtual Machine and JVM. Is this Java software?
The Java Virtual Machine is only one aspect of Java software that is involved in web interaction. The Java Virtual Machine is built right into your Java software download, and helps run Java applications.

Have you ever wondered how computer programs work? Have you ever wanted to learn how to write your own computer programs?
•Computer program - A computer program is a set of instructions that tell a computer exactly what to do. The instructions might tell the computer to add up a set of numbers, or compare two numbers and make a decision based on the result, or whatever. But a computer program is simply a set of instructions for the computer, like a recipe is a set of instructions for a cook or musical notes are a set of instructions for a musician. The computer follows your instructions exactly and in the process does something useful -- like balancing a checkbook or displaying a game on the screen or implementing a word processor.

•Programming language - In order for a computer to recognize the instructions you give it, those instructions need to be written in a language the computer understands -- a programming language. There are many computer programming languages -- Fortran, Cobol, Basic, Pascal, C, C++, Java, Perl -- just like there are many spoken languages. They all express approximately the same concepts in different ways.

•Compiler - A compiler translates a computer program written in a human-readable computer language (like Java) into a form that a computer can execute. You have probably seen EXE files on your computer. These EXE files are the output of compilers. They contain executables -- machine-readable programs translated from human-readable programs.

In order for you to start writing computer programs in a programming language called Java, you need a compiler for the Java language. The next section guides you through the process of downloading and installing a compiler. Once you have a compiler, we can get started. This process is going to take several hours, much of that time being download time for several large files. You are also going to need about 40 megabytes of free disk space (make sure you have the space available before you get started).

Downloading the Java Compiler

In order to get a Java development environment set up on your machine -- you "develop" (write) computer programs using a "development environment" -- you will have to complete the following steps:

1.Download a large file containing the Java development environment (the compiler and other tools). 2.Download a large file containing the Java documentation.
3.If you do not already have WinZip (or an equivalent) on your machine, you will need to download a large file containing WinZip and install it.
4.Install the Java development environment.
5.Install the documentation.
6.Adjust several environment variables.
7.Test everything out.

Before getting started, it would make things easier if you create a new directory in your temp directory to hold the files we are about to download. We will call this the download directory.

Step 1 - Download the Java development environment

Go to the page http://java.sun.com/j2se/1.4.2/download.html. Download the SDK software by clicking on the "Download J2SE SDK" link. You will be shown a licensing agreement. Click Accept. Select your operating system and download the file to your download directory. This is a huge file, and it will take several hours to download over a normal phone-line modem. The next two files are also large.

Step 2 - Download the Java documentation

Download the documentation by selecting your operating system and clicking the SDK 1.4.1 documentation link.

Step 3 - Download and install WinZip

If you do not have a version of WinZip or an equivalent on your machine, go to the page http://www.winzip.com/ and download an evaluation copy of WinZip. Run the EXE you get to install it. We will use it in a moment to install the documentation.

Step 4 - Install the development kit

Run the j2sdk-1_4_1-*.exe file that you downloaded in step 1. It will unpack and install the development kit automatically.

Step 5 - Install the documentation

Read the installation instructions for the documentation. They will instruct you to move the documentation file to same directory as that containing the development kit you just installed. Unzip the documentation and it will drop into the proper place.

Step 6 - Adjust your environment

As instructed on this page, you need to change your path variable. This is most easily done by opening an MS-DOS prompt and typing PATH to see what the path is set to currently. Then open autoexec.bat in Notepad and make the changes to PATH specified in the instructions.

Step 7 - Test

Now you should be able to open another MS-DOS window and type javac. If everything is set up properly, then you should see a two-line blob of text come out that tells you how to use javac. That means you are ready to go. If you see the message "Bad Command or File Name" it means you are not ready to go. Figure out what you did wrong by rereading the installation instructions. Make sure the PATH is set properly and working. Go back and reread the Programmer's Creed above and be persistent until the problem is resolved.

You are now the proud owner of a machine that can compile Java programs. You are ready to start writing software!

By the way, one of the things you just unpacked is a demo directory full of neat examples. All of the examples are ready to run, so you might want to find the directory and play with some of the samples. Many of them make sounds, so be sure to turn on your speakers. To run the examples, find pages with names like example1.html and load them into your usual Web browser.

Your First Program

Your first program will be short and sweet. It is going to create a drawing area and draw a diagonal line across it. To create this program you will need to:

1.Open Notepad and type in (or cut and paste) the program
2.Save the program
3.Compile the program with the Java compiler to create a Java applet
4.Fix any problems
5.Create an HTML web page to "hold" the Java Applet you created
6.Run the Java applet
Here is the program we will use for this demonstration:

import java.awt.Graphics;

public class FirstApplet extends java.applet.Applet

{

public void paint(Graphics g)

{

g.drawLine(0, 0, 200, 200);

}

}Step 1 - Type in the program

Create a new directory to hold your program. Open up Notepad (or any other text editor that can create TXT files). Type or cut and paste the program into the Notepad window. This is important: When you type the program in, case matters. That means that you must type the uppercase and lowercase characters exactly as they appear in the program. Review the programmer's creed above. If you do not type it EXACTLY as shown, it is not going to work.

Step 2 - Save the file

Save the file to the filename FirstApplet.java in the directory that you created in step 1. Case matters in the filename. Make sure the 'F' and 'A' are uppercase and all other characters are lowercase, as shown.

Step 3 - Compile the program

Open an MS-DOS window. Change directory ("cd") to the directory containing FirstApplet.java. Type:

javac FirstApplet.javaCase matters! Either it will work, in which case nothing will be printed to the window, or there will be errors. If there are no errors, a file named FirstApplet.class will be created in the directory right next to FirstApplet.java.

(Make sure that the file is saved to the name FirstApplet.java and not FirstApplet.java.txt. This is most easily done by typing dir in the MS-DOS window and looking at the file name. If it has a .txt extension, remove it by renaming the file. Or run the Windows Explorer and select Options in the View menu. Make sure that the "Hide MD-DOS File Extensions for file types that are registered" box is NOT checked, and then look at the filename with the explorer. Change it if necessary.)

Step 4 - Fix any problems

If there are errors, fix them. Compare your program to the program above and get them to match exactly. Keep recompiling until you see no errors. If javac seems to not be working, look back at the previous section and fix your installation.

Step 5 - Create an HTML Page

Create an HTML page to hold the applet. Open another Notepad window. Type into it the following:






Save this file in the same directory with the name applet.htm.

[If you have never worked with HTML before, please read How a Web Page Works. The applet tag is how you access a Java applet from a web page.]

Step 6 - Run the Applet

In your MS-DOS window, type:

appletviewer applet.htmYou should see a diagonal line running from the upper left corner to the lower right corner.

Pull the applet viewer a little bigger to see the whole line. You should also be able to load the HTML page into any modern browser like Netscape Navigator or Microsoft Internet Explorer and see approximately the same thing.

You have successfully created your first program!!!

Understanding What Just Happened

So what just happened?

First, you wrote a piece of code for an extremely simple Java applet. An applet is a Java program that can run within a Web browser, as opposed to a Java application, which is a stand-alone program that runs on your local machine (Java applications are slightly more complicated and somewhat less popular, so we will start with applets). We compiled the applet using javac. We then created an extremely simple Web page to "hold" the applet. We ran the applet using appletviewer, but you can just as easily run it in a browser.

The program itself is about 10 lines long:

import java.awt.Graphics;

public class FirstApplet extends java.applet.Applet

{

public void paint(Graphics g)

{

g.drawLine(0, 0, 200, 200);

}

}This is about the simplest Java applet you can create. To fully understand it you will have to learn a fair amount, particularly in the area of object oriented programming techniques. Since I am assuming that you have zero programming experience, what I would like you to do is focus your attention on just one line in this program for the moment:

g.drawLine(0, 0, 200, 200);This is the line in this program that does the work. It draws the diagonal line. The rest of the program is scaffolding that supports that one line, and we can ignore the scaffolding for the moment. What happened here was that we told the computer to draw one line from the upper left hand corner (0,0) to the bottom right hand corner (200, 200). The computer drew it just like we told it to. That is the essence of computer programming!

(Note also that in the HTML page, we set the size of the applet's window in step 5 above to have a width of 200 and a height of 200.)

In this program, we called a method (a.k.a. function) called drawLine and we passed it four parameters (0, 0, 200, 200). The line ends in a semicolon. The semicolon acts like the period at the end of the sentence. The line begins with g., signifying that we want to call the method named drawLine on the specific object named g (which you can see one line up is of the class Graphics -- we will get into classes and methods of classes in much more detail later in this article).

A method is simply a command -- it tells the computer to do something. In this case, drawLine tells the computer to draw a line between the points specified: (0, 0) and (200, 200). You can think of the window as having its 0,0 coordinate in the upper left corner, with positive X and Y axes extending to the right and down. Each dot on the screen (each pixel) is one increment on the scale.

Try experimenting by using different numbers for the four parameters. Change a number or two, save your changes, recompile with javac and rerun after each change in appletviewer, and see what you discover.

What other functions are available besides drawLine? You find this out by looking at the documentation for the Graphics class. When you installed the Java development kit and unpacked the documentation, one of the files unloaded in the process is called java.awt.Graphics.html, and it is on your machine. This is the file that explains the Graphics class. On my machine, the exact path to this file is D:\jdk1.1.7\docs\api\java.awt.Graphics.html. On your machine the path is likely to be slightly different, but close -- it depends on exactly where you installed things. Find the file and open it. Up toward the top of this file there is a section called "Method Index." This is a list of all of the methods this class supports. The drawLine method is one of them, but you can see many others. You can draw, among other things:

•Lines
•Arcs
•Ovals
•Polygons
•Rectangles
•Strings
•Characters

Read about and try experimenting with some of these different methods to discover what is possible. For example, try this code:

g.drawLine(0, 0, 200, 200);
g.drawRect(0, 0, 200, 200);
g.drawLine(200, 0, 0, 200);It will draw a box with two diagonals (be sure to pull the window big enough to see the whole thing). Try drawing other shapes. Read about and try changing the color with the setColor method. For example:

import java.awt.Graphics;
import java.awt.Color;

public class FirstApplet extends java.applet.Applet
{
public void paint(Graphics g)
{
g.setColor(Color.red);
g.fillRect(0, 0, 200, 200);
g.setColor(Color.black);
g.drawLine(0, 0, 200, 200);
g.drawLine(200, 0, 0, 200);

}
}Note the addition of the new import line in the second line of the program. The output of this program looks like this:

One thing that might be going through your head right now is, "How did he know to use Color.red rather than simply red, and how did he know to add the second import line?" You learn things like that by example. Because I just showed you an example of how to call the setColor method, you now know that whenever you want to change the color you will use Color. followed by a color name as a parameter to the setColor method, and you will add the appropriate import line at the top of the program. If you look up setColor, it has a link that will tell you about the Color class, and in it is a list of all the valid color names along with techniques for creating new (unnamed) colors. You read that information, you store it in your head and now you know how to change colors in Java. That is the essence of becoming a computer programmer -- you learn techniques and remember them for the next program you write. You learn the techniques either by reading an example (as you did here) or by reading through the documentation or by looking at example code (as in the demo directory). If you have a brain that likes exploring and learning and remembering things, then you will love programming!

In this section, you have learned how to write linear, sequential code -- blocks of code that consist of method calls starting at the top and working toward the bottom (try drawing one of the lines before you draw the red rectangle and watch what happens -- it will be covered over by the rectangle and made invisible. The order of lines in the code sequence is important). Sequential lines of code form the basic core of any computer program. Experiment with all the different drawing methods and see what you can discover.

Bugs and Debugging

One thing that you are going to notice as you learn about programming is that you tend to make a fair number of mistakes and assumptions that cause your program to either: 1) not compile, or 2) produce output that you don't expect when it executes. These problems are referred to as bugs, and the act of removing them is called debugging. About half of the time of any programmer is spent debugging.

You will have plenty of time and opportunity to create your own bugs, but to get more familiar with the possibilities let's create a few. In your program, try erasing one of the semicolons at the end of a line and try compiling the program with javac. The compiler will give you an error message. This is called a compiler error, and you have to eliminate all of them before you can execute your program. Try misspelling a function name, leaving out a "{" or eliminating one of the import lines to get used to different compiler errors. The first time you see a certain type of compiler error it can be frustrating, but by experimenting like this -- with known errors that you create on purpose -- you can get familiar with many of the common errors.

A bug, also known as an execution (or run-time) error, occurs when the program compiles fine and runs, but then does not produce the output you planned on it producing. For example, this code produces a red rectangle with two diagonal lines across it:

g.setColor(Color.red);
g.fillRect(0, 0, 200, 200);
g.setColor(Color.black);
g.drawLine(0, 0, 200, 200);
g.drawLine(200, 0, 0, 200);The following code, on the other hand, produces just the red rectangle (which covers over the two lines):

g.setColor(Color.black);
g.drawLine(0, 0, 200, 200);
g.drawLine(200, 0, 0, 200);
g.setColor(Color.red);
g.fillRect(0, 0, 200, 200);The code is almost exactly the same but looks completely different when it executes. If you are expecting to see two diagonal lines, then the code in the second case contains a bug.

Here's another example:

g.drawLine(0, 0, 200, 200);
g.drawRect(0, 0, 200, 200);
g.drawLine(200, 0, 0, 200);This code produces a black outlined box and two diagonals. This next piece of code produces only one diagonal:

g.drawLine(0, 0, 200, 200);
g.drawRect(0, 0, 200, 200);
g.drawLine(0, 200, 0, 200);Again, if you expected to see two diagonals, then the second piece of code contains a bug (look at the second piece of code until you understand what went wrong). This sort of bug can take a long time to find because it is subtle.

You will have plenty of time to practice finding your own bugs. The average programmer spends about half of his or her time tracking down, finding and eliminating bugs. Try not to get frustrated when they occur -- they are a normal part of programming life.

Variables

All programs use variables to hold pieces of data temporarily. For example, if at some point in a program you ask a user for a number, you will store it in a variable so that you can use it later.

Variables must be defined (or declared) in a program before you can use them, and you must give each variable a specific type. For example, you might declare one variable to have a type that allows it to hold numbers, and another variable to have a type that allows it to hold a person's name. (Because Java requires you to specifically define variables before you use them and state the type of value you plan to store in a variable, Java is called a strongly typed language. Certain languages don't have these requirements. In general, when creating large programs, strong typing tends to reduce the number of programming errors that you make.)

import java.awt.Graphics;
import java.awt.Color;

public class FirstApplet extends java.applet.Applet
{
public void paint(Graphics g)
{
int width = 200;
int height = 200;
g.drawRect(0, 0, width, height);
g.drawLine(0, 0, width, height);
g.drawLine(width, 0, 0, height);

} }In this program, we have declared two variables named width and height. We have declared their type to be int. An int variable can hold an integer (a whole number such as 1, 2, 3). We have initialized both variables to 200. We could just as easily have said:

int width;
width = 200;
int height;
height = 200;The first form is simply a bit quicker to type.

The act of setting a variable to its first value is called initializing the variable. A common programming bug occurs when you forget to initialize a variable. To see that bug, try eliminating the initialization part of the code (the "= 200" part) and recompile the program to see what happens. What you will find is that the compiler complains about this problem. That's a very nice feature, by the way. It will save you lots of wasted time.

There are two types of variables in Java -- simple (primitive) variables and classes.

The int type is simple. The variable can hold a number. That is all that it can do. You declare an int , set it to a value and use it. Classes, on the other hand, can contain multiple parts and have methods that make them easier to use. A good example of a straightforward class is the Rectangle class, so let's start with it.

One of the limitations of the program we have been working on so far is the fact that it assumes the window is 200 by 200 pixels. What if we wanted to ask the window, "How big are you?," and then size our rectangle and diagonals to fit? If you go back and look on the documentation page for the Graphics class (java.awt.Graphics.html -- the file that lists all the available drawing functions), you will see that one of the functions is called getClipBounds. Click on this function name to see the full description. This function accepts no parameters but instead returns a value of type Rectangle. The rectangle it returns contains the width and height of the available drawing area. If you click on Rectangle in this documentation page you will be taken to the documentation page for the Rectangle class (java.awt.Graphics.html). Looking in the Variable Index section at the top of the page, you find that this class contains four variables named x, y, width and height, respectively. What we want to do, therefore, is get the clip boundary rectangle using getClipBounds and then extract the width and height from that rectangle and save the values in the width and height variables we created in the previous example, like this:

import java.awt.Graphics;
import java.awt.Color;
import java.awt.Rectangle;
public class FirstApplet extends java.applet.Applet
{
public void paint(Graphics g)
{
int width;
int height;
Rectangle r;
r = g.getClipBounds();
width = r.width - 1;
height = r.height - 1;
g.drawRect(0, 0, width, height);
g.drawLine(0, 0, width, height);
g.drawLine(width, 0, 0, height);
} }When you run this example, what you will notice is that the rectangle and diagonals exactly fit the drawing area. Plus, when you change the size of the window, the rectangle and diagonals redraw themselves at the new size automatically. There are five new concepts introduced in this code, so let's look at them:

1.First, because we are using the Rectangle class we need to import java.awt.Rectangle on the third line of the program.

2.We have declared three variables in this program. Two (width and height) are of type int and one (r) is of type Rectangle.

3.We used the getClipBounds function to get the size of the drawing area. It accepts no parameters so we passed it none ("()"), but it returns a Rectangle. We wrote the line, "r = g.getClipBounds();" to say, "Please place the returned rectangle into the variable r."

4.The variable r, being of the class Rectangle, actually contains four variables -- x, y, width, and height (you learn these names by reading the documentation for the Rectangle class). To access them you use the "." (dot) operator. So the phrase "r.width" says, "Inside the variable r retrieve the value named width." That value is placed into our local variable called width. In the process, we subtracted 1. Try leaving the subtraction out and see what happens. Also try subtracting five instead and see what happens.

5.Finally, we used width and height in the drawing functions. One question commonly asked at this point is, "Did we really need to declare variables named width and height?" The answer is, "No." We could have typed r.width - 1 directly into the drawing function. Creating the variables simply makes things a little easier to read, and it's therefore a good habit to fall into.

Java supports several simple variable types. Here are three of the most common:

•int - integer (whole number) values (1, 2, 3...)
•float - decimal values (3.14159, for example)
•char - character values (a, b, c...)
You can perform math operations on simple types. Java understands + (addition), - (subtraction), * (multiplication), / (division) and several others. Here's an example of how you might use these operations in a program. Let's say that you want to calculate the volume of a sphere with a diameter of 10 feet. The following code would handle it:

float diameter = 10;
float radius;
float volume;

radius = diameter / 2.0;
volume = 4.0 / 3.0 * 3.14159 * radius * radius * radius;The first calculation says, "Divide the value in the variable named diameter by 2.0 and place the result in the variable named radius." You can see that the "=" sign here means, "Place the result from the calculation on the right into the variable named on the left."

Looping

One of the things that computers do very well is perform repetitive calculations or operations. In the previous sections, we have seen how to write "sequential blocks of code," so the next thing we should discuss is the techniques for causing a sequential block of code to occur repeatedly.

For example, let's say that I ask you to draw the grid pictured at the top of the page.

A good place to start would be to draw the horizontal lines.

One way to draw the lines would be to create a sequential block of code:

import java.awt.Graphics;

public class FirstApplet extends java.applet.Applet

{ public void paint(Graphics g)

{
int y;
y = 10;
g.drawLine(10, y, 210, y);
y = y + 25;
g.drawLine(10, y, 210, y);
y = y + 25;
g.drawLine(10, y, 210, y);
y = y + 25;
g.drawLine(10, y, 210, y);
y = y + 25;
g.drawLine(10, y, 210, y);
y = y + 25;
g.drawLine(10, y, 210, y);
y = y + 25;
g.drawLine(10, y, 210, y);
y = y + 25;
g.drawLine(10, y, 210, y);
y = y + 25;
g.drawLine(10, y, 210, y);

}

}(For some new programmers, the statement "y = y + 25;" looks odd the first time they see it. What it means is, "Take the value currently in the variable y, add 25 to it and place the result back into the variable y." So if y contains 10 before the line is executed, it will contain 35 immediately after the line is executed.)

Most people who look at this code immediately notice that it contains the same two lines repeated over and over. In this particular case the repetition is not so bad, but you can imagine that if you wanted to create a grid with thousands of rows and columns, this approach would make program-writing very tiring. The solution to this problem is a loop, as shown below:

import java.awt.Graphics;

public class FirstApplet extends java.applet.Applet

{
public void paint(Graphics g)
{
int y;
y = 10;
while (y <= 210)
{
g.drawLine(10, y, 210, y);
y = y + 25;
}
}
}When you run this program, you will see that it draws nine horizontal lines 200 pixels long.

The while statement is a looping statement in Java. The statement tells Java to behave in the following way: At the while statement, Java looks at the expression in the parentheses and asks, "Is y less than or equal to 210?"

•If the answer is yes, then Java enters the block of code bracketed by braces -- "{" and "}". The looping part occurs at the end of the block of code. When Java reaches the ending brace, it loops back up to the while statement and asks the question again. This looping sequence may occur many times.

•If the answer is no, it skips over the code bracketed by braces and continues. So you can see that when you run this program, initially y is 10. Ten is less than 210, so Java enters the block in braces, draws a line from (10,10) to (210, 10), sets y to 35 and then goes back up to the while statement. Thirty-five is less than 210, so Java enters the block in braces, draws a line from (10,35) to (210, 35), sets y to 60 and then goes back up to the while statement. This sequence repeats until y eventually gets to be greater than 210. Then the program quits.

We can complete our grid by adding a second loop to the program, like this:

import java.awt.Graphics;

public class FirstApplet extends java.applet.Applet

{
public void paint(Graphics g)
{
int x, y;
y = 10;
while (y <= 210)
{
g.drawLine(10, y, 210, y);
y = y + 25;
}
x = 10;
while (x <= 210)
{
g.drawLine(x, 10, x, 210);
x = x + 25;
}
}
}You can see that a while statement has three parts:

•There is an initialization step that sets y to 10.

•Then there is an evaluation step inside the parentheses of the while statement.

•Then, somewhere in the while statement there is an increment step that increases the value of y. Java supports another way of doing the same thing that is a little more compact than a while statement. It is called a for statement. If you have a while statement that looks like this:

y = 10;
while (y <= 210)
{
g.drawLine(10, y, 210, y);
y = y + 25;
}then the equivalent for statement looks like this:
for (y = 10; y <= 210; y = y + 25)
{
g.drawLine(10, y, 210, y);
}You can see that all the for statement does is condense the initialization, evaluation and incrementing lines into a short, single line. It simply shortens the programs you write, nothing more.

While we are here, two quick points about loops:

•In many cases, it would be just as easy to initialize y to 210 and then decrement it by 25 each time through the loop. The evaluation would ask, "Is y greater than or equal to 10?" The choice is yours. Most people find it easier to add than subtract in their heads, but you might be different. •The increment step is very important. Let's say you were to accidentally leave out the part that says "y = y + 25;" inside the loop. What would happen is that the value of y would never change -- it would always be 10. So it would never become greater than 210 and the loop would continue forever (or until you stop it by turning off the computer or closing the window). This condition is called an infinite loop. It is a bug that is pretty common.

What Can Java Technology Do?
The general-purpose, high-level Java programming language is a powerful software platform. Every full implementation of the Java platform gives you the following features:

•Development Tools: The development tools provide everything you'll need for compiling, running, monitoring, debugging, and documenting your applications. As a new developer, the main tools you'll be using are the javac compiler, the java launcher, and the javadoc documentation tool.

•Application Programming Interface (API): The API provides the core functionality of the Java programming language. It offers a wide array of useful classes ready for use in your own applications. It spans everything from basic objects, to networking and security, to XML generation and database access, and more. The core API is very large; to get an overview of what it contains, consult the Java Platform Standard Edition 8 Documentation.

•Deployment Technologies: The JDK software provides standard mechanisms such as the Java Web Start software and Java Plug-In software for deploying your applications to end users.

•User Interface Toolkits: The JavaFX, Swing, and Java 2D toolkits make it possible to create sophisticated Graphical User Interfaces (GUIs).

•Integration Libraries: Integration libraries such as the Java IDL API, JDBC API, Java Naming and Directory Interface (JNDI) API, Java RMI, and Java Remote Method Invocation over Internet Inter-ORB Protocol Technology (Java RMI-IIOP Technology) enable database access and manipulation of remote objects.

How Will Java Technology Change My Life?
We can't promise you fame, fortune, or even a job if you learn the Java programming language. Still, it is likely to make your programs better and requires less effort than other languages. We believe that Java technology will help you do the following:

•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 written in C++.

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

•Develop programs more quickly: The Java programming language is simpler than C++, and as such, your development time could be up to twice as fast when writing in it. Your programs will also require fewer lines of code.

•Avoid platform dependencies: You can keep your program portable by avoiding the use of libraries written in other languages.

•Write once, run anywhere: Because applications written in the Java programming language are compiled into machine-independent bytecodes, they run consistently on any Java platform. •Distribute software more easily: With Java Web Start software, users will be able to launch your applications with a single click of the mouse. An automatic version check at startup ensures that users are always up to date with the latest version of your software. If an update is available, the Java Web Start software will automatically update their installation.

Why you should learn Java Programming Language

1) Java is Easy to learn

Many would be surprised to see this one of the top reason of learning Java, or considering it as best programming language, but it is. If you have steep learning curve, it would be difficult to get productive in short span of time, which is the case with most of professional project. Java has fluent English like syntax with minimum magic characters e.g. Generics angle brackets, which makes it easy to read Java program and learn quickly. Once a programmer is familiar with initial hurdles with installing JDK and setting up PATH and understand How Classpath works, it's pretty easy to write program in Java.

2) Java is an Object Oriented Programming Language

Another reason, which made Java popular is that it's an Object Oriented Programming language. Developing OOPS application is much easier, and it also helps to keep system modular, flexible and extensible. Once you have knowledge of key OOPS concept like Abstraction, Encapsulation, Polymorphism and Inheritance, you can use all those with Java. Java itself embodies many best practices and design pattern in it's library. Java is one of the few close to 100% OOPS programming language. Java also promotes use of SOLID and Object oriented design principles in form of open source projects like Spring, which make sure your object dependency is managed well by using dependency Injection principle.

3) Java has Rich API

One more reason of Java programming language's huge success is it's Rich API and most importantly it's highly visible, because come with Java installation. When I first started Java programming, I used to code Applets and those days Applets provides great animation capability, which amazes new programmer like us, who are used to code in Turbo C++ editor. Java provides API for I/O, networking, utilities, xml parsing, database connection, and almost everything. Whatever left is covered by open source libraries like Apache Commons, Google Guava and others.

4) Powerful development tools e.g. Eclipse , Netbeans

Believe it or not, Eclipse and Netbeans has played huge role to make Java one of the best programming language. Coding in IDE is pleasure, especially if you have coded in DOS Editor or Notepad. They not only helps in code completion but also provides powerful debugging capability, which is essential for real world development. Integrated Development Environment (IDE) made Java development much easier, faster and fluent. It's easy to search, refactor and read code using IDEs. Apart from IDE, Java platform also has several other tools e.g.. Maven and ANT for building Java applications, decompilers, JConsole, Visual VM for monitoring Heap usage etc.

5) Great collection of Open Source libraries
Open source libraries ensures that Java should be used everywhere. Apache, Google, and other organization has contributed lot of great libraries, which makes Java development easy, faster and cost effective. There are framework like Spring, Struts, Maven, which ensures that Java development follows best practices of software craftsmanship, promotes use of design patterns and assisted Java developers to get there job done. I always recommend to search for a functionality in Google, before writing your own code. There is good chance that, it's already coded, tested and available for ready to use.

6) Wonderful community support
Community is the biggest strength of Java programming language and platform. No matter, How good a language is, it wouldn't survive, if there is no community to support, help and share there knowledge. Java has been very lucky, it has lots of active forums, Stackoverflow, open source organizations and several Java user group to help everything. There is community to help beginners, advanced and even expert Java programmers. Java actually promotes taking and giving back to community habit. Lots of programmers, who use open source, contribute as commiter, tester etc. Expert programmer provides advice FREE at various Java forums and stackoverflow. This is simply amazing and gives lot of confidence to a newbie in Java.

7) Java is FREE
People like FREE things, Don't you? So if a programmer want to learn a programming language, or a organization wants to use a technology, COST is an important factor. Since Java is free from start, i.e. you don't need to pay anything to create Java application. This FREE thing also helped Java to become popular among individual programmers, and among large organizations. Availability of Java programmers is another big think, which makes organization to choose Java for there strategic development.

8) Excellent documentation support - Javadocs
When I first saw Javadoc, I was amazed. It's great piece of documentation, which tells lot of things about Java API. I think without Javadoc documentation, Java wouldn't be as popular, and it's one of the main reason, Why I think Java is best programming language. Not every one has time and intention to look at code to learn what a method do or how to use a class. Javadoc made learning easy, and provide an excellent reference while coding in Java. With advent of IDE, you don't even need to look Javadoc explicitly in browser, but you can get all information in your IDE window itself.

9) Java is Platform Independent
In 1990s, this was the main reason of Java's popularity. Idea of platform independence is great, and Java's tag line "write once run anywhere" was enticing enough to attract lots of new development in Java. This is still one of the reason of Java being best programming language, most of Java applications are developed in Windows environment and run in UNIX platform.

10) Java is Everywhere
Yes, Java is everywhere, it's on desktop, it's on mobile, it's on card, almost everywhere and so is Java programmers. I think Java programmer out number any other programming language professional. Though I don't have any data to back this up, but it's based on experience. This huge availability of Java programmers, is another reason, why organization prefer to choose Java for new development than any other programming language.

Having said that, programming is very big field and if you look at C and UNIX, which is still surviving and even stronger enough to live another 20 years, Java also falls in same league. Though there are lot of talk about functional programming, Scala and other JVM languages, but they need to go a long way to match community, resources and popularity of Java. Also OOPS is one of the best programming paradigm, and as long as it will be there Java will remain solid.

What Can You Do With PHP Java & Javascript?

Back-end Server Applications

Back-end or server-side applications process data and instructions on a remote computer, then serve the results to the user who requested it. For example, when you type in search engine request, the actual work of searching the Web is performed by many different applications running on the search engine provider's computers. PHP powers server-side applications used by social networks, blogs and electronic learning systems. Banks and other financial institutions are big customers for server-side applications written in Java. While most JavaScript applications you will encounter only run in your Web browser, the creators of the language intended for it to be used for server-side applications as well. According to an "InfoWorld" website article, the use of JavaScript for back-end programing is seeing a resurgence. JavaScript's popularity, improvements in the third-party libraries and advances in interpreter runtime speed combine to make JavaScript a good choice for back-end processing.

Utilities

While flashy games and multimedia software get all the attention, simple, single-purpose utilities are often the applications that get real work done. The Java and PHP languages have native support for data file manipulation. This makes them useful as data filters, format converters, data encryption and and data decryption applications. Java's speed makes it a good choice for intense scientific and business data processing. JavaScript utilities can be found working behind the scenes to produce Web animations, validate Web forms input, create drop-down menus or the dreaded pop-ups.

Desktop Applications

Java, JavaScript and PHP can each be used to create stand alone desktop applications. Java allows programmers to write an application that can run on any computer hardware or operating system that have a verified Java virtual machine installed. The website "Java-Apps.org" lists Java text processing, multimedia, business, scientific and graphic desktop software. Though it is most frequently used as an interpreted scripting language, PHP can be used to create desktop applications by using the PHP-GTK extension. PHP-GTK is a collection of libraries and PHP language extensions which let programmers create graphical user interface or "GUI" applications that look and function like modern Windows, OS X or Linux desktop programs. Thanks to the new HTML5 - Hypertext Markup Language Version 5 - standard, improvements in interpreter speed and JavaScript frameworks such as Jquery, Node.js and Google's CommonJS, JavaScript can power application that run in the browser without the need for a live Internet connection. For example, there are word processor, spreadsheet and presentation application suites available that can create, edit and store documents on your computer's hard drive while you are off-line.

Mobile Applications

JavaScript, Java and PHP are used to construct many of the games, utilities and productivity applications available for mobile devices like tablets, cellphones and smartphones. Java's portability allows it to be used for many of the games, media players, social media interfaces and other applications thatt run on many different cell phone brands and models. Finally, many popular online games and applications use PHP for server-side processing along with HTML5 and Javascript for visuals and user interaction. These applications are portable and can run on any mobile device or operating system that has a modern, JavaScript-enabled Web browser installed.