Java 2.0 Complete Tutorial

Java - The most demanded programing language. It is used inside your dvd player, mobile phone, internet and even inside your car. It is platform independent, that mean it work on all operating systems.

Java is well popular in mobile phones, especially in games. This Java tutorial will guide you to learn all features of Java and developing standard commercial applications.

This blog updates every week. Please post your comments about this site.

Use google search for better results

Google
 

Thursday, September 6, 2007

How to embed a java applet into a web page?

Lets now connect our hello applet (hello.class file) into a web page and run it. I hope you have a basic knowledge in HTML which is web page language. Use the notepad or your text editor to create this web page. Type these codes and save it to the same directory where hello.class file is as a .htm or .html file.



Now open the web page with any internet browser such as Internet Explorer. Bingo! You will see your applet running "Hello from Java!" displays on the web page.

You can also view your applet with java applet viewer. Go to the Command Prompt and type this command to open your applet in the applet viewer.

c:\java12\hello\appletviewer hello.htm

Next we will try to understand how exactly this applet works, line by line.

Wednesday, September 5, 2007

Installing the Java JDK and compile java applet

To compile the java hello example, we need to install a set of special java programs called java jdk (Java Development Kit). You can download the latest java jdk from java sun microsystems website at http://java.sun.com/products/jdk/1.2/ and install by running the setup file. Java jdk is a free to download and use.

When you installed the jdk we need to configure computer to to use the jdk features within any directory. To do this we need to add followig lines to systems Autoexec.bat file. Generally autoexec.bat file is found on the C:\ drive. Open it with the notepad and add this line then restart the computer to apply modifications.

PATH=C:\WINDOWS;C:\JDK12\BIN;C:\JDK12\LIB

here I have installed the java jdk to C:\JDK12 directory. Use whatever the path you installed the java jdk. Now you have successfully installed and configured java jdk. Now lets compile our hello example into a java applet.


Compiling the hello applet

Java applet is a 'class file', that mean java applet always have the file extention .class. Now we are going to compile out hello.java file into a hello.class file using java jdk.

Go to the command prompt and change to the directory where we saved our hello.java file. Here I saved my file to,

c:\java12\hello>

Now type this java command to compile the applet;

c:\java12\hello>javac hello.java

Java compiler will now create a java.class file and it is a ready to go java applet. You will see both hello.java and hello.class files in the folder.

Next we will learn how to embed this java applet to a html webpage and view it.

Tuesday, September 4, 2007

Creating the first Java Example

Lets create a simple java example. This is an java applet, and we called this applet "hello". This program displays the word "Hello from Java!" in a web page. You can use any text editor such as Notepad in windows to write source codes. Open your text editor and start typing following codes exactly as it is, keeping attention on letter case. Java programs are case sensitive.

Java source code for hello example.


import java.awt.Graphics;
public class hello extends java.applet.Applet
{
public void paint(Graphics g)
{
g.drawString("Hello from Java!", 60, 30);
}
}


now save this file as "hello.java", the extension of the file is .java, means this is a java source file and it can open from any text editor and DOS. If you usign notepad you can save by selecting file type as all files or save this as a text file and later rename in DOS prompt.

These pictures shows you how to do it in both ways.

java tutorial

Saving java file from notepad, attention to "save as type" selected All Files(*.*) and "File Name" is hello.java

java tutorial

From the DOS prompt change to the directory where your text file is saved and then type;

ren hello.txt hello.java

Yoour text file is now converted in to a java file. Next we will learn to install Java SDK and how to embed java applet into a web page.

Wednesday, July 25, 2007

Introduction to Java

Java programs come two ways: Stand-alone applications and small programs that can embed in web pages called Applets. Java applets are the most popular Java programs.

Tuesday, July 17, 2007

Welcome to Java Complete

Java is the ultimate language we all wants to learn. I am following a Java course and I would like to my knowledge with you. You can learn Java with me free and it is easy and fun. I will update this website with every class I attend, generally once a week. I will post all articles and examples here, you can post your comments and build example codes with me.

After all you will get all benefits of learning Java free.