| | |
New to Java, can't get program to compile
![]() |
•
•
Join Date: Apr 2004
Posts: 573
Reputation:
Solved Threads: 5
Hello everyone,
I just started learning Java, I like it so far because it is very similar to c#, which I am familar with. But I can't get programs to compile for me. It gives me an error saying 'Exception in thread "main" ' I am using NetBeans to compile the program.
Any suggestions would be great.
Thanks in advance.
I just started learning Java, I like it so far because it is very similar to c#, which I am familar with. But I can't get programs to compile for me. It gives me an error saying 'Exception in thread "main" ' I am using NetBeans to compile the program.
Any suggestions would be great.
Thanks in advance.
A public class needs to have the same name as the java file it's contained in.
A class must also be public in order to be able to run as a program AND have a main method with the correct signature.
A class must also be public in order to be able to run as a program AND have a main method with the correct signature.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Aug 2004
Posts: 8
Reputation:
Solved Threads: 0
copy this following code sample
class Test
{
public static void main(String arg[])
{
System.out.println("Hello From the Java World");
}
}
//////// Save this file as Test.java
now start cmd prompt and ur current dir must be the bin of jdk
use this command
javac Test.java
run the application using
java Test
Note Java is case sensitive. in every terms.
class Test
{
public static void main(String arg[])
{
System.out.println("Hello From the Java World");
}
}
//////// Save this file as Test.java
now start cmd prompt and ur current dir must be the bin of jdk
use this command
javac Test.java
run the application using
java Test
Note Java is case sensitive. in every terms.
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
Solved Threads: 0
If you are new to java, netbeans will only hold you back. Try using a less advanced, lessdecorated, and less stiff IDE like JCreator or eclipse, so you have control over the language instead of the IDE. Just my opinion but it is what i was told when i first started programming and i'm sure many experienced programmers agree that the bells and whistles make learning java alot more complex than it needs to be.
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
•
•
•
•
Originally Posted by twocentwhoracle
If you are new to java, netbeans will only hold you back. Try using a less advanced, lessdecorated, and less stiff IDE like JCreator or eclipse, so you have control over the language instead of the IDE. Just my opinion but it is what i was told when i first started programming and i'm sure many experienced programmers agree that the bells and whistles make learning java alot more complex than it needs to be.
I agree, but a new java programmer should start out with the command line and text editor. I feel that is an important learning experience, altough in the beginning it really sucks.
•
•
Join Date: Apr 2004
Posts: 573
Reputation:
Solved Threads: 5
Well, I was using sciTE editor, which is pretty nice to have. Java looks pretty much like c#, and I already know that pretty well. Netbeans really doesn't help me at all, it's auto-complete thing is crap (it takes forever to load). I tried to compile my program using the command prompt but I dont think I did it right, so it didn't work. Is there any special command prompt thing I need to do in order to use the command line compiler?
Thanks
Thanks
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
You have to set your environment variables:
Considering you have windows:
Goto start--->right click on my computer--->select properties
Goto the advanced tab, and you should see a button at the bottom that says environment variables...click on that.
The only thing you need to worry about is the PATH variable, and the CLASSPATH variable, nothing else.
SKIP THIS STEP AND GO ON TO THE CLASSPATH, IF IT DOESN'T WORK AFTER SETTING THE CLASSPATH, THEN COME BACK AND SET THIS.
The path variable must point to the bin folder in the sun app server, and the bin folder in the jdk directory. Now, those are two different directories, so you seperate them with a semicolon when creating it. Here is what mine looks like:
C:\Sun\AppServer\bin;C:\Program Files\Java\jdk1.5.0\bin
Classpath....This points to the tools.jar file in the jdk directory. It's pretty easy to find. Here is what mine looks like:
.;%classpath%.;C\Program Files\Java\jdk1.5.0\lib\tools.jar
Your's will look similar, although you do not need the .;%classpath%.; statement.
Next, you need to know how to access your files at the command line.
To do so, you simply type cd/folderName at the command line. The cd stands for current directory. My folder was named javawork, so to access it, I did this at the command prompt:
cd/javawork // brings me to the right directory
javac Hello.java //compiles my program
java Hello //runs my program
Let me know if you don't undestand something or need more help.
Considering you have windows:
Goto start--->right click on my computer--->select properties
Goto the advanced tab, and you should see a button at the bottom that says environment variables...click on that.
The only thing you need to worry about is the PATH variable, and the CLASSPATH variable, nothing else.
SKIP THIS STEP AND GO ON TO THE CLASSPATH, IF IT DOESN'T WORK AFTER SETTING THE CLASSPATH, THEN COME BACK AND SET THIS.
The path variable must point to the bin folder in the sun app server, and the bin folder in the jdk directory. Now, those are two different directories, so you seperate them with a semicolon when creating it. Here is what mine looks like:
C:\Sun\AppServer\bin;C:\Program Files\Java\jdk1.5.0\bin
Classpath....This points to the tools.jar file in the jdk directory. It's pretty easy to find. Here is what mine looks like:
.;%classpath%.;C\Program Files\Java\jdk1.5.0\lib\tools.jar
Your's will look similar, although you do not need the .;%classpath%.; statement.
Next, you need to know how to access your files at the command line.
To do so, you simply type cd/folderName at the command line. The cd stands for current directory. My folder was named javawork, so to access it, I did this at the command prompt:
cd/javawork // brings me to the right directory
javac Hello.java //compiles my program
java Hello //runs my program
Let me know if you don't undestand something or need more help.
![]() |
Similar Threads
- What's the HARDEST program you've written? (Computer Science)
- Can't get program to compile (C++)
- Help with Java program writing (Java)
- Java Problem with running program (Java)
- a Java GUI based program using Swing classes, Vat (Java)
Other Threads in the Java Forum
- Previous Thread: help with calednars and photo gallerys
- Next Thread: A Java Question??
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking bidirectional binary binarytree birt bluetooth chat chatprogramusingobjects class client code columns component database derby design eclipse encryption error errors expand fractal game givemetehcodez graphics gui guidancer homework html ide if_statement image inheritance integer intellij interface j2me java javadesktopapplications javaprojects jlabel jme jni jpanel jtextfield julia linux list map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source problem program programming project property recursion reference ria scanner search server set sms sort sourcelabs splash sql sqlite static stop string support swing testautomation threads tree ui unicode validation windows






