java file

helloI have A java file with extension *.java how can I include it in the Java libraray to make use of it.it is about text input and output...
[170 byte] By [SMALLTALK73] at [2007-9-30 15:24:47]
# 1
You'll need to compile it to a class file and make sure it's visible in your classpath.
yawmark at 2007-7-5 22:30:23 > top of Java-index,Java Essentials,Java Programming...
# 2

[url=http://java.sun.com/docs/books/tutorial/]Sun's basic Java tutorial[/url]

[url=http://java.sun.com/learning/new2java/index.html]Sun's New To Java Center[/url]. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.

[url=http://javaalmanac.com]http://javaalmanac.com[/url]. A couple dozen code examples that supplement [url=http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance]The Java Developers Almanac[/url].

[url=http://www.jguru.com]jGuru[/url]. A general Java resource site. Includes FAQs, forums, courses, more.

[url=http://www.javaranch.com]JavaRanch[/url]. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.

Bruce Eckel's [url=http://mindview.net/Books/DownloadSites]Thinking in Java[/url] (Available online.)

Joshua Bloch's [url=http://www.amazon.co.uk/exec/obidos/Author=Bloch,%20Josh]Effective Java[/url]

Bert Bates and Kathy Sierra's [url=http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance]Head First Java[/url].

jverd at 2007-7-5 22:30:23 > top of Java-index,Java Essentials,Java Programming...
# 3

Java has a concept of namespaces, unlike Smalltalk (Although there are extensions that have this ability). Packages tend to be layed out according to their underlying organisation on the file-system.

I.E

package edu.utah.physics.jason;

public class MyClass

{

}

Needs to be layed out on the filesystem under the directory:

edu/utah/physics/jason/MyClass.java

You can then compile the class:

javac edu/utah/physics/jason/MyClass.java

Then you can include this directory structure in your CLASSPATH.

from .bash_profile:

export CLASS_PATH=$CLASS_PATH:/home/jason/myJavaClasses/

Whatever directory you set in your classpath has to be the root of the directory that contains your package structure, in this case myJavaClasses has a subdirectory named 'edu', which has a subdirectory named 'utah' and so on.

These directory structures can become a little large for a big project, and it's often nice to be able to distribute these files and use them in a more organised fashion. For this purpose there is 'jar' which is like a java version of tar for creating java archives.

jar cf MyClasses.jar edu

Will create a file called 'MyClasses.jar' that preserves the underlying filestructure of edu for easy distribution. You have to specifically name the jar file in your CLASSPATH if you want to use it.

export CLASSPATH=$CLASSPATH:/home/jason/myJavaClasses/MyClasses.jar

Jar files also have a META-INF directory that contains meta-data about the main class of the entire structure, and other information for distribution. When you're done with development, you can pack your entire source-tree into a single jar file, specify the main-class, and then just execute it using 'java -jar MyJavaExecutable.jar'

-Jason Thomas.

thedracle at 2007-7-5 22:30:23 > top of Java-index,Java Essentials,Java Programming...