First off, create a desktop shortcut to make it easy to start a DOS box in your Java working directory. On our Windows XP laptop, we copied the "Command Prompt" shortcut from <start><All Programs><Accessories> to the desktop. Right click on the DOS prompt icon and you should see "Target: %SystemRoot%\system32\cmd.exe". Change the "Start in:" field to your working Java directory. In our case "C:\Documents and Settings\Sucio\Desktop\Java".
On Windows 7, the Target would be "%windir%\system32\cmd.exe" and we'd probably start in "%HOMEDRIVE%%HOMEPATH%\Java" which comes out as "C:\Users\Sucio\Java".
(I changed the name of my shortcut to "JAVA Prompt.)
So, I'm sure you're itching to try something so let's get started. Here's the text of our simple "Hello World" program.
class HelloWorldApp { public static void main(String[] args) { System.out.println("Viva Sucio!"); } }There's a very good description of what every word of this program is doing at <Jimmy Wales' blog>. For now, we'll just say that the program defines a class of objects called HelloWorldApp and tells Java what the object can do (its methods - in this case, just the method main).
Copy and paste the simple program into a new file "HelloWorldApp.java" in your working directory. (Note, a java program must have a file name ending with ".java"; and the name must match that of the class defined by the program - in our case "HelloWorldApp".)
Once you've saved the program, at the command prompt, type
javac HelloWorldApp.java
and press enter. If you haven't screwed up, there'll be a slight pause and then you'll get a new prompt as though nothing's happened. But, if you list the directory contents, you'll find that there's now a new file called "HelloWorldApp.class". (If the PC complains that it can't find javac, it's because you didn't set the PATH environment variable properly. Follow the link in yesterday's post to find instructions.)
So what happened here? The Java compiler ("javac") compiled (translated) the Java class definition in our program source file into bytecode. Bytecode is a special kind of machine instruction which can be run (interpreted) by something called the Java Virtual Machine (JVM). the bytecode program is stored in a ".class" file.
Rather than waffling let's have a go: type
java HelloWorldApp
and press enter. Your "Hello World" message (in our case "Viva Sucio!") should appear on the screen, followed by a new prompt.
The JVM ("java") loaded the bytecode in "HelloWorldApp.class" and started running the program at the "main" entry point. The "main" method told the JVM to print the line of text "Viva Sucio!" to the system output stream.
Hopefully some the the jargon in our last post is getting clearer now. We downloaded the Java Runtime Environment (JRE) which contained the Java Virtual Machine (JVM - "java"). We also downloaded the Java Development Kit (JDK) which contained the Java compiler ("javac").
Play around a bit changing the message string in the program.
,/, ,.%((.))) |.
'///_, (///)\\))) , |||/
\ ,' (([]-[]-\\\) y-";,-"
| | )| - @))) | |
| \ ((\___,"(( / |
| `---.__))| |())___.---' |
`-._ "-_ _ -" _,-"
"-.__," ".__.-"
( @ / \ @ )
`---' `---'
| |
| . |
/ \
/ "-.-" \
/ /^\ \
/ / \ \
/ / \ \
( ." ". \
\ ) \ \
\ ". `. \
". \ \ \
`. `) \ ".
\ ( \ \
.mno/ | \
Oonm'
"Sarah Palin nude" - That should get the google hits up.(Based on an image by hjw at the ASCII pôrn archive.)
I would avoid a nude Sarah Palin like the plague.
ReplyDeleteYikes, Sarah Palin nude..... hello world!
ReplyDeleteSarah Palin seems like a nice lady on the news:D
ReplyDeleteI can't tell whether her arms are droopy/flabby or muscular. Either way... I need to go throw up now.
ReplyDeletenice post
ReplyDelete$upporting
Damnit!: http://i.imgur.com/Xve9q.jpg
ReplyDelete@ Rorschach Redemption - "Main.Java"? Should be called "HelloWorldApp.java". The filename has to match the public class. ("main" is a method of class HelloWorldApp.)
ReplyDeleteConfusing and frustrating I know.
Great stuff :)
ReplyDeleteShe looks better here! good work
ReplyDeleteI actually managed to delete my Java final....You know those buttons on the side of some mice that go front a page/back a page?.....You should be real careful not to click those when you've already gone 2 hours over the time limit on a final.
ReplyDeletehttp://robertfunf.blogspot.com/
Ooooooooooooooooooooh.
ReplyDeleteI thought I could get away with changing names to protect...nothing.
Public class? NO SUCH THING!
Brb.
Yeah and those are what her b**bs look like? sure Sarah...
ReplyDelete"Sarah Palin nude" - oh the horror!
ReplyDelete@ Rorschach Redemption - it's pretty lame that the compiler doesn't give a more meaningful message for an error that 99.9% of noobs will make (myself included).
ReplyDeleteReminds me of my first Pascal compilation in Unix. I got the error message "bad magic number". It took 3 or 4 hours of reading man pages to work out that I'd left the ".p" off the end of the program file name.
Are they real?
ReplyDelete@ Marlene - I think she's had space implants.
ReplyDeleteEven though that's suppose to be a Sarah Palin, it's kind of neat looking.
ReplyDeleteWhy is Sarah Palin holding up her middle fingers? I find that obscene.
ReplyDeleteYou sure it's not Tina Fey?
ReplyDeletesomething something something something Sarah Palin nude. haha
ReplyDeleteAh, needed some more palin porn.
ReplyDeleteAlso, I should get into java. I hear it's good for games devs to know.
You know, that art perfectly portrayed her substance.
ReplyDeletelol @ sarah palin nude
ReplyDelete