
-----------------------------------
Vertico
Fri Mar 25, 2005 1:00 pm

is Java a free? if so were can i get?
-----------------------------------
just wondering were it is. i have a java course coming up in school and would like 2 have a copy at home.

-----------------------------------
wtd
Fri Mar 25, 2005 2:50 pm


-----------------------------------
Yes it's free.  http://java.sun.com

-----------------------------------
Vertico
Thu Apr 21, 2005 2:22 pm


-----------------------------------
okay. i would like to know what i would downloaded for someone who wants to begin/start Java. i went to the website and found alot of different things.

-----------------------------------
rizzix
Thu Apr 21, 2005 2:28 pm


-----------------------------------
http://java.sun.com/j2se/1.5.0/download.jsp

if ur interested in programming.. always download the JDK...

-----------------------------------
Vertico
Thu Apr 21, 2005 4:18 pm


-----------------------------------
Okay I downloaded the file that u said,  "JDK". After doing so, iv come across most likly the most pathetic, pointless problem.

Dont know how to open it so i can actually put code in. The Java application at my school looks alot like the turing programing screen, not sure if that is what this is suppost to look like but since there is no shortcut on my desktop or a icon in my start up window im having truble finding the program were you type in code.

i can find the java file folder and everything that was installed, but i dont know what im looking for.


P.S. im a 100% noob when it comes to Java.

-----------------------------------
wtd
Thu Apr 21, 2005 4:26 pm


-----------------------------------
Java source code is just a plain text file that happens to end in ".java".  Really.  Other than that there's nothing special about it.  So, type up a simple "hello world":

import java.io.*;
import java.lang.*;

class HelloWorld
{
   public static void main(String[] args)
   {
      System.out.println("Hello world");
   }
}

Save it as "HelloWorld.java".  Open a command prompt (Start -> Accessories).  "cd" to the directory where you saved HelloWorld.java.  Compile and run like so:

prompt> javac HelloWorld.java

prompt> java HelloWorld

-----------------------------------
Vertico
Thu Apr 21, 2005 7:57 pm


-----------------------------------
alright so this is what i got out of what you said :

i can make a file anywhere like notepad as long as i save it with a .java extension?

then i open up the Command Promt 

thats all i got out of what u said. I dont know what you mean by compile and then what im suppost to do in the Command Prompt window.

remember im brand spanking new to Java and am just tryig to understand how to run programs and were 2 wright them.

-----------------------------------
wtd
Thu Apr 21, 2005 8:12 pm


-----------------------------------
Yes, you can use any plain text editor.  Keep in mind that word-processing programs typically add code you can't see for formatting, and thus are unacceptable.  Make sure the extension is ".java".  Some text edtors will automatically add ".txt", so you could end up with something like "HelloWorld.java.txt".

Compilation takes source code, which is the stuff that can be read by a human, and turns it into machine code.  In this case we take Java source code and compile it into code that's executable by the Java Virtual Machine.  We do this with the "javac" program.

We can then tell the Java Virtual Machine to run the code.  This is done with the "java" program.

-----------------------------------
Vertico
Fri Apr 22, 2005 2:19 pm


-----------------------------------
can i get a step by step? i have a file called HelloWorld.java. what do i do after that? dont know how to work command prompt very good.

-----------------------------------
rizzix
Fri Apr 22, 2005 2:27 pm


-----------------------------------
cd to_directory_with_file_HelloWorld.java
javac HelloWorld.java
java HelloWorld

-----------------------------------
Vertico
Fri Apr 22, 2005 2:45 pm


-----------------------------------
cd to_directory_with_file_HelloWorld.java

this is the part i still dont understand. how do i "cd" to directory?

-----------------------------------
wtd
Fri Apr 22, 2005 3:23 pm


-----------------------------------
cd to_directory_with_file_HelloWorld.java

this is the part i still dont understand. how do i "cd" to directory?

"cd" is the command to "change directory".  In a filesystem, files are organized into directories (or in the GUI age, "folders").  In the command prompt, you are only ever in one directory at a time.  This is typically indicated in the prompt itself.

Of course, directories can themselves contain directories.  And in Windows, there can be numerous filesystems, each with their own root.  For the C drive, this root looks like:

C:\

For D:

D:\

I'm sure you see the pattern.

A directory at the top level of the C drive named "Foo" looks like:

C:\Foo\

A "Bar" directory inside that one looks like:

C:\Foo\Bar\

See the pattern?

Now, to cd into the "Baz" directory in the "Foo" directory from "C:\Foo\Bar" I must first move up one level:

C:\Foo\Bar\> cd ..

Then, I need to change into the "Baz" directory:

C:\Foo\> cd Baz

Of course, this could have been shortened to:

C:\Foo\Bar\> cd ..\Baz

-----------------------------------
Vertico
Fri Apr 22, 2005 4:31 pm


-----------------------------------
okay i found out why i was having so much trouble with the changing directory. For some reason it wont change to my D drive where i use to have all the Java stuff. i moved it to my C drive and it now will change. Also i ran the helloworld file and im pretty sure it worked since it is only suppost to say hello world and thats what it said.



but then i tryed to run a demo that came with it (TicTacToe) and repeated the same actions i took for the helloworld file and changed my directory to it. then comacted with javac and then when i did the java TicTacToe all it said was TicTacToe and didnt actauly do anything else.

did i do something wrong? or is that all its suppost to do/say?

-----------------------------------
wtd
Fri Apr 22, 2005 5:45 pm


-----------------------------------
To change to a different drive (C, D, etc.):

C:\Yada\Yada\Yada\> D:

-----------------------------------
Vertico
Fri Apr 22, 2005 9:42 pm


-----------------------------------
alright so lets see if i can understand this.


so i changed the directory to :

 C:\Program FIles\Java

and the file called Helloworld.java is saved in the file Java. then i type

prompt> javac Helloworld.java
then
prompt>java Helloworld

is this right??

after that it should show me what is suppost to be printed off right?
in the command prompt screen or in a new window?

well when i do all that all it does is writes Helloworld in the command prompt screen. Even if the msg inside the code is "happy happy".

What am i doing wrong and what should i be doing?

-----------------------------------
wtd
Fri Apr 22, 2005 9:57 pm


-----------------------------------
Yes, anything printed with System.out goes to the standard output, which is the terminal window, by default.

Can you please show me the exact program you're compiling?

-----------------------------------
Vertico
Fri Apr 22, 2005 10:21 pm


-----------------------------------

import java.io.*; 
import java.lang.*; 

class HelloWorld
{ 
   public static void main(String[] args) 
   { 
      System.out.println("what is up people"); 
   } 
}




its the exact program u wrote out before. except i changed the print

-----------------------------------
wtd
Fri Apr 22, 2005 10:34 pm


-----------------------------------
After you made a change to the program, did you recompile it, or just run it again?

When you make a change to a Java program you must recompile it.  You see, the source code lives in (in this case) HelloWorld.java.  But when we compile with:

javac HelloWorld.java

The program is converted to a format the Java virtual machine can use, and this is placed in the file HelloWorld.class.  It's this file which:

java HelloWorld

Is concerned with.  If you don't recompile, that file is unchanged, and any changes to HelloWorld.java won't be seen in the results.

-----------------------------------
Vertico
Sat Apr 23, 2005 8:14 am


-----------------------------------
do u know of a website that can help me through this? like the most slowest newbiest yet effective site to help me learn how to run files?

cuz i keep trying what ur saying and i keep getting nothing back but what i type.

-----------------------------------
Hikaru79
Sun Apr 24, 2005 1:45 pm


-----------------------------------
Also, you don't need either of the import statements you used at the top. You don't need java.io.* because you're not using it anywhere in your program, and you don't need java.lang.* because its imported by default -- you don't need to worry about that.

-----------------------------------
wtd
Sun Apr 24, 2005 4:12 pm


-----------------------------------
Also, you don't need either of the import statements you used at the top. You don't need java.io.* because you're not using it anywhere in your program

It never hurts to have either of these import statements.

-----------------------------------
1of42
Sun Apr 24, 2005 9:33 pm


-----------------------------------
But isn't it extraneous and unnecessary?

-----------------------------------
rizzix
Sun Apr 24, 2005 9:48 pm


-----------------------------------
one can argue.. it self-documents the code.. so yea... well refering to the java.lang package i.e.. the java.io is unnecessary.

-----------------------------------
Hikaru79
Wed Apr 27, 2005 12:00 am


-----------------------------------
Also, you don't need either of the import statements you used at the top. You don't need java.io.* because you're not using it anywhere in your program

It never hurts to have either of these import statements.

Really? It doesn't hurt to import packages you don't use at all? All this time I've been doing stuff like import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
if those would be the only classes I was using in a particular class. I figured I was getting at least a tiny bit of a boost here for only importing exactly what I needed as opposed to import java.io.*;. Have I been misinformed this whole time? Or is there some sort of benefit to my stinginess, however small it may be? Or is the compiler smart enough only to load the bare neccesities?

-----------------------------------
rizzix
Wed Apr 27, 2005 12:16 am


-----------------------------------
no this is a compile time issue.. not a runtime issue.. the compiler will optimise ur code importing only what you need.. actually imports are all syntatic sugar.. the bytecode uses the full form internally. 

but yea.. ur stingyness can reduce compile time.. but not necessarily improve runtime speed... on the other hand it can be seen as self-documentation ;)

-----------------------------------
Hikaru79
Wed Apr 27, 2005 12:40 am


-----------------------------------
no this is a compile time issue.. not a runtime issue.. the compiler will optimise ur code importing only what you need.. actually imports are all syntatic sugar.. the bytecode uses the full form internally. 

but yea.. ur stingyness can reduce compile time.. but not necessarily improve runtime speed... on the other hand it can be seen as self-documentation ;)
*phew* At least I have *some* justification  :lol: Thanks, rizzix! ;)

-----------------------------------
rizzix
Wed Apr 27, 2005 2:13 pm


-----------------------------------
yes but there is no point in trying to import stuff you dont use.. its very bad practise... dont do it.

-----------------------------------
wtd
Wed Apr 27, 2005 3:53 pm


-----------------------------------
Don't micro-optimize.  If you want several classes from "java.io", import "java.io.*".  You could spend lots of valuable time individually importing each class you use, but at the end you'd have done nothing the compiler/VM couldn't do in a fraction of a second.

-----------------------------------
rizzix
Wed Apr 27, 2005 4:08 pm


-----------------------------------
depends... if you are using a tool like eclipse... they can automaticaly organise and fold ur import statements.. and by organising i mean expanding it completly and grouping/sorting them in a perticular order..

it actually makes, looking up classes used in that class or file, a breeze.. and bsides cuz of the folding, it dosen't really come in way your while coding..

as for the time "wasted" well, actually none of it is actually wasted.. its all done automatically.

-----------------------------------
wtd
Wed Apr 27, 2005 4:37 pm


-----------------------------------
Perhaps, but I mean, don't spend time typing out each class name you're importing if a "import javax.swing.*;" or such will do the trick.

-----------------------------------
Hikaru79
Wed Apr 27, 2005 5:43 pm


-----------------------------------
Perhaps, but I mean, don't spend time typing out each class name you're importing if a "import javax.swing.*;" or such will do the trick.
Aaah... yet another case of me wasting two minutes of coding time to save two milliseconds of compiling time  :? I gotta stop doing that.
