<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.scott5.org/index.php?action=history&amp;feed=atom&amp;title=Java_Basics</id>
	<title>Java Basics - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.scott5.org/index.php?action=history&amp;feed=atom&amp;title=Java_Basics"/>
	<link rel="alternate" type="text/html" href="https://wiki.scott5.org/index.php?title=Java_Basics&amp;action=history"/>
	<updated>2026-04-13T03:26:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://wiki.scott5.org/index.php?title=Java_Basics&amp;diff=537&amp;oldid=prev</id>
		<title>Scott: /* The classpath */</title>
		<link rel="alternate" type="text/html" href="https://wiki.scott5.org/index.php?title=Java_Basics&amp;diff=537&amp;oldid=prev"/>
		<updated>2011-02-04T23:20:24Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;The classpath&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==File Structure==&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;MyClass&amp;lt;/code&amp;gt; should be defined in a file called &amp;lt;code&amp;gt;MyClass.java&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Compiling==&lt;br /&gt;
To compile a project, use the command line&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
javac MainClass.java&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where MainClass.java contains the main method. If MainClass.java refers to other classes (through import statement or by belonging to a package), the compiler searches for the appropriate class files on the CLASSPATH. If it finds no .class file, or if it finds a corresponding .java file that has been modified more recently than the .class file, it will compile the .java file. Thus, the compiler has the functionality of make built in.&lt;br /&gt;
&lt;br /&gt;
==Running==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
java MainClass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
will run the program.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
java -Xmx1000M MainClass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sets the maximum heap size to 1000MB. &amp;lt;span id=&amp;quot;line-24&amp;quot; class=&amp;quot;anchor&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span id=&amp;quot;line-25&amp;quot; class=&amp;quot;anchor&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The classpath==&lt;br /&gt;
I have packages/directories &amp;quot;utility&amp;quot; and &amp;quot;cluster&amp;quot; in my home directory. cluster depends on utility, so I compile utility first. To compile cluster, I give the following command from my home directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
javac -classpath &amp;quot;.&amp;quot; cluster/*.java&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example script:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
cd /home/barney/work/mmm/code&lt;br /&gt;
CP=classes&lt;br /&gt;
CP=$CP:../../utility/classes&lt;br /&gt;
CP=$CP:lib/mysql-connector-java-3.0.11-stable-bin.jar&lt;br /&gt;
/opt/sun-jdk-1.4.2.05/bin/java -classpath $CP mmm.RunControl report&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Packages==&lt;br /&gt;
To include class MyClass in package betty.sue, the first line of MyClass.java should be&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
package betty.sue;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and MyClass.java, MyClass.class should be stored in directory sue, which is in directory betty.&lt;br /&gt;
&lt;br /&gt;
To use a class from a package:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import &amp;lt;package_name&amp;gt;.&amp;lt;class_name&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import &amp;lt;package_name&amp;gt;.*;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each has the same performance, but the first form might serve as a mnemonic.&lt;br /&gt;
&lt;br /&gt;
If the current class already belongs to a package (its first line uses the package statement), then the import is implied.&lt;br /&gt;
&lt;br /&gt;
Classes have package visibility by default.&lt;br /&gt;
&lt;br /&gt;
To execute something in a package, the directory containing the package directory structure must be in your classpath. In the example above, the directory &amp;#039;&amp;#039;containing&amp;#039;&amp;#039; betty/sue would be in your classpath.&lt;br /&gt;
&lt;br /&gt;
==Jar Files==&lt;br /&gt;
Unzipping a jar file &amp;lt;span id=&amp;quot;line-72&amp;quot; class=&amp;quot;anchor&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span id=&amp;quot;line-73&amp;quot; class=&amp;quot;anchor&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
jar xf jarfile.jar&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Strings==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
String text = &amp;quot;abcde&amp;quot;;&lt;br /&gt;
text.substring(2) == &amp;quot;cde&amp;quot;&lt;br /&gt;
text.substring(0,1) == &amp;quot;a&amp;quot;&lt;br /&gt;
text.substring(1,5) == &amp;quot;bcde&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Scott</name></author>
	</entry>
</feed>