-
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
-
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.
}
}
}
-
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
-
sorry, you may be confused.... I am denniswrenn,
this is my chit chat name, I just forgot to logout before posting....
-
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!
-
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");
}
}
-
If the name of your class is HelloWorld then to
compile it should be
c:\jdk1.3\bin>java -classpath c:\java; HelloWorld
-
thanks a lot! it works :D
-Dennis
-
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
-
java (meaning java.exe) doesn't like to see .class
javac (meaning javac.exe) likes to see .java