What is the best way to start creating java programs?

Caporegime
Joined
12 Mar 2004
Posts
29,962
Location
England
Everytime I try to use an ide I get errors like "cannot resolve symbol" "package system not setup" or something like that and I'm only trying to compile the hello world app! When I try to compile a notepad file I always get "javac is not a recognised command" even though I have set the environmental variables, I don't want to have to keep typing in the directory everytime I want to compile something either.

So can someone please tell me how to create java applications without having to setup loads of complicated things? It's bad enough having to install the sdk without settings up classes or whatever they are called. With C++ I just downloaded the devc++ ide and I could just go "new"---->"file" and start coding and compiling straight away. Is there any program that will allow me to do this for java?
 
Last edited:
Eclipse might be a good way to start, or the Sun Netbeans IDE. Others exist such as JBuilder but a) they arnt free and b) JBuilder is terrible :p

if "javac" isnt working at the command line than your environment variables arn't set up correctly!
 
manic_man said:
Eclipse might be a good way to start, or the Sun Netbeans IDE. Others exist such as JBuilder but a) they arnt free and b) JBuilder is terrible :p

I get those errors I mentioned when I use eclipse. Why can't java just be like c++ where it just works without setting anything up? It seems like java is actually more complicated than c++.

Even my instructor can't figure out why it isn't working!
 
java is a bit more complicated than C++ in concept :) its running on a virtual machine within a "real" machine rather than just being directly compiled to base level machine specific code, your code is then interpreted on the fly by the JVM, so really things are a tad more difficult.

Once your sorted though it gets much easier than it seems when you first start.

I have to say, when i installed the latest Java SDK on my Vista system it just set up all my sys vars etc for me!

Heres a reasonabky good guide though if things still arnt working:

http://www.cs.ucsb.edu/~teliot/Path_and_Classpath.htm

Also ,try netbeans, a lot find it a bit more "user friendly" to begin with althugh eclipse is more powerful and far faster overall.
 
You can just compile programs using javac Classname.java then execute them using java Classname. You just have to make sure the right enviromental variables are setup correctly/classpath is correct. In linux if you install sunjava-sdk it automatically configures this for you (not sure about the windows installer).
 
We used this at uni in the first year:
http://drjava.org/
Nothing fancy. Just gets right to it. Things like Eclipse are great, but I remember when I tried to use it in the first year I spent ages trying to get it to work.
 
Ok I've compiled the file using javac finally, but not when I type java to try to run it, it fails spectaculary again.

crap-java.JPG
 
Show us your code :)

Edit: try java Test

Class names are always in capitals.


e.g.
Code:
C:\>java HelloWorld.class
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class

C:\>java HelloWorld
Hello World!
 
Ahh well you have to use the name of the class, test isn't the name.

It's the correct standard to use the name of the file as the name of the class

i.e.
HelloWorldApp.java
would contain a class called HelloWorldApp..

java HelloWorldApp
should do it
 
Last edited:
There must be something very wrong with your setup then :(
I just tried it as you had it...

test.java:
Code:
class HelloWorldApp {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}


Code:
C:\>javac test.java

C:\>java test
Exception in thread "main" java.lang.NoClassDefFoundError: test

C:\>java HelloWorldApp
Hello World!

C:\>
 
Compiling via the command line is not the best way to start creating Java programs :p

You really should install an IDE, such as NetBeans or Eclipse :)
 
Last edited:
NathanE said:
Compiling via the command line is not the best way to starting creating Java programs :p

You really should install an IDE, such as NetBeans or Eclipse :)

I said I already tried that and the errors I get with them, "cannot resolve symbol" and "package system not setup". I've been told though that I should start with the command line because it's good to know how to use it.

Una said:
Whats the error?


I already posted it.
 
Last edited:
Energize said:
I said I already tried that and the errors I get with them. I've been told though that I should start with the command line because it's good to know how to use it.

It is good to start with the command line and a syntax hightlight text editor such as VIM. No need to jump straight into an IDE when your learning the basics.
 
Try java -cp . Test from the same directory as your program. If that works you got a problem with your CLASSPATH enviromental variable, check that.
 
alex@xor:~$ java -cp . Test
Hello World.

Assuming you got a Test.class in the current directory.
 
Back
Top Bottom