Sign in to follow this  
The C modest god

[java] Working with java

Recommended Posts

I have installed Java 1.4.1 SDK, now I want to work with it(I use windowsXP) From the command prompt when I write java -version I can see the version is really 1.4.1. However, I want to compile a program using javac. I saw that where the java SDK was installed, inside a bin library, there is that javac.exe file. So if I want to compile a java program with javac in the command prompet, I should simply add a path somewhere in windows to the bin library in the SDK? How do I add that path? Or should I do something else? Also, I was recommended to work with JBuilder and eclipse, but for now I want to work using command prompt. I would appreaciate if you help me with this. Thanks in advance.

Share this post


Link to post
Share on other sites
scgrn    168
Yeah, you need to the add the location of your SDK to your path. Go to control panel -> system -> advanced tab. Click on the "environment variables" button, you can add it to your path there.

Share this post


Link to post
Share on other sites
Ok, I was able to append the path, compile and run the helloworld application.
Now I have installed eclipse and I try to somehow run the helloworld application in it.
I have created a project, but I am unable to add the already existing file helloworld.java, I can only create new files.
How do I add the homworld.java file into the project? and how do I compile/run the project in eclipse?
The help is a bit confusing.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
Original post by The C modest god
I have installed Java 1.4.1 SDK, now I want to work with it(I use windowsXP)


Stop, stop, stop, why are you using 1.4.1? Use 1.5.0 the latest release, it's much better.

BTW if you REALLY have the need of using 1.4.X, it can't be any other, use 1.4.2 the latest release because it's going to have fixes to some security bugs.

Share this post


Link to post
Share on other sites
I have another question, I can have only one public class in a .java file, right?
So how do I make a public class in one file, to use a public class in another file.
Simply using it doesn't work, because he says he can't find the class. So there is something additional I need to do.
I am working with JBuilder now.
So I have two .java files in my project, one of them uses the public class in the other file.
Also, how do I compile and run these two .java files using javac from MSDOS?

Thanks in advance.

Share this post


Link to post
Share on other sites
Kevinator    229
In DOS:

one way is to have java use the 'default' package, which is simplest. Put all your files in the same directory, run <javac.exe path> *.java while in the directory, then to run, just type <java.exe path> <name of the class with main method>.

If you want to separate your files into packages, your directory structure must match your package structure and you need to put a package statement in your source files, and you need to use the import statement to import your classes.

Share this post


Link to post
Share on other sites
CaptainJester    523
As someone has already provided you a link to, everything is explained in "The Java Tutorial" I highly recommend that you do the entire thing before continuing. It is the best place to learn all the basic and intermediate Java concepts/API.

There is a link in my signature to The Java Tutorial.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this