aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Traps to be aware of in any SCJP test !!!!! :) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Traps to be aware of in any SCJP test !!!!! :)" Watch "Traps to be aware of in any SCJP test !!!!! :)" New topic
Author

Traps to be aware of in any SCJP test !!!!! :)

Junaid Bhatra
Ranch Hand

Joined: Jun 27, 2000
Posts: 213
Hi Ajith,
Inner classes can contain static fields provided they are also declared final (compile-time constants).
This is clearly specified in the 2nd edition of JLS. http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#262890
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by satya5:
Another URL with lots of one liners to remember for the exam
here
From a previous post by Hari P.
Regds.
- satya


Does anyone know of any more links to lists like this? I'll be taking my exam tomorrow morning and these lists are an extremely valuable resource for last minute study. Thank you all by the way for putting this together.
-Meadowlark Bradsher
Aru
Ranch Hand

Joined: Jul 20, 2000
Posts: 112
Hi All,

If I run this piece of code...given by Khalid, I'm getting this error...Can anyone Help.
Exception in thread "main" java.lang.VerifyError:
(class: Sample, method: main signature: ([Ljava/lang/String V) Expecting to find unitialized object on stack
Thx in Advance
Aruna
import java.io.*;
class Sample {
public static void main( String arg[] ) {
System.out.println("I'm a little sample, short and ... ");
Sample.LittleSample b = new Sample().new LittleSample();
}

static class LittleSample {
static String str = "stout";
LittleSample() {
System.out.println(str);
}
}

}
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi,
change the line of the creation of u r static class to the one given below.
Remember static nested classes are not linked with the outer class
Sample.LittleSample b = new LittleSample();
Regds.
Rahul
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hello surya,
Below is one of your statements. I was trying to do something like what u mentioned. I am not able to initialize the class variable in the class method.
Can u elaborate on ur statement.
You can call a method to provide an initialization value for the variable at the class level and at the method level itself.
thanx
shanks
Deepak M
Ranch Hand

Joined: Jul 10, 2000
Posts: 124
An object of an inner class has an enclosing instance.
Is NotInner below an inner class ?
class Test {
static {
class NotInner {}
}
}
Declaration of NotInner occurs in a static context and hence does not have any enclosing instances. THerefore it is NOT an inner class !
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Deepak,
Yes, you are right. Here NotInner is not an inner class. It is a nested-class also called as top level nested class. Your class declaration is equivalent to

Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Hema
Greenhorn

Joined: Aug 01, 2000
Posts: 12
Hi Ajith,
I'm taking my exam this month end & preparing with the help
of this thread & the book " Java cert study guide- Robert, Heller".
In this book, chapter 6- Objects & classes covers the
inner classes.It has a sub heading , "Static Inner Classes"
which states "Java allows an inner class to be marked Static"
But what I infer from yr reply to Deepak is that there is no
static inner class in java, instead it shuld be called
top level nested class.
Is that what you mean ?
Thanks,
Hema
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Hmmm.. looks like I have successfully confused you, haven't I?
Well, believe me my intention was not to confuse people. The following is a post from Jim( under the same thread ), which is what I wanted to say. So here it goes...

A couple addenda to Ajith's list: static member classes used to be called "top-level nested classes", and were considered top-level, at least according to the original Nested Classes Specification. However this never really caught on, and under the JLS 2nd edition they are no longer considered top-level. I don't think any exam questions ever considered them top-level (or at least, they don't ask about it), so you're safe here.
However, the exam does apparently consider static member classes to be inner classes, even though this is clearly contradicted by the Nested Classes Specification and the JLS2. They don't make a big deal about it - they just call them "static inner classes". So, for the exam, pretend they're inner classes, and remember that in the real world, they aren't.

Hope this helps.
Ajith
Hema
Greenhorn

Joined: Aug 01, 2000
Posts: 12
Thanks Ajith,
That really helped & I'm very CLEAR now.
Got to do lot of reading.
-Hema
Shubhangi A. Patkar
Ranch Hand

Joined: Sep 20, 2000
Posts: 78
my contribution AFTER clearing SCJP
Try to keep a time gap between your mocks, and keep them only for last three weeks, otherwise with current mocks the questions are simmilar and you tend to score higher not because you know the concept, but because you know the question.
All the best...
Shubhangi
Kaushik Subramanya
Greenhorn

Joined: Sep 26, 2000
Posts: 9
Ajit,
There has been quite a bit of confusion (at least in my case) about the inner classes. Can you once and for all sum it all up and post the correct features of the Inner classes
Sorry for disrupting your extended vacation
~Kaushik
Originally posted by Ajith Kallambella:
[B]Here is a summary of types of classes

Hope this helps!
Ajith
[This message has been edited by Ajith Kallambella (edited July 13, 2000).][/B]

Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Kaushik,
The table above is the correct summary of inner classes. Is there anything you want to contest??
Note for other readers - The summary of this post has been incorporated into the Certification FAQ. You may want to go there if you find this thread confusing..
Ajith
Amit Roy
Ranch Hand

Joined: Oct 10, 2000
Posts: 132
I hav not gone carefully through this entire post so might be what i am putting has appeared
1)INNER CLASSES CAN EXTEND ONLY I INTERFACE
2) ALL LISTENERS METHOD RETURN VOID
3)main is not a keyword


<I>Chance Favours the Prepared minds"</I>
yogesh sood
Ranch Hand

Joined: Aug 31, 2000
Posts: 108
hi following lines bout INNER CLASSES is from my side
An inner class is a nested class that is not explicitly or implicitly declared static
Inner classes may not declare static intilaizers or memeber interfaces.
Inner classes may not declare static members,unless they are compile time constant field
However Innner classes can inherit static member that are not compile time constant.
Nested classes that are not static can declare static member according to normal rule of java.
Member interfaces are always static they are not consider as inner class
Here is code to proof this.
classs Hasstatic{
static int j=100;
}
class Outer {
class Inner extends Hasstatic{
static final int x=3; //O.K compile time constant
static int y=90; //ERROR
}
}


If its green its biology if its stinkks its chemistry if it has numbers it is Maths and if it doesn't work its TECHNOLOGY
Prasanna V
Greenhorn

Joined: Feb 18, 2001
Posts: 2
Thanks a Million to all those who contributed to this page..
That was great a help
a hui
Ranch Hand

Joined: Oct 14, 2000
Posts: 39
I'd like to thank you for clarifying this point. Here is an example for a top-level class (not that static class is referenced differently than non-static one)
import java.io.*;
class Sample {
public static void main( String arg[] ) {
System.out.println("I'm a little sample, short and ... ");
Sample.LittleSample b = new Sample.LittleSample();
}
class LittleSample {
static String str = "stout";
LittleSample() {
System.out.println(str);
}
}
}

Also I'd like to provide an example for a static local class where static variables can't be declared. The only way to reference the local class is from the methodA(), is there another way to instantiate the LittleSample class?
import java.io.*;
class Sample {
public static void main( String arg[] ) {
System.out.println("I'm a little sample, short and ... ");
methodA();
}
static void methodA(){
class LittleSample {
//static String str = "stout";
String str = "stout";
LittleSample() {
System.out.println(str);
}
}
new LittleSample();
}
}

AH
a hui
Ranch Hand

Joined: Oct 14, 2000
Posts: 39
I'd like to thank you for clarifying this point. Here is an example for a top-level class (not that static class is referenced differently than non-static one)
import java.io.*;
class Sample {
public static void main( String arg[] ) {
System.out.println("I'm a little sample, short and ... ");
Sample.LittleSample b = new Sample.LittleSample();
}
class LittleSample {
static String str = "stout";
LittleSample() {
System.out.println(str);
}
}
}

Also I'd like to provide an example for a static local class where static variables can't be declared. The only way to reference the local class is from the methodA(), is there another way to instantiate the LittleSample class?
import java.io.*;
class Sample {
public static void main( String arg[] ) {
System.out.println("I'm a little sample, short and ... ");
methodA();
}
static void methodA(){
class LittleSample {
//static String str = "stout";
String str = "stout";
LittleSample() {
System.out.println(str);
}
}
new LittleSample();
}
}

AH
Nisheeth Kaushal
Ranch Hand

Joined: Jul 20, 2001
Posts: 87
Keep this intouch.
--Nisheeth
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
A great work is made here to start and maintain this thread by you people. Thanks a lot to you all...
This kind of suggestions i was looking for from you ranchers...
Keep it up and share your experiencd suggestions with us...here.
Rashid Ali
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
I had my exam on augustus.
Too bad that I discovered javaranch so late.
It would have been of great help.
I did only 71%, maybe my score would have been a little bit higher.
This site is really great, with great people helping each other.
I will definitly come here everyday.
Thx Guys.


Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
James Childers
Greenhorn

Joined: Jan 07, 2002
Posts: 9
Essouabni,
Maybe you could post some tips of your own. What suprised you, and advice would you offer to those who will soon take the test?
- James


"The enemy is never the enemy in his own eyes." - Sun Tzu
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
Nothing to do much .... atleast today
but can avoid this ranch .. so ..
Suggestions :
1. first read RHE then take mocks, after each mock make a list of quetions which were wrong ... and WHY? clear the concept or topic... best place for discussion.... I won't tell
2.between mocks give some break.
3. Read Khalid... without it u will feel something is missing ... and yes it helps you to revise the concepts.
4. again mocks ... repeat step 2.
5.JQ+ is good as it gives real simulation and lot of que. on ur desktop. BUT do not take them for there gaurantee.... it is good as you get lot of questions together... AND NEVER start with JQ+... Keep it for last 10-15 days... never trust it's answer blindly(I found lot of them to be , if not wrong, then not with correct explanation.).... It's good means you get lot questions at one place, that's all.
6.]http://www.javaranch.com/maha/_Mock_Exams/_mock_exams.html] Do visit this page[/URL]

I have myself noted down some points(I think 99.99% they are correct, some I copy/paste from sites) .. but still plz correct me if u find any point wrong.
so here goes list ...
==================================

* We can declare array of element ZERO.
* Java do not have any operator like &&=
* instanceof operator always return false for null value.
* null value can be casted but do remember it is of no use to cast null value
* you can not use more than '4' digits in case of character constant.
* You can give char constants value between 0-255.
* Char constant '\101' is valid as it is representing the value in "octal", which is equivalent to 65.
* Values for char constant '\u000A' and '\u000D' is not valid as they represent line breaks.
* CODE:
while(false)
{
System.out.println("Hello");
}
will give you error " Unreachable statement ".
* We cannot declare a static variable inside a non-static inner class but static final variable is allowed as the compiler will treat it as a constant.
* Class H and class G has no relation(i.e if two class has no relation) with each other so both instanceof and == operator will give you compile time error.
* Interface methods can not be native, static, synchronized, final, private, or protected.
* Interface fields can't be private or protected. They are by default public static final. The final variable must be initialized
* transient variables can't be members of interfaces.
* Volatile variables can't be final or members of interfaces.
* Math.abs() will return the argument itself, if it is equivalent to Integer.MIN_VALUE or Long.MIN_VALUE. Exa Math.abs(-2147483648) return -2147483648. if litral is less than MIN_VALUE then compile time error will occur "Decimail must be in the range of so and so".
* We can use negative argument in indexOf() and lastIndexOf() method of String class. In such case it will start searching from zero.
* In switch statement case: arg
arg can be either Integer LITRAL or variable which is CONSTANT or expression which is CONSTANT.
* Methods can not have static variable. mehod1() { static int I ; } won't compile.
*
Also from Vel's notes as provided by Ajith Kallambella
- 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 vars.
- case statements with values out of permissible range.
- Math class being an option for immutable classes !!
- instanceOf is not same as instanceof
- Private constructors
- An assignment statement which looks like a comparison if ( a=true)...
- System.exit() in try-catch-finally blocks (if before finally, finally would not execute).
- 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 doesnot 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 sparce 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, eventhough the primitives themselves can be assigned. ie., ArrayofLongPrimitives = ArrayofIntegerPrimitives gives compiler error eventhough longvar = intvar is perfectly valid.
- A constructor can throw any exception.
- Initilializer blocks are executed in the order of declaration.
- Instance initializer(s) execute ONLY IF the objects are constructed.
- All comparisons involving NaN and a non-Nan would always result 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
* Always see carefully overLOAD OR overRIDE
* In switch statement case: arg
arg can be either Integer LITRAL or variable which is CONSTANT or expression which is CONSTANT.
Hi ,
I got messages regarding information on the exan Here it goes.
The changes in the code were made last year in October not this year.The rules are the same :
2 hours, 59 questions, 61% to pass. I could get 51 questions correct of 59 questions.
I started with around 7 questions on threads. You should know how to work with threads running together and calling synchronized or non- synchronized methods or methods having synchronized blocks.
In IO you need to be clear with the constructors.....can i put OutpuStream in FileOutputStream ??? like this.
Be clear with the operators and loops and how the continue , switch, break behave in all the different ways. Putting default in a switch in the beginning, middle or at the end when the passed integer is there as a case....or not there....
You should know the main methods of the StringBuffer, String, Math Class....with their return types.
You should know in awt how different layouts would place things... their defaults - alignment, positions, etc,
On the whole its cool,
take lots of mock tests,
cheers,
* Careful about final var... they can not be changed....
* main() can not access member var directly ... if member is not static.... As main() is static method......
List all the things that you want to remember during the exam such as
All awt event listeners and their methods and the arguments to that method. Next to each event listener, write down the awt component that can generate that event.
Write down all the collections interfaces and their features.Then next to each interface, write the name of the class that implements that interface.
Write down the names of all stream readers/writers
Write them down accoring to their inheritance hierarchy
Write down all the methods available in the File class- along with their signature.
Write down the constructors of the thread class and the mehods- at least the one's covered in RHE.
Write down all the methods of the Object class.
Write down all the methods of the String and StringBuffer class- one has append and the other has concat - both do the same thing.
You can add anything else you want. But make this on your own. Go through the books, go through the API and compile this.
* Read options very clear fully ... give weightage to each word.
* Always see the no of correct answer.
* The moment see the constructor with arguments.... See the extending class can be created or not ... in all prob...
* See the ; as the end of statement.
* Static method .. check it out .. accessing any instance variable or calling any member method... it CAN NOT do so .
I had 6 questions on threads. so at least remember api of Thread and Runnable.
collection: list, set, map, vector, arraylist, their constructors/methods and characteristics
IO: constructors for InputStream, FileInputStream etc.
* While checking range +tive range should be odd and -tive range should be even number.
* If package stmt is there ... then make sure that access is public .. if that thing is going to be accessed outside the package.
*
* The genral rule is that ~i = -i-1 (Exa: ~3 = -3 - 1 = -4)
* Rules are the layout manager (GridLayout) adds another column when
necessary and rearrange all the element again. One
exception to it is when there are only one column,
extra element will be added to the same column.
* \u000a and \u000d are line terminators. So they should not be used in java source program.
* Singaniture for finalize() method is:
protected void finalize() throws Throwable
You can override it as protected or public and can throw any exception.
* When you add an object to HashSet object using add(Object obj) method then if object is equal to some object inside the HashSet, the operation just failed and return false.
* HashSet allows null.
* Null can not be assigned to primitive data type.
* Math.ceil(-0.5) = -0.0
* Math.round(-5.5) = -5
* Math.round(5.5) = 6
* Math.round(5.49) = 5
* Math.round(-5.49) = -5
* GridLayout always ignores components preferred size.
* getCanonicalPath() = C:\java\12345.msg
* getAbsolutePath() = C:\java\dir1\..\12345.msg
* Non static inner classes can not have static members.
* Applet can not have menu as it is not subclass of Frame.
* File class method renameTo( ) takes File object as param.
* System.out.println(null) will not compile.
1. ExamCram -
* Wrapper classes are immutable.
* Equals() never throw Exception... it will return false.
*
2. JQ+ Demo
* Object has two protected methods finalize() and clone()
* If method is static then see if it is accessing any non static member variable.(it can not access non static-member var)
* Evalution of operand is Left to Right.... Note it ... a[i][i=3][i] = a[4][3][3] if I = 4.
*
2. Kahild
* methods are public by default in interface, but not in class, so make sure if any class is implementing any method from any interface then it has a access modifier as public in class.
3. JQ+
* if any sub class is in different package then baseClassObject.memVar can not be accessed in class body of subclass, that can be accessed by subClassObject only . [IMP]
* compiler checks whether if(arg) arg returns boolean or not .. if not then compile time error.
* About clone( ) it is protected and may throw CloneNot SupportedException
x.clone() != x will be true, means they are not pointing to same memory
and that the expression:
x.clone().getClass() == x.getClass() will be true, as they are object of same class
but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x) will be true.
In cloning constructor is not called while creating object.
4. JavaCaps Mock Exam
* Boolean is valid identifier ... do not assume it to be keyword... only KEYWPRD/RESERVED words can not be valid identifier.
* Import statement CAN not appear any where
* If Parent class default constructor throws Exception then derived construtor must either catch it or thorw it again(include throws clause).
* byte ver's binary arithmetic operation can not be assigned to LHS byte var as they are promoted to integer. Cast is needed.
*
5. JQ+ Test 2
* List does not have setRows() method i.e. once no of items can be displayed set in the CONSTRUCTOR then it can not be changed.
*
6. JQ+ Test3
* Inner classes do not have same name as enclosing classes.
* If ther is no stmt after try/catch/finally ........ then all blocks can return .
* Flow layout: .. flow of putting componenet is left to right ... and in the center of screen.
* To extract (positive num) byte from int & with 0xff.
* hashCode() returns a int.
* nearly all Hashtable methods are synchronized
* BitSet has nothing to do with sets or collections.
7. JQ+ Test 4
* Non-static inner classes can contain final static fields (but not methods), without final won't compile.
* NOTE: static classes can have static member which are not final.
* Anonymous classes cannot have explict constructors, since they have no names.
* Every interface is implicitly abstract.
* Every field declaration in the body of an interface is implicitly public, static and final.
* A field in an interface must not include any of the modifiers synchronized, transient or volatile, or a compile-time error occurs.
* A method in an interface cannot be declared static, because in Java static methods cannot be abstract.
* A method in an interface cannot be declared native or synchronized, However, a method declared in an interface may be implemented by a method that is declared native or synchronized in a class that implements the interface.
* Member Variable will always be accessed by the Type of class.. not by the object that TypeVar is holding.
* >>> operators result can be negative if RHS is multiple of 0,32,64... as no shift will be there.
8. JQ+ Test 5
* If f1 represents +0.0f while f2 represents -0.0f, or vice versa, the equal test has the value false, even though 0.0f==-0.0f has the value true.
* If f1 and f2 both represent Float.NaN, then the equals method returns true, even though Float.NaN==Float.NaN has the value false.
* A NaN is not equal to NaN. So Float.NaN != Float.NaN is true.
* A break statement with no label attempts to transfer control to the innermost enclosing switch, while, do, or for statement; this statement, which is called the break target, then immediately completes normally. If no switch, while, do, or for statement encloses the break statement, a compile-time error occurs.
* A break statement with label Identifier attempts to transfer control to the enclosing labeled statement that has the same Identifier as its label; this statement, which is called the break target, then immediately completes normally. In this case, the break target need not be a while, do, for, or switch statement.
* A continue statement with no label attempts to transfer control to the innermost enclosing while, do, or for statement; this statement, which is called the continue target, then immediately ends the current iteration and begins a new one. If no while, do, or for statement encloses the continue statement, a compile-time error occurs.
* A continue statement with label Identifier attempts to transfer control to the enclosing labeled statement that has the same Identifier as its label; that statement, which is called the continue target, then immediately ends the current iteration and begins a new one. The continue target must be a while, do, or for statement or a compile-time error occurs. If no labeled statement with Identifier as its label contains the continue statement, a compile-time error occurs.
* Can not over ride static method with non-static method... compiler error .
* processEvent () and dispatchEvent () are methods of Component class
* setSize() and setBounds are for adjusting the size of componenet.... No method is like setDimensions()..
* When RandomAccessFile is opened in "rw" mode then filePointer is at start.
* Only InputStreamReader is for customizing the Encoding.
* Make sure all var are initialized .... And not in if block as it might not initialized so compiler error ...
* '\uoooa' should not be used anywhere in java source file .
* ClassName.this.varName = this.varName
* continue with/out label but has to be with loop.
* break without label only with loop, outside loop needs label else compile time error.
JQ+ Test 6
* Objects passed to the method are never garbage collected in that method.
* FileOutputStream if opened as true (for append mode).. then it creates file if it does not exist or append the text in end.
* notify() is supposed to do notify one of the threads that were waiting on this object.
* If null is passed as parameter than most specific down to the hierarchy class param method will be called. BUT if two methods which are not form the same hierarchy are present than compiler will raise error.
* for loops mid stmt has to be boolean, first stmt should either declation(can declare & init more than 1 var BUT type should be same and written only once) or stamt. In Third you can not declare any variable.
* (long) by/d*3 => ( (long) by ) / d * 3;
* A column in TextArea is an approximate average character width that is platform-dependent.
* The Writer class has no write() method with a parameter of type char.
* Abstract Writer class's subclass must implement are write(char[], int, int), flush(), and close(). Most other methods are defined .. or are overridden by subclasses.
* Remember : variables are SHADOWED and methods are OVERRIDDEN. In Shadowing .... methods will use there class's member var(though they are shadowed).... till it is not directly accesses by using refName.VarName
* All numeric wrapper classes namely, Byte, Short, Integer, Long, Float and Double extend the Number class.
* A constructor can not be final, static or abstract.
* round(2. 5) = 3 => trunc(j + 0.5) NOTE: round(-2. 5) = -2
* suspend(), resume() and stop() are deprecated methods because they don't give the Thread a chance to release shared resources which may cause deadlocks.
* Main thread created by JVM is not deamon thread.
* ClassName.this.varName = this.i for that class.
* String String = ""; //This is valid.
String : for(int i = 0; i< 10; i++) //This is valid too!
* To convert it to base 8:
668/8 => 83 and Remainder = 4
83/8 => 10 and Remainder = 3
10/8 => 1 and Remainder = 2
1/8 => 0 and Remainder = 1 So it is 1234 !
* If f1 and f2 both represent Float.NaN, then the equals method returns true, even though Float.NaN==Float.NaN has the value false.
* If f1 represents +0.0f while f2 represents -0.0f, or vice versa, the equal test has the value false, even though 0.0f==-0.0f has the value true.
JQ+ Test 7
* Abstract class can have final or static method.
* Interface ... while defining methods of interface .... Make them public else compile time error .
* Classes do not extend interfaces
* ========================= FROM JQ+ ===================================
* Remember these rules for primitive types:
1. Anything bigger than an int can NEVER be assigned to an int or anything smaller than int ( byte, char , short) without explicit cast.
2. CONSTANT values up to int can be assigned (without cast) to variables of lesser size ( eg. short to byte) if the value is representable by the variable.( ie. fits into the size of the variable).
3. operands of mathematical operators are ALWAYS promoted to ATLEAST int. (ie. for byte * byte both bytes will be first promoted to int.) and the return value will be ATLEAST int.
4. Compound assignment oprators ( +=, *= etc) have strange ways so read this carefully:
A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.
Note that the implied cast to type T may be either an identity conversion or a narrowing primitive conversion.
For example, the following code is correct:
short x = 3;
x += 4.6; // no compilation error / runtime error ... data may be lose .. i.e byte b = 127 ; b += 50;// NO ERROR
and results in x having the value 7 because it is equivalent to:
short x = 3;
x = (short)(x + 4.6);
=======================================================================
* No trim() method in StringBuffer.
* In GridbagConstraint ..... give notice to X , Y as they decide .. hori or verti..

JQ+ Test 8
* Always see if there is no stmt ... then there will no compile error of non-Reachable stmt.
* while(false){ }
* RAF throws EOFException if not returning int as -1.
JQ+ Test 9
* If catch throws any exception still finally will be executed.
* method prototypes in interfaces can never be static
==============================================
in last JQ+ test I got 85%.....
thats all one I have
Thanks to all Rancher for there help
Specially to bartenders
and yes if you have TIME then first try to search and write a program .. Most the time I did not post que. as I got the ans and PLUS lot of extra knowledge through search.
ALL THE BEST TO ALL
[ February 06, 2002: Message edited by: ravish kumar ]

"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
aymen esawey
Ranch Hand

Joined: Jan 29, 2002
Posts: 61
hi
great thread
i just stopped at this by ravish:

3. JQ+
* if any sub class is in different package then baseClassObject.memVar can not be accessed in class body of subclass, that can be accessed by subClassObject only . [IMP]

i can't understand what it means!! any help will be appreciated


Aymen Esawey<br />SCJP <img src="smile.gif" border="0"> <br /><a href="http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=32&t=001968" target="_blank" rel="nofollow">how to nuke the SUN </a>
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Hello,
The lesson Controlling Access to Members of a Class from the The Java Tutorial explains this concept.
Good Luck,
-Dirk Schreckmann


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
aymen esawey
Ranch Hand

Joined: Jan 29, 2002
Posts: 61
alrighty then(still in happy mode):
don't get overconfident in those:
Decl&access ctrl,flow ctrl &exception hndlng,lang fund,oper &assignments,and yeah java.io package.
questions never appear to be what they are so read answers first to know what they're about,and time is not an issue.
1* get the io constructors and methods real good,know what could be thrown ,and what to catch(only checked required).
2* know your file methods' return types.
3* know your string methods and how different from StringBuffer methods they are,when passed by reference to methods what really changes & waht stays the same.( string and wrappers immutable so you can never change there values contained)
4* know exactly what happens whith try-catch-finally blocks when exceptions thrown and when no exceptions thrown ,and return occurring in one of t-c-f blocks."just practice with (conditions and throwing) and (return and printing) and other statements inside try and after finally"i think i didn't get that one right so beware".
5* know equals very well,and how == is different and what classes override equals to behave differently than Object.equals()(for wrapper classes and collections and "String").
6* threading is stressed ,so better know your methods (join,sleep,wait,notify ,notifyAll)and their effect on threads state.wording is important.
7* synchronized code being accessed from non-synchronized code"real tricky get mughals' test engine its similar"
8* know your access modifiers ,how they affect inheritence in subclasses(inside same package and outside JLS has real good code examples read and play with the code amazing)also the effect with constructors."real tricky".
9* instance,class members and constants and and the inheritence either by extends or implements.
*** know that local fields can't be static .
10* static inner classes and the instantiation of them,and how it differs from non static inner classes.also watch out for access modifiers with those.
11* know your precedence and associativity(janeg tutorial got this)with casting ,bit shifting and arithmetic operations"that is in the absence of ( and ).
12* overloading and overriding ,overloading is independent,while there is rules with overriding not just throws and accessibility. also order of args in overloading.(native synchronized and abstract ).
13* order of constructors execution top to current.
and what methods get called in constructor of super if methods overriden"successfully".
* the effect of output io operations on the h/d,when is file created ,and where writing takes place("",true).

i thought i was so good in those and practiced alot on them still am surprised that i only got the easy parts wrong.

14* know your events and eventlisteners methods and thier signatures.
15* nested layouts and the resize behavior,flow layout honors "pr.size" and grid ,border don't.
16* really get a deep understanding of gridBagConstraints don't just read you'll never get it ,got to try some code"suns' tutorial best thing i found on that".
17* know conversions and casting.also in method calls.primitives and object references.
*** don't take every mock you see,only mocks discussed here or at jchq and you find to be useful ,that would only mislead you and slowdown your learning process ,i found that the hard way.
*** now you find some Q with code that you don't get compile and play with then write your notes and go read about the Qs' subject,you'll be amazed how your findings can be said in an easier way(but having Q in your mind then finding the answer surely stays til the next morning)
*** if you're new to the site just open the first 3 pages and see whats discussed,maybe some Q that would never come to you could popup and be solved on the fly."my desktop was also full of saved threads every night".
** bill brogdens' exam prep really helped me alot.
if any of the moderators find this posting to be not in accordance with suns or javaranch rules,just delete it.
note : these are fresh notes ,just passed with91% today.
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
Originally posted by aymen esawey:
hi
great thread
i just stopped at this by ravish:

i can't understand what it means!! any help will be appreciated

Hi Aymen
here is the question:
Consider following two classes:

What will be the output of compiling and running class B ?
1) print 10
2) print 20
3) not compile
4) throw exception
5) none of above
Explanation is here .. and which is correct
-------------
Although, class B extends class A and 'i' is a protected member of A, B still cannot access i , (now this is imp) THROUGH A's reference because B is not involved in the implementation of A.
Had the process() method been defined as process(B b); b.i would have been accessible as B is involved in the implementation of B.
For more information read Section 6.6.7 of JLS:
http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#36191
----------
I did wrong on my first attempt
HTH
swapna sivaraju
Ranch Hand

Joined: Jan 18, 2002
Posts: 75
I have some doubts regarding the tips posted by Kahild--

1. You can use yield, sleep(int) and wait() for yielding other thread
2. You can perform >> on any primitive (although it is not wise to do it on primitives
smaller than int because you may suffer sign change...)

3. LayoutManager2 is an interface used for constraints with GridBagLayout, GridLayout and
BordLayout.

regarding the 1. point-- is it not true we yield only the current thread? and also sleep causes the currently running thread the to sleep???

2.---the statement says we can perform >> on any primitive but its not allowed on floatpoint nos.
3.---And GridLayout doesnt implement LayoutManager2 but it implements LayoutManager interface(thats what i read )
Am i right??
swapna


SCPJ2
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Resurrecting...


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
sun moon
Greenhorn

Joined: Oct 09, 2002
Posts: 28
This code gives you full picture of referencing class,intefaces and abstract classes
May i think it helps us
// This program provides u various situation of class and interface references with exaplation
// Step - 1 : Inheriting Inteface to class
// if u inherit then type casting is neccessary at @1
/*interface BestReference
{
void methodA();
};
interface RestReference
{
void methodA();
};
class TestReference implements RestReference,BestReference
{
public void methodA(){
System.out.println("interface method!");
}
public static void main(String[] args)
{
RestReference rr = new TestReference();
rr.methodA();
BestReference br = new TestReference();
BestReference br1 = (BestReference)rr; // here type casting is neccessary @1
br.methodA();
System.out.println("Hello World!");
}
}
// Step - 2 : creating reference to class through Interface
// type casting is neccessary at @1,@2,@3 because u r not inheriting but u r refering
// the object by interface. If u remove typecasting then Type casting exception is through
interface BestReference
{
void methodA();
};
interface RestReference
{
void methodA();
};
class TestReference
{
public void methodA(){
System.out.println("interface method!");
}
public static void main(String[] args)
{
RestReference rr =(RestReference) new TestReference(); // @1
rr.methodA();
BestReference br = (BestReference)new TestReference(); // @2
BestReference br1 = (BestReference)rr; // @3
br.methodA();
System.out.println("Hello World!");
}
}
// Step - 3 : creating reference to Class through Class
// type casting is neccessary at @3
// If u remove typecasting then Type casting exception is through
class BestReference
{
void methodA()
{
System.out.println("best!");
}
};
class RestReference extends BestReference
{
void methodA()
{
System.out.println("Rest!");
}
};
class TestReference extends RestReference
{
void methodA(){
System.out.println("Test!");
}
public static void main(String[] args)
{
RestReference rr = new TestReference(); // @1
rr.methodA();
BestReference br = new RestReference(); // @2
br.methodA();
BestReference br1 = (BestReference)rr; // @3
br.methodA();
System.out.println("Hello World!");
}
}
// Step - 4 : creating reference to Class through Class
// if u create typecasting without extending the classes like @1,@2,@3 then
// it pops up with error saying illegal typecasting
class BestReference
{
void methodA()
{
System.out.println("best!");
}
};
class RestReference extends BestReference
{
void methodA()
{
System.out.println("Rest!");
}
};
class TestReference
{
void methodA(){
System.out.println("Test!");
}
public static void main(String[] args)
{
RestReference rr = (RestReference) new TestReference(); // @1
rr.methodA();
BestReference br = (BestReference) new TestReference(); // @2
br.methodA();
BestReference br1 = (BestReference)rr; // @3
br.methodA();
System.out.println("Hello World!");
}
}
// Step - 1 : Inheriting Inteface to class
// if u inherit then type casting is neccessary at @1
abstract class BestReference
{
abstract void methodA();
void methodB()
{
System.out.println("Best");
}
};
abstract class RestReference extends BestReference
{
abstract void methodA();
void methodB()
{
System.out.println("Rest");
}
};
class TestReference extends RestReference
{
public void methodA(){
System.out.println("Test abstract!");
}
void methodB()
{
System.out.println("test");
}
public static void main(String[] args)
{
RestReference rr = new TestReference();
rr.methodA();
BestReference br = new TestReference();
BestReference br1 = (BestReference)rr; // here type casting is neccessary @1
br.methodA();
System.out.println("Hello World!");
}
}

\**********************VERY IMPORTANT****************************/
// ABSTRACT CLASS IS A CLASS NOT A INTERFACE
// Step - 6 : creating reference to class through abstract class (WHICH IS A CLASS)
// if u create typecasting without extending the classes like @1,@2,@3 then
// it pops up with error saying illegal typecasting
abstract class BestReference
{
abstract void methodA();
void methodB()
{
System.out.println("Best");
}
};
abstract class RestReference extends BestReference
{
abstract void methodA();
void methodB()
{
System.out.println("Rest");
}
};
class TestReference
{
public void methodA(){
System.out.println("Test abstract!");
}
void methodB()
{
System.out.println("test");
}
public static void main(String[] args)
{
RestReference rr =(RestReference) new TestReference(); // @1
rr.methodA();
rr.methodB();
BestReference br = (BestReference)new TestReference(); // @2
BestReference br1 = (BestReference)rr; // @3
br.methodA();
System.out.println("Hello World!");
}
}

Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
resurrection...
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
I saw Valentin�s instruction in my post. And am happy to be directed to this thread
Do a resurrection to thank Valentin
[ January 20, 2003: Message edited by: Ellen Fu ]
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Ok - slightly off the topic...
1 - Don't cram too much near the end.
2 - Get a good night's sleep.
3 - Drink water.
4 - Manage your time while taking the exam.
5 - Breathe !


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
Thanks Valentin for providing this link
I am confused with sun moons post

In this case why cast is necessary, even though it is super class?
Are the following points correct

Thanks
[ March 28, 2003: Message edited by: sun par ]

Sunita<br />SCJP 1.4
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
Hello Ajith
I wonder if you can explain the different between top-level nested class and inner-class.


Francis Siu
SCJP, MCDBA
sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
Top level nested class is a member class that is static.
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Sunita
I wonder if you can explain more details?
thank you for your attention
Badri Sarma
Ranch Hand

Joined: Apr 01, 2003
Posts: 72
Hi,
i think inner classes can also extend other class it is not limited to INTERFACES only
Check out

1)INNER CLASSES CAN EXTEND ONLY I INTERFACE

Badri


Thanks<br />Badri
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
Hi everybody
I am grateful if anyone can answer what are the different between inner-class and Top level nested class?
Jeff L.
Greenhorn

Joined: Sep 02, 2003
Posts: 8
I disagree with the claims of delayed final initialization. In particular this doesn't compile...
final xxx l;
l = new xxx();
***Edit: see my self-rebuttal to the above, two posts hence***
The rule is not that final variables can only be initialized once. The rule is final variables can only be initialized during declaration.
Also, NAN returns false when compared with NAN's too.
[ September 03, 2003: Message edited by: Jeff L. ]
 
Don't get me started about those stupid light bulbs.
 
subject: Traps to be aware of in any SCJP test !!!!! :)