aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Javaranch_javatips 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 "Javaranch_javatips" Watch "Javaranch_javatips" New topic
Author

Javaranch_javatips

Kishan Kumar
Ranch Hand

Joined: Sep 26, 2000
Posts: 130
friends,
These points were taken from maha anna discussion forumns.
hope it helps for last minute preperations.
Decleration and Access Control:
===============================
-------------------------------------------------------------------------------------------------
1. Private methods cannot be overridden because subclass dosent know that such a method exists
at all.
see the following example.
class b {
private void method() {
System.out.println("In superclass");
}
public void call {
method();
}

public class a extends b {
public static void main(String s[]) {
new b().g();
}
public method() {
System.out.println("In subclass");
}
}
Ans : In Superclass
-------------------------------------------------------------------------------------------------
Language Fundementals:
======================
-------------------------------------------------------------------------------------------------
1. Non Static inner classes can access
a. Final local variables.
b. Final method arguments.
c. Instance and class variables who are reffered to as fields.
-------------------------------------------------------------------------------------------------
2. String x = new String()
string y = new String("")
both create a empty string and this is NOT a null string.
-------------------------------------------------------------------------------------------------
3. Final varibales initialisation
a. All final can be intialised at the time of decleration.
b. static final variables can be initialised in the static block.
c. Instance final variables can be initialised in constructors.
WARNING:
Instance final variables should be intialised in ALL constructors
and each constructor may contain different values.
-------------------------------------------------------------------------------------------------
4. Static Inner does not have a outer class object and hence it will not be able to access
Instance fields and methods in the outer class. However an istance of outer class may be
created to achieve the goal.
-------------------------------------------------------------------------------------------------
5. Static member varibale of a static inner class which is referred to as top level class can be
accessed by
a. new outer().new inner().staticvariable//This will cause runtime verufy error.
b. new outer.inner().staticvariable
although the following seems correct, it is not right with jdk 1.2.
b. new outer().inner.staticVariable.
-------------------------------------------------------------------------------------------------
6. A char in octal representation can be specified by '\[digit1][digit2][digit3]'
char a = '\141';
WARNING: digit 1 should be in the range [0-3] if there are three digits, or else [0-7] should
be valid.
-------------------------------------------------------------------------------------------------
7. A class can have private constructors, In this case the class cannot be instantiated from
outside.
-------------------------------------------------------------------------------------------------
8. A static inner class hides the top level class for eg:
class B {};
class A extends B{
static class B {};
}
Class B when instaitiated within the class A the object corresponding to inner static class B
is instantiated.
-------------------------------------------------------------------------------------------------
9. An interface defined inside a class is implicitly static meaning it is a top level interface.
-------------------------------------------------------------------------------------------------
10. Primitives can have a wider conversion but primitive arrays cannot
ie. long a[] = new long[20];
int b[] = new int [20];
a = b; // NOT ALLOWED
-------------------------------------------------------------------------------------------------
11. with respect SJCP both keywords and reserved words are keywords!.
ie. null,true,false are keywords. //debatable!!!
-------------------------------------------------------------------------------------------------
12. Variables declared in subclass can hide superclass's declared variables, even final variables
Holds same for superinterfaces too. interface variables are implicitly static final, these
can be hidden in the class that implements by redefining the variables.
-------------------------------------------------------------------------------------------------
13. The sequence of execution in a class is
a. Static Initializers
b. Instance Initializers
c. Constructors.
-------------------------------------------------------------------------------------------------
14. Anonymous Instance class can be constructed not only in a method but also in static
and Instance initializers.
-------------------------------------------------------------------------------------------------
15. Constructos can have only public,protected and private access specifiers not anything else.
-------------------------------------------------------------------------------------------------
AWT
===
-------------------------------------------------------------------------------------------------
1. To place a component exactly on a container we use null layout.
-------------------------------------------------------------------------------------------------
2. Popup menu can be added to any component while menu bar can be added only to Frames.
-------------------------------------------------------------------------------------------------
3. GridLayout.
a. If rows is specified as zero then as many rows that are required are formed.
b. If columns are specified zero then as many columns that are required are formed.
c. Both rows and columns cannot be zero however it accepts an empty constructor which gives
one row and required numnber of columns equivalent to (1,0).
d. Components are placed in left-right,top-bottom fashion.
-------------------------------------------------------------------------------------------------
4. GridBagLayout,
gridx,gridy : where to place the component, x,y coordinates of top left xorner of the comp.
gridwidth,gridheight : how many cells to occupy.
fill : How to fill the remaining space if there is any,
anchor : where to place the component if there is more space than the required for the comp.
If fill is set anchor has no meaning but not the other way round. always fill gets the choice.
-------------------------------------------------------------------------------------------------
5. It is enough for a frame to be set setVisible(true) for it to be displayed, it has size 0,0
here. IT is visible but only top border is displayed
-------------------------------------------------------------------------------------------------
6. If the same component is added to different containers then the last container to which
component is added has the component and rest does not have it. Actually what happens is the
component reference is moved to the container object, not copied to, thus only the last
container has the component.
-------------------------------------------------------------------------------------------------
7. pack() is simillar to setsize(), it shows the frame enough to hold the specified component.
show() is simillar to setVisible(true). Both are methods of Window class.
-------------------------------------------------------------------------------------------------
8. In BorderLayout resizing the container will never change the height of North and South
component and the width of the component in the East and West will never change when
container is resized. Only the centre component resizes to fit the available space.
-------------------------------------------------------------------------------------------------
9. setBounds() does not call validate(). It should be called explicitly. pack() calls the
validate() implicitly.
-------------------------------------------------------------------------------------------------
10. FlowLayout by default arranges the components to centre of the container.
-------------------------------------------------------------------------------------------------
11. In BorderLayout first all the edges are filled and then the remaining is given to centre.
When resized edges stay in same thickness, centre resizes to fit to the resized container.
-------------------------------------------------------------------------------------------------

FLOW CONTROL AND ECEPTIONS
==========================
1. RandomAccess Files creates a new file if the file does not exist if it is opened in the "rw"
mode. If already present the info is appended to the file unlike Fileoutputstream which
rewrites the file.
-------------------------------------------------------------------------------------------------
2. Both JVM and program can throw exceptions.
-------------------------------------------------------------------------------------------------
tips:
=====
1. to_string() method of a string when given a string gives the same object, it does not create
a new one.
2. a null can be passed to a method expecting a string argument not to anything else.
3. A vector class is public implements java.util.list and is NOT final.
4. A String class is final,public and serializable and can take StringBuffer as an argument.
5. Java.lang.Exception is public serializable and extends Throwable.
6. All wrapper classes are public immutable, serializable and are final.
7. min(0.0,-0.0) gives -0.0
8. If space is available after resizing a border layout container the etra space is given
in the order north,south,west,east,center
9. addition of a componenet in the same region makes the component to be removed from the
container.
10. Component class is abstract whereas container class is not.
11. Checkbox responds only to ItemListener.
12. A explicit cast is needed to convert byte to a char even thought it is a narrowing
conversion.
byte b = 65;
char a = b; //NOT LEGAL.
char a = (char)b; //Gives a = 'A';
13. static initializers cannot be written in a interace. classes and interfaces declared
inside the interface are implicitly static.
14. getX() method of the mouseevent returns the position with respect to the component on
' which event is generated.
15. An anonymous inner class is not assumed to always extend object.
16. LayoutManager2 is an interface
18. The only way to check for a null reference is if(x == null);
19. Enumeration is a interface in java.util, vector and dictionary class implement them to
obtain the contained element.
20. Dictionary is a abstract class.
21. When Interrupt is issued on a waiting thread it goes to ready state and when it gets
the cpu then the InterruptedException is thrown.
22. A waiting thread becomes ready when
1. notify,notifyall is issued by a thread holding the lock on the object on which the
waiting thread was waiting.
2. Interrupt method is invoked.
3. when the number of milliseconds specified in the wait method elapses.
23. The wait causes the thread to unlock obly this lock, all other object locks if this
thread is holding will not be released.
24. If wait and notify are not invoked in a synchronized code then a IllegalMonitorState
exception is thrown.
25. Yield does not give up the lock on the object it is holding. Yield never gives control
threads with lower priority than its.
26.

Media Tracker.
--------------
Utility class that tracks the images being downloaded from the web.
MediaTracker(Component comp) is the constructor.
addImage(Image img, int id) this adds the image to the tracker with the priority specified by
the integer. The lower the number the higher the priority.
boolean checkAll() checks if all images are loaded. Returns true even if loading had encountered
errors.
boolean checkAll(boolean value) if value is true then it starts loading the unloaded images and
does the same thing as above.
boolean isErrorAny() returns true if loading encountered any errors.
object[] getErrorsAny() returns the media objects which encountered error.
void waitForAll() loads all media objects and if encountered then it is assumed as loaded.
void waitForAll(long msec) loads all media objects till the specified time
boolean checkID(int id) same as checkAll but for the priority specified nedia objects are checked
object[] getErrorsID(int id) same as explained above but only media objects of specified priority
are taken in to account.
waitForID(int id) same as above but for the specified priority.
waitForID(long msec) same as above but for the specified priority.
removeImage(Image image)

Thanks,
V. Kishan Kumar.



Regards,<BR>V. Kishan Kumar
Harpal Singh
Ranch Hand

Joined: Oct 10, 2000
Posts: 229
Kishan,
People like you make life so easy yaar....Thanks a ton for these great notes...........we shld all learn from from you....
Harpal
Jonathan Jeban
Ranch Hand

Joined: Oct 08, 2000
Posts: 52
Wow Kishen!
Thats a great work!
Surely its helpful.
I guess now there is no need to concentrate on Media tracker,
right?
Cheers,
Jeban
Kishan Kumar
Ranch Hand

Joined: Sep 26, 2000
Posts: 130
jeban,
You are right, I did not get any question on media tracker or
sockets. Once can safely leave it.
thanks
V. kishan Kumar
Aru Ven
Ranch Hand

Joined: Sep 28, 2000
Posts: 199
Kishan,
Thx for sharing ur work....
I have a point to make...
Kishen : a null can be passed to a method expecting a string argument not to anything else.
A null can be passed to a method expecting StringBuffer also.
Thanks,
Aruna
 
jQuery in Action, 2nd edition
 
subject: Javaranch_javatips
 
Similar Threads
inner class
NOTES FROM VELMURUGAN'S SITES:
Study Notes from a person who secured 100%.
inner classes
why I need to define a parameter variable as final?