== and equals to
compare objects.
First check to see if Sun's JDK is already on your path by executing:
If Linux does not respond with the full pathname ofwhich javac
javac,
then you will need to fix your path by:
set path directive is in your
.cshrc or
.login in your home directory.
If the set path directive is in your .login, move it to
your .cshrc file.
.cshrc file (from 1 above) adding:
to your/usr/local/jdk/bin
set path directive.
as appropriate from within an Xterm window.source ~/.cshrc
which command again.
Step 3 is a one-time only event; the next time you login the commands
javac and java should be in your path.
ssh. This will give you full remote X Window displays to all
your favorite X applications, including Java applets.
for some class X. Anjavac X.class
ls reveals that indeed
X.class is in your current directory. This is a common error.
The java command expects a class name, not a
filename. Leave out the .class, i.e., enter the command:
where X is the name of your class.java X
Unless the method is part of the current class, the compiler does not know which method is being invoked. In this case, the statement should read:i = max(a, b);
In the case of a method in the current class,i = Math.max(a, b);
this is
implied.
A change toa = new Ref(...); Ref b = a; a.set(5);
a also changes b since a and b are
references to the same object. This is what allows a method to change an object parameter, since the object parameter (a reference or pointer) is actually passed by value. Thus, a method can change the contents of an object parameter, but not which object the parameter references.
When you need a copy of an object, you must use its clone method.
== and equals to
compare objects.equals to compare two objects. The operator
== tests for pointer equality (i.e., do the objects point to the
same thing). The equals method tests to see whether the two
objects are equal (and may vary in definition from one object to the
next).