following are the tips given but not explained in javaranch, i tried to find out but couldn't get answers, how these work ? ** Two public classes in the same file. ** Main method calling a non-static method. ** Methods with the same name as the constructor(s). ** Thread initiation with classes that don't have a run() method. ** Local inner classes trying to access non-final variables. ** Case statements with values out of permissible range. ** Math class being an option for immutable classes !! ** instanceOf is not the same as instanceof ** Private constructors ** An assignment statement which looks like a comparison if( a=true)... ** System.exit() in try-catch-finally blocks. ** Uninitialized variable references with no path of proper initialization. ** Order of try-catch-finally blocks matters. ** main() can be declared final. ** -0.0 == 0.0 is true. ** A class without abstract methods can still be declared abstract. ** RandomAccessFile descends from Object and implements DataInput and DataOutput. ** Map does not implement Collection. ** Dictionary is a class, not an interface. ** Collection is an Interface where as Collections is a helper class. ** Class declarations can come in any order ( derived first, base next etc. ). ** Forward references to variables gives compiler error. ** Multi dimensional arrays can be sparse ie. if you imagine the array as a matrix, every row need not have the same number of columns. ** Arrays, whether local or class-level, are always initialized Strings are initialized to null, not empty string. ** An empty string is NOT the same as a null string. ** A declaration cannot be labelled. ** continue must be in a loop( for, do , while ). It cannot appear in case constructs. ** Primitive array types can never be assigned to each other, even though the primitives themselves can be assigned. ie., ArrayofLongPrimitives = ArrayofIntegerPrimitives gives compiler error even though longvar = intvar is perfectly valid. ** A constructor can throw any exception. ** Initializer blocks are executed in the order of declaration. ** Instance initializer(s) gets executed ONLY IF the objects are constructed. ** All comparisons involving NaN and a non-Nan always result in false. ** Default type of a numeric literal with a decimal point is double. ** integer (and long ) operations / and % can throw ArithmeticException while float / and % will never, even in case of division by zero. ** == gives compiler error if the operands are cast-incompatible. ** You can never cast objects of sibling classes( sharing the same parent ), even with an explicit cast. ** .equals() returns false if the object types are different. It does not raise a compiler error. ** No inner class can have a static member. ** File class has NO methods to deal with the contents of the file. ** InputStream and OutputStream are abstract classes, while DataInput and DataOutput are interfaces.
Hi! Maybe you should read a good book first and then your questions above would be clear to you. Anyhow I can answer some of them.
** Two public classes in the same file. ** Main method calling a non-static method. ** Case statements with values out of permissible range. ** instanceOf is not the same as instanceof
** Two public classes in the same file. There isn't much to understand here. Just test to put 2 public classes in the same javafile and you would get compile error. This is something you should look for in the real test. Don't miss this one. ** Main method calling a non-static method. You can only call methods through a instance of the class like this. test t = new test(); t.yourmethod() if your calling yourmethod() directly and yourmethod isn't static then you would get a compile time error. You can call a static method direct, through an instance or by your classname. A static method means there is only one of the static method per class and not one method per instance. ** Case statements with values out of permissible range. A case block can only deal with. byte , short , int , char. If another primitive type is called upon then you will get a compile time error. ** instanceOf is not the same as instanceof instanceof is an operator. By this you can test if your objects is of the same class or not. There isn't any operator with the identifier instanceOf . Just lowercase. Javaranch will like you to remeber this, so you don't think your dealing with an operator // MAthias
Joined: Sep 09, 2001
Thanks for the answers of some questions.... I'm going through books and I think you are right I may get most of them from the books, again very thatnks ------------------ Harjeet Singh Dadwal
Joined: Nov 22, 2008
No problem The list that javaranch has supplied is suppose to be , what do you say , a regular check list. You can just take a quick look at the list so that you remember the "traps" not to fall into. // Mathias
Joined: Sep 09, 2001
where is the check list located pla. ?
------------------ Harjeet Singh Dadwal
subject: Wanna know answers to the tips given in javaranch