advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Making the Switch to Java :

Graeme Kerry is a first year computer systems engineering student from the UK, studying at Lancaster University. He has been programming in Java for about 3 years. Outside of studies he enjoys sports and socialising with friends. Kezz's Java Tutorials are written in Graeme's spare time.

Part 1 HelloWorld.java

Introduction

Welcome to the first of my introduction to Java tutorials. These tutorials are aimed at complete beginners to programming. Java is a good language to start with because its syntax is very similar to the more powerful c++ and it has been designed in a very object oriented way. Object oriented programming (or OOP for short) is a way of programming that breaks the problem down into parts. These parts then slot together to form the solution.

What You Will Need

To follow these tutorials all you need to get your hands on is the Java SDK (sometimes called the JDK). SDK stands for Software Development Kit. The Java SDK is available free!! from here . This kit contains all you need to program in java. To write your source files I recommend using a program such as notepad or Xemacs (under *NIX environments). These are just suggestions and any plain text editor can be used as long as it can save files in raw text format.

Main Parts of the Java SDK

The SDK contains many programs and is quite a hefty download. The main parts you will be using are detailed below.

    • javac.exe - This is the java compiler. It turns your source code into files that can be read by the java interpreter.
    • java.exe - This is the java interpreter. It reads through you compiled code line by line and executes the statements.
    • appletviewer.exe - This will be used later on in the tutorials when we get into applet programming. This tool displays an applet as it would appear on an html page. (An applet is a java program that can run in a web browser).

 

HelloWorld.java

Ok enough explanation, lets start coding! This is the most basic of programs and all programming tutorials and courses I've seen seem to start with it.

Fire up your text editor and enter the code listed below and save it as HelloWorld.java.

public class HelloWorld {

public static void main (String [] args) {

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

}

}

After saving this file open an ms-dos command box (Start->Run->command.com should do the trick, on newer versions of Windows try cmd.exe) or a *NIX terminal and change to the directory where you saved the source file. To compile a java source file we use javac, the java compiler. So to compile out HelloWorld.java program execute the following statement:  javac HelloWorld.java. If you copied the code exactly right as shown above the compiler won't say a thing and you'll just end up with a new command prompt. This is good!!! Now to run your program use the java interpreter (java.exe) by executing java HelloWorld. The computer now reads your file and should print "Hello World!!!" before leaving you at a fresh command prompt. Thats all there is to it. I realise this isn't very impressive but its essentially one line of code!.

Lets take a closer look at the source code.

public class HelloWorld {

This line of code defines a new java class called HelloWorld. A class is a java program. Note the capitalisation of the HelloWorld. To make this file compile it must be stored in a file called HelloWorld.java with exactly the same name (capitalisation etc). The { at the end signifies the start of a block of code in java and as you can see on the last line this block is ended with a }

public static void main (String [] args) {

This is the main part of the program. It is called the main method. This method is always the first thing that is executed in a java application so everything in here is very important. Once again a { must be used to start the main method block. This means that everything that follows between the { and } belongs to the main method.

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

This line is a call to the println method of the System.out class. Don't worry about the technicalities, just remember that to print something to the screen you use System.out.println("<what you want to print>"); The speechmarks indicate that you want to print a string of text. This means that java will print exactly what is in the speechmarks.

Rounding Off

Ok thats all for this time. I hope you've been able to follow it. The next tutorial will be on getting user input and probably types of variable but lets worry about that next time!! If in the meantime you have any problems you can contact me @ graeme.kerry@btinternet.com and I will try to answer your questions.

 

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Avaya DevConnect Center
 Service Component Architecture/Service Data Objects Solution Center
 Intel Go Parallel Portal
 Internet.com eBook Library
 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 53
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Metasploit 3.2 Offers More 'Evil Deeds'
'Thank You Apple. Seriously.'
The Buzz: BlackBerry App Store Seen Next
Is .NET on Linux Finally Ready?
Red Hat Takes on HPC Market, Microsoft
Python's New Release Bridges the Gap
No Flash Seen on iPhone Horizon
Apple Yields to Complaints Over iPhone NDA
Microsoft Shows Some Ankle With Visual Studio
Gentoo Linux Cancels Distribution

Use Explicit Conversion Functions to Avert Reckless Implicit Conversions
Polyglot Programming: Building Solutions by Composing Languages
Automated testing for .NET by Ben Hall
"Supply Chain" SOA with SKOS
Service Component Architecture in Real Life
C++Ox: The Dawning of a New Standard
Getting Started with Virtualization
Master Complex Builds with MSBuild
eCryptfs: Single-File Encryption in Linux
CCXML in Action: A CCXML Auto Attendant

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES