|
||||||||||||||||
. . . . . |
Java - Using the MS_DOS Prompt
| Intro |
Begin |
if/else |
Loops |
Arrays |
Graphics |
Animation |
Mouse |
Game |
Real |
Methods |
Class |
Class 2 |
Applet |
MouseClick |
Thread |
Button |
Now we are going to start using Real Java. JUDO uses it but it is like an interface between us and Java. Firstly find out where your Java is situated on your hard drive. Do a search for "javac.exe". Find the directory path for it. Write it down. Mine is "E:\jdk\bin\". Open your Text Editor(NotePad, Crimson Editor) and write your first real java program. It has to be hello world of course. Write this in your text editor:
public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}
Save it as Hello.java in a directory such as "d:\javatute\".
Open up your Dos prompt. Go to Start- Programs - MSDOS Prompt . You will get
a black window with a prompt that says somethin like c:\windows>
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com Compiling your Java Program
When you get to your directory , your command prompt will look like:
What have you just done? You have compiled and run your first java program all by yourself.
javac is the command that compiles your text file Hello.java into machine code that the computer
can understand. Computers cant understand English , they only understand 0's and 1's. They are
very dumb. A compiler allows us to write Java code and it will compile it for us into
a language that the computer will understand. Imagine how hard it would be typing in 0's and 1's!
It would drive you round the twist! It might look something like this. Run your Java ProgramSick of that yet? Once your java program is compiled , you need to RUN it. java is the command that runs your program. All you need to do to run a command-line program is type in "java" followed by the program name. In this case "Hello"
You now know how to compile and run a java program.
Lets analyse our code for "Hello.java". You already know heaps of java from our earlier tutorials using JUDO. The syntax is the same for variables such as int, double , String. We will be using arrays, conditional loops such as while, for. And in the lessons on Graphics we have laid the foundations of work that we will do later on animation and games. You already know heaps of java if you have done the previous lessons on JUDO. You will just be accessing it directly instead of through an interface or GUI. Here is a program from Lesson 4 dealing with loops. Lets reuse it as a Java program. Write this in your text editor:
public class Counter
{
public static void main(String[] args) {
// declare our variable
int count = 0;
// loop 8 times
while( count < 8 )
{
System.out.println("Count is equal to " count);
}
}
}
Save it as "Counter.java". Compile it using the command " [mydirectory]\javac Counter.java"Where [mydirectory] is where javac is. If there are no errors , run the program using the command "[directory]\java Counter" . What did you get? should be the same as lesson 4.
Java Exercise |
|
||||||||||||||
|
| Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Forum | Games | free backgrounds | Resume | Flash Animations | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | store | advertisers | . . |
||||||||||||||||