Java Programming - a Brief Introduction

Brandee Teer
For the next few weeks I will be using labs from my Java programming class to give some tutorials on java (Thanks to my awesome Java teacher). Java is one of my favorite languages and I will soon be undertaking an advanced Java class. Because of that, I thought this would give me a good refresher and help out everyone else who's looking to learn some Java. This series of tutorials will include some basic programs, nothing too advanced.

To get started: Before we can start programming in Java, there are some programs that you will need to download and set up on your local machine. Java is written in an editor and saved as a .java file. It is then run through a compiler and turned into a .class file, which is then run through the java virtual machine interpreter in order to actually run the program.

First step is to download the Java SE Developers Kit. This can be found here. I decided to download JDK 6 Update 20 with JavaFX SDK but you can choose the option that's best for you.

The next step is to set up java's path. This is optional but it does make it easier to run the programs once you write them. For Windows XP:

  1. Start -> Control Panel -> System -> Advanced
  2. Click on Environment Variables, under System Variables, find PATH, and click on it.
  3. In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
  4. Close the window.
For Windows Vista:
  1. Right click "My Computer" icon
  2. Choose "Properties" from context menu
  3. Click "Advanced" tab ("Advanced system settings" link in Vista)
  4. In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.

There are lots of other tutorials out there on how to set up java so check them out or look on Sun's Site.

Now that the path is set up, we are almost ready to write our first java program!

The last step is to download some type of editor. I use JEdit because it has nice format highlighting. You can find that here.

Now we are ready to write our first Java program but let's learn a little about how Java works before we write a program.

Rules:
Java is case sensitive - E is not the same as e in java so we need to make sure that we use capitals where necessary and lower case in the right places too.
All class names have to start with a capital - What's a class? Ok, we didnt talk about that yet, but when we do, it's important to remember that the name must start with a capital letter.
Every java program must have a main method - In order for the program to work it must meet certain rules and one of those includes that it must have a main method. We will look at methods soon.
All statements must end with a ; - Yes every statement must end with a ; in order for it to be valid.
File name must match class name - If you class is called Smiles then your file should be called Smiles.java.

And the last thing before getting started on writing a program is to remember that java has to be compiled before it can be run. We will write our first program in the next tutorial but here we will briefly learn how to compile and run it.

First: Write your program and save it (We will do this soon). Let's pretend the name is Smiles.java. Second: Compile your program. We do this by opening the cmd window. Click start than run then type cmd. Or in the search box of later versions of windows just type cmd. You will type the compile command exactly as its written here : javac Smiles.java. If you have any errors in your program, they will show up here, otherwise your program will compile.

Finally: Run your program. We do this in the cmd window still. Type: java Smiles. Your program should now run!

That's the end of this tutorial. In the next tutorial we will learn a little bit more about java and actually write our first program. See you then!

Published by Brandee Teer

I am currently working as a Web Develop and pursuing Bachelor's in Web Development. I also operate my own freelance web design business. I am working on fixing my past mistakes and becoming a person my child...  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.