Q: I read it on http://java.sun.com/docs/books/tutorial/java/javaOO/override.html:
"Also, a subclass cannot override methods that are declared static in the superclass. In other
words, a subclass cannot override a class method. A subclass can HIDE a static method in the
superclass by declaring a static method in the subclass with the same signature as the static
method in the superclass. "
My question: It looks like play with words: override, hide.. Why is it written HIDE?

If I can write a static method in subclass with the same signature it means that I override that
method in superclass, I really changed that method here in subclass. Am I wrong?
Answer: Let's start from the very beginning - definition for overriding. It includes three main
points that overridden method must:
* have the same name
* have the same signature
* have the same data type.
In your case the static method in subclass can have another data type.
Example:
************ Alex.java *************
package alex;
public class Alex {
file:///C|/330_new/330_new/general_java-V.htm (1 of 6) [2003-07-22 22:07:56]
General Java Questions - V
static String al(String name){
return name;
}
}
******************** EOF ***********
************ John.java *************
package alex;
public class John extends Alex {
static int al(int name){
return name;
}
}
******************** EOF ***********
It compiles! You see that in Alex class the method "al" returns String and in John class - int.
It is hiding, not overriding.
Advice: try to avoid such situation when you hide methods in super class. Use different names
instead and you will save a lot of time.
--
AP (JA)
Q: Why C++ is not platform independent?
Answer: C++ compiles to binary code (.obj, .exe, .dll, a.out etc.). Binary code (Machine code,
0's and 1's) are machine dependent.
Java compiles to byte code which is independent of any machine. It need to be interpreted to
binary code by JVM, and executed by the machine
Question: I know that void method does not return any value. But I still write the code like
this:
void nothing() {};
void nothing2() {return;};
Why can we still use "return" in the body of method?
Answer: To be able to exit method when it is necessary.
You can exit the method when you reach the end of method and do not need to use "return".
If due to some condition program must exit the method then you use "return".
Q: I can't find the API documentation on any classes in the sun.* packages. Where is it?
Answer: The short answer is that SUN provides documentation only for the public classes in
java.*. SUN does not provide documentation for sun.* because those are the Sun-specific
implementation, and specifically not part of the Java technology API standard, and are
therefore subject to change without notice.
file:///C|/330_new/330_new/general_java-V.htm (2 of 6) [2003-07-22 22:07:56]
General Java Questions - V
In general, SUN doesn’t provide javadoc documentation for sun.* classes in order to
discourage developers from writing programs that use them. For further explanation, see the
next question.
However, if you must have it, the documentation for sun.* is available separately, here:
http://java.sun.com/communitysource/index.html For example, the doc comments for sun.net
are in the source files located at:
/src/share/sun/sun/net/*.java
This source code release does not include javadoc-generated documentation. You would have
to generate those docs yourself using javadoc.
source: http://java.sun.com/products/jdk/faq.html#A12
Q: How do I copy one array to another?
Given that I have an byte array defined like this:
byte byteSmall = new byte[23];
and another larger byte array defined like this:
byte byteBig = new byte[30];
How do I copy byteSmall into byteBig starting at index 7 without a for loop like this:
for(int i = 0; i < 23; i++){
byteBig[i + 7] = byteSmall;
}
?
Answer: See System.arraycopy:
"Copies an array from the specified source array, beginning at the specified position, to the
specified position of the destination array. A subsequence of array components are copied
from the source array referenced by src to the destination array referenced by dst. The number
of components copied is
equal to the length argument. The components at positions srcOffset through srcOffset+length-
1 in the source array are copied into positions dstOffset through dstOffset+length-1,
respectively, of the destination array.
If the src and dst arguments refer to the same array object, then the copying is performed as if
the components at positions srcOffset through srcOffset+length-1 were first copied to a
temporary array with length components and then the contents of the temporary array were
copied into positions dstOffset through dstOffset+length-1 of the argument array."

Q: Does the java class that call the JNI need to be in the same directory of the DLL?
I have the java class in a package and in a jar file. The DLL it uses is outside of the jar file. The
file:///C|/330_new/330_new/general_java-V.htm (3 of 6) [2003-07-22 22:07:56]
General Java Questions - V
JNI call does not work. I am confused with the path.
Answer: As long as the library is in your "path" you should be able to load it with
java.lang.System.loadLibrary.
On Linux it should be in your LD_LIBRARY_PATH and on Windows in your PATH.
With java.lang.System.load you can load the library from a predefined location.
--
Flaps
Q: By default an application has no security manager and Java runtime environment does
not create automatically a security manager for my program. How then applet where I am not
creating any security manager already prevented from many operations?
Answer: It is true - Java by default let you do whatever you want and then it is your
responsibility to restrict something. In case with applets a little bit different story - applet
viewers and browser have THEIR OWN security manager, not from JRE.
That's why even if you did not define any security manager in the code of your applet, during
the start up time browser/viewers will use their own security manager. This manager is built in
into their application (browser, viewer), not your Java applet.
--
AP (J.A.)
Q: I am a Java beginner. I just want to ask what's the difference between
int [] number;
and
int number[];
Answer: The "postfix []" syntax is to make the language more comfortable with C programmers.
In Java, the "postfix []" binds to the variable name, while the "prefix []" binds to the type name.
In C, there is only the "postfix []". But C also includes pointers, which Java doesn't. The pointers
are identified by having a * between the type name and the variable name.
While there is no danger of ambiguity in this declaration:
int a[], b;
there IS danger of ambiguity in this declaration:
int *a, b;
In the latter case, the C rules are that a is declared a pointer, while b is not.
Java offers the following different ways of declaring arrays:
int a[], b; <--> int[] a, b;
These are not equivalent, because b is an array only on the right side.
Whereas with C-style pointers these would become:
int *a, b; <--> int* a, b;
which breaks the concept of "white space doesn't matter", so it will not be as easy to scan and
parse.
So the designers of C decided to have only 1 form of defining variables with pointer types or
array types, and this was that the * or the [] binds to the variable, not to the type.
file:///C|/330_new/330_new/general_java-V.htm (4 of 6) [2003-07-22 22:07:56]
General Java Questions - V
Java carried over the variable binding, but also introduced the type binding, because there
were no more pointers, so the ambiguity was removed.
--
Joona Palaste
And think also about marketability!
Making Java's syntax highly similar to C and C++'s during its early years:
* Made the language seem more familiar to C/C++ programmers.
* Decreased the learning curve for C/C++ programmers.
* Gained credibility through the frequent inference that it was a next-generation descendant of
C++.
* Increased its pool of programmers by attracting C/C++ programmers through the effects
above.
This isn't the only instance of anachronistic syntax; consider the optional semicolon at the end
of a class declaration.
--
Andrew R.
Q: When do I need to use overloading in a program? And why?
Answer: Overloading is best used when you want to have a function that has the same name
but can accept different arguments. The only restriction is that it must return the same type.
e.g.
public String aName(String str) {
String retStr;
retStr = "Hello" + str;
return retStr;
}
// Now the same function but overloaded
public String aName(String str, String str2){
String retStr;
retStr = "Hello " + str + str2;
return retStr;
}
Both functions return the same type (a String) but have different signatures.
You will find this used a lot with constructors. See any recommended text on Java for a much
better explanation.
--
Anthony Miller
file:///C|/330_new/330_new/general_java-V.htm (5 of 6) [2003-07-22 22:07:56]
General Java Questions - V

Q: Why people claim that java is a secure language...
Answer: The java programming language itself is just as secure or insecure as any other
programming language. A Java Applet (which are used on the web) is a different matter. They
are quite secure.
An applet does not have access to system resources outside of the directory that it is created
in. There are ways that you can give an applet access to this information, but they are pretty
explicit and you will most likely know that the applet is trying to do this.
I am not really familiar with the subject but did a little reading on the sun website. Check it out
for more info:
http://developer.java.sun.com/developer/technicalArticles/Security/
You aren't supposed to be able to break the rules easily at run time. The elimination of pointer
arithmetic is supposed to improve type safety.
The Code Red worm is a good example of the weakness of the 'old-style' languages. This
worm uses a 'buffer overflow' attack to 'trick' the IIS program in to doing it's bidding.
The Java system is designed to make it harder to make the programming mistake that Code
Red exploits. It is important that you understand that Code Red would not have been possible
without careful attention to a fast buck by Mr William Gates III and his cohorts.
--
Dr Hackenbush
Q: Does anyone know if there is a way to prevent System.exit() being called?
Answer: Look into java.lang.SecurityManager. It has a method called checkExit() with which
you can prevent System.exit().
This method throws a SecurityException if the calling thread is not allowed to cause the Java
Virtual Machine to halt with the specified status code.