Exforsys

Online Training

Getting Started With Java Programming !!

This is a discussion on Getting Started With Java Programming !! within the Java Tutorials forums, part of the Articles and Tutorials category; This tutorial will introduce you to Java programming. You'll compile and run your very own Java application, using Sun'...


Go Back   Exforsys > Articles and Tutorials > Java Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-21-2006, 06:24 AM
Member
 
Join Date: Apr 2006
Posts: 30
insane is on a distinguished road
Getting Started With Java Programming !!

This tutorial will introduce you to Java programming. You'll compile and run your very own Java application, using Sun's Java Development Kit.

The Java programming language has, within only a few years, become a de facto industry standard for developing portable applications, and interactive dynamic content for web pages. It's extremely easy to pick up Java programming skills, and in this lesson, you'll learn how to write, compile, and run Java applications.

Downloading & Installing the JDK

Before you can develop Java applications, you'll need to download the Java Development Kit (JDK). You may prefer at a later time to use a third party IDE, such as Visual J++ or Borland JBuilder, but it is important to become familiar with the basics of Java first.
You should always use third party tools in combination with Sun's JDK, not exclusion, to ensure compatibility.

Installing the JDK

Sun offers many versions of its JDK, for different Java versions and platforms. You are advised to use the most recent JDK, to gain access to all of the functionality of the latest version of the Java platform. If you don't already have the JDK installed, then stop off at Sun's official Java site, http://java.sun.com/.

For an even quicker way to find the latest Java tools, visit the JDK download page, located at http://java.sun.com/jdk/index.html. The most current version at time of writing is the Java 2 SDK v1.3, which contains all the tools you will need for this tutorial.

The installation process is fairly straightforward, but you should consult the documentation if you encounter problems. You'll need to make sure that the JDK is installed correctly, and that the JDK tools are within your operating system's path, before proceeding.

In most cases, this involves setting environmental variables. As many first-time Java developers do not have experience in this, we'll show you how to set these, for the most popular Java development environment -- Windows. Macintosh, Unix, and other environments, have their own way of setting environmental variables (for more information consult your operating system documentation).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-21-2006, 06:27 AM
Member
 
Join Date: Apr 2006
Posts: 30
insane is on a distinguished road
Setting up environmental variables for JDK

Under Windows, you set environmental variables by modifying the autoexec.bat file, located in the root directory of your hard-drive. This batch file is executed on startup; modifications to this file will not take effect until you run it, or reboot.
Code:
Remember to reboot! I can't stress this enough. Many readers make the changes, forget to reboot, and wonder why JDK doesn't work properly.
Modifying autoexec.bat

You'll need to edit the autoexec.bat file with a simple text editor. Open it up, and add a path statement pointing to the /bin/ directory under your JDK installation directory.

Code:
Use a simple text editor, like notepad or the DOS command 'edit'.
For example, if I'd installed my JDK to c:\jdk1.3\, I'd want to point the path statement to c:\jdk1.3\bin\. However, you must also be careful not to overwrite existing path statements set for other software packages. To prevent this, use the following statement (modifying directory for your installation location)

set path=%path%;c:\jdk1.3\bin\

Next, you need to set the classpath to include the current directory. The classpath helps JDK locate Java software (class files) that are installed on your machine. Some versions of JDK don't require this, but some of the tools that ship with JDK do require it, so it's best to set this environmental variable up properly.

set classpath=%classpath%;.\

Code:
Sometimes, you may run out of environmental space, and see the message "Too many parameters" on boot up. If this happens, add the following line to config.sys (located in the root directory)
shell=c:\command.com /p /e:32000

That done, reboot and you'll be ready to start writing your first Java application.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-21-2006, 06:28 AM
Member
 
Join Date: Apr 2006
Posts: 30
insane is on a distinguished road
Writing your first Java application

Like any other language, Java programming starts with writing source code. Source code are instructions that will be followed by the computer. We can create source code using any standard text editor, such as 'notepad' on Windows, or 'vi' on Unix. All Java source code ends in a '.java' extension.

Our first application will be extremely simple - the obligatory "Hello World". If you've never heard of "Hello World" before, its a common programming exercise when learning a new language. This example will display the words "Hello World" when executed.

class myfirstjavaprog
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}

Code : myfirstjavaprog.java

You should type this code out, using your preferred text editor, and save it as 'myfirstjavaprog.java'. Place this file in a directory (for example, "c:\src\") of its own, not your Java installation directory. Its best to keep your tools and source code separate.
Quote:
Java compilers expect the filename to match the class name. Thus the class, myfirstjavaprog, must be saved as myfirstjavaprog.java. If you're using notepad, you'll need to rename if from myfirstjavaprog.java.txt back to myfirstjavaprog.java
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-21-2006, 06:29 AM
Member
 
Join Date: Apr 2006
Posts: 30
insane is on a distinguished road
Compiling your first Java application

While some languages are interpreted (such as PERL), others introduce an extra step, called compilation. Compilation takes source code (files ending in a .java extension), and converts it into byte-code. This byte-code is low level machine code, which is executed inside a Java Virtual Machine (JVM).

To compile Java code, we need to use the 'javac' tool. This ships as part of the JDK, so if you have it installed and in the current path, you can compile your application using the following command from any DOS prompt or Unix session :

javac myfirstjavaprog.java

This will produce a Java class file, called myfirstjavaprog.class. Once your program is in this form, its ready to run. Check to see that a class file has been created. If not, or you receive an error message, check for typographical errors in your source code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-21-2006, 06:30 AM
Member
 
Join Date: Apr 2006
Posts: 30
insane is on a distinguished road
[b]Running your first Java application[b]

Now the time has come, (said the Walrus). You're ready to run your first Java application. From a dos prompt or Unix session, enter the directory where your source code and class file is stored, and type the following :

java myfirstjavaprog
Quote:
You should not type java myfirstjavaprog.class. All Java classes end in this extension, it is not necessary, and will cause an error messages.
Your Java application will load, display its message, and then terminate. Congratulations!

Summary

Writing and developing Java applications and applets need not be a great mystery. Armed with the JDK and a text editor, virtually any programmer can write in Java. You've just taken the first step, in a long journey, towards learning Java.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-23-2006, 09:57 PM
Senior Member
 
Join Date: Jun 2004
Posts: 353
kalareddy is on a distinguished road
Thanks for posting nice tutorials... This really helping me with Java.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-24-2006, 05:57 AM
Member
 
Join Date: Apr 2006
Posts: 30
insane is on a distinguished road
Your Welcome kalareddy ..
Will Add more tutorials soon
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-26-2006, 03:19 PM
Junior Member
 
Join Date: Apr 2006
Posts: 21
falco85 is on a distinguished road
That's great stuff!

Making the "Hello World" program in a new language always make me feel so proud thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new questions
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
How to understand Java by looking at pretty colors ? insane Java Tutorials 1 03-15-2007 03:17 PM
FREE JAVA GUIDE- free Java, j2ee, sql and plsql tutorials hemanthjava Java Tutorials 0 04-01-2006 09:01 AM
applying job karthik.gokul@gmail.com Freshers Jobs 1 07-25-2005 09:24 AM
Enjoy 25% savings when you purchase a Java Technology Certification Exam Voucher sanereddy Certification News 0 06-01-2005 06:07 AM
Java requirements in Cognizant - Hyderabad techguru Experienced Job Seekers - India 0 05-31-2005 10:49 PM


All times are GMT -4. The time now is 03:38 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.