I want to use a java class I created - where to put file / code?

A

Angus

Hello

I have created a java class which I want to use from another java program.

Do I need to store the java file in a particular location? (bit like C/C++
include files?).

I tried just pasting class to bottom of file with main java program I was
using but that didn't work. Can I just have class in same file? But how?

Any help would be much appreciated.

Angus
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Angus said:
I have created a java class which I want to use from another java program.

Do I need to store the java file in a particular location? (bit like C/C++
include files?).

I tried just pasting class to bottom of file with main java program I was
using but that didn't work. Can I just have class in same file? But how?

Any help would be much appreciated.

You can only have one public class per source file.

I think what you are looking for is "classpath".

Simple example:

javac -classpath .;C:\utilities Foobar.java
java -classpath .;C:\utilities Foobar

will be able to use a class mystuff.SmartUtility
in C:\utilities\mystuff\SmartUtility.class

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top