|
-
Nov 26th, 2000, 04:54 PM
#1
Thread Starter
Member
I have no clue what I am doing...
I just downloaded JDK 2 1.3
and I tried writing a java program
Code:
main()
{
print "hello";
return 0;
}
I named it with a java extension.
then I did this in an MS DOS console
Code:
C:\WINDOWS>cd ..
C:\>cd jdk1.3
C:\JDK1.3>java c:\java\test.java
c:\java\test.java is the full path to my java file...
it gives me an error, I can post the error if you want...
Thanks
-
Nov 26th, 2000, 05:34 PM
#2
Dazed Member
This will print out Hello World! ten times on the screen.
If you compile your program you will get erors.
To compile type in cd C:\jdk1.3\bin this will get you to
where the compiler and interpeter is located
then javac C:\java\test.java.
To run your program java -classpath C:\java; test
/***
* The HelloWorld class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorld {
public static void main(String[] args) {
for (int i = 0; i <= 10; i++){
System.out.println("Hello World!"); //Display the string.
}
}
}
-
Nov 26th, 2000, 05:42 PM
#3
the code you gave me "compiled" fine, but it doesn't work when I try to execute it..
I type
Code:
c:\jdk1.3\bin>java c:\java\helloworld.class
-
Nov 26th, 2000, 05:45 PM
#4
Thread Starter
Member
sorry, you may be confused.... I am denniswrenn,
this is my chit chat name, I just forgot to logout before posting....
-
Nov 27th, 2000, 12:40 AM
#5
Benjamin
Try Dilenger4's instructions. An executable class must take most of that format.
public class WatchMyCamelCase{
public static void main(String[] args){
Required signature--only variants are VarName and location of brackets (String anyName[])
main does not return anything, hence "void".
denniswrenn
Drop the .class
Try
c:\jdk1.3\bin>java c:\java\helloworld
or more likely
c:\jdk1.3\bin>java c:\java\HelloWorld
All
Watch the CamelCase for HelloWorld!
-
Nov 27th, 2000, 10:57 AM
#6
I removed the return,
and I tried what you said
c:\jdk1.3\bin>java c:\java\HelloWorld
and it said:
Exception in thread "main" java.lang.NoClassDefFoundError: c:\java\HelloWorld
and this is my exact code
Code:
class helloworld{
public static void main(String[] args)
{
System.out.println("hello");
}
}
-
Nov 27th, 2000, 12:15 PM
#7
Dazed Member
If the name of your class is HelloWorld then to
compile it should be
c:\jdk1.3\bin>java -classpath c:\java; HelloWorld
-
Nov 27th, 2000, 01:28 PM
#8
thanks a lot! it works 
-Dennis
-
Nov 27th, 2000, 02:08 PM
#9
Hyperactive Member
The easiest way to run Class files is to add "C:\SDK1.3\bin" or wherever you installed it to the path variable in autoexec.bat, andthen you can run a class file located in (for example) "C:\Java\Class" this way:
Code:
C:\>cd C:\Java\Class
C:\Java\Class>java HelloWorld.class
and hey preto, it works!
This way, you can also compile files a lot easier, ie
Code:
C:\Java>javac HelloWorld.java
-
Nov 27th, 2000, 02:53 PM
#10
java (meaning java.exe) doesn't like to see .class
javac (meaning javac.exe) likes to see .java
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|