Nagarajan Subramanian

Greenhorn
+ Follow
since Mar 18, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nagarajan Subramanian

Congratulations Michael
I had the same feeling when I passed the exam.
Venkat
20 years ago
Thanks everybody.
I consider this as the first step. I have a background of procedural programming for too many years. 10+ years of AS/400 - RPG to be exact. I have a long way to go.
Venkat
20 years ago
I have always been an observer at this site.
This site is the best, I would say, to get certified. And, JQPLUS - it is too good. Some of the questions I got today were similar to the JQPLUS questions.
I used Khalid's book to prepare and took Marcus's mock exam, Sun's mock exam.
Thanks again to the people who manage and participate in this website.
Venkat
20 years ago
Hello Jeena,
From what I could gather from Khalid Mughal, the yield() method is used to relinquish processor resources (CPU). I do not think it will relase the lock on the monitor. This is more to do with processor resource sharing rather than object locks I believe.
So if a thread is waiting for an object lock and a second thread has the object lock, executing the yield() method in the second thread should not relase the object lock.
Somebody please correct me if wrong.
Thanks
Hello Priya,
I will try to answer your question.
- The scope for local variables is from the declaration statement to the end of the block. So if I had switch statement like
switch (i) {
case 1:
j = 30; // line 1
case 2:
int j = 10; // line 2
System.out.println(j); // line 3
}
This code will not compile because at line 1 variable j is not defined so scope is not for entire switch statement.
- in your code, if line 1 is commented out, there exists a path of execution that will use a local variable that has not been ASSIGNED. (System.out.prinln(j). Read this
From JLS quote:
-------
Definite Assignment
-------------------------------------------
Each local variable (�14.4) and every blank final (�4.5.4) field (�8.3.1.2) must have a definitely assigned value when any access of its value occurs. A Java compiler must carry out a specific conservative flow analysis to make sure that, for EVERY ACCESS of a local variable or blank final field f, f is definitely assigned before the access; otherwise a compile-time error must occur.
-------------------------------------------
Hope that helps
Hello Ash,
The equals method is specified in the Object class and checks if two object references actually point to the the same object. It does not check the contents of the objects. Other classes override the equals method to provide that functionality. For example the String class overrides the equals method to check if two strings are the same - contentwise.
The Stringbuffer class does not override the equals method so Stringbuffer objects use the equals method in the Object class and hence the result of sb1 not being equal to sb2 as they are different objects and nothing prints
The == method checks if two object reference point to the same object. For primitives it checks the contents.
Hope this helps.
Thanks
Hello nt,
Are you sure that class B will compile. I tried and it looks for the default contructor in class A.
I believe the rule is that if you specify a contructor with arguments the system will not supply the default constructor and you need to make sure that all references to this class will use the contructor with arguments or you specify a default contructor yourself. And any subclasses need to explicitly call one of the constructors you have specified, using the super(args) statement or else the system will try implicitly call the default constructor and fail. When constructors in the subclass are chained using the this() statement, the last one needs to call the superclass contructor.
Thanks
Hi jeena,
I will try to explain this one.
1) The start method is defined in the the Thread class and not in the Runnable interface. So when you define the start method, you are not implementing a method in the interface but it is your own new method. When t1.start() is executed, it will call the start method if Thread object t1 which in turn will call the run() method in Thread t1 which in turn will call the run() method in the Runnable object t.
This is from JDK docs:
-------
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
------
2) In this class you have extended the Thread class and are overriding the start method. The start method in the Thread class has been defined already to call the run() method in the same class but since you have overridden it, the functionality is lost. If the you remove the start method in this case, you will the run() method execute.
Fromt the JDK docs:
--------
Start method
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
----------

Anybody, please correct me if wrong.
Thanks
Hi all,
I found this in JLS which explains the reason why the system behaves this way it try-catch-finally constructs.
quote:
-----------
14.16 The return Statement
A return statement returns control to the invoker of a method (�8.4, �15.12) or constructor (�8.8, �15.9).
ReturnStatement:
return Expressionopt ;
A return statement with no Expression must be contained in the body of a method that is declared, using the keyword void, not to return any value (�8.4), or in the body of a constructor (�8.8). A compile-time error occurs if a return statement appears within an instance initializer or a static initializer (�8.7). A return statement with no Expression attempts to transfer control to the invoker of the method or constructor that contains it.
To be precise, a return statement with no Expression always completes abruptly, the reason being a return with no value.
A return statement with an Expression must be contained in a method declaration that is declared to return a value (�8.4) or a compile-time error occurs. The Expression must denote a variable or value of some type T, or a compile-time error occurs. The type T must be assignable (�5.2) to the declared result type of the method, or a compile-time error occurs.
A return statement with an Expression attempts to transfer control to the invoker of the method that contains it; the value of the Expression becomes the value of the method invocation. More precisely, execution of such a return statement first evaluates the Expression. If the evaluation of the Expression completes abruptly for some reason, then the return statement completes abruptly for that reason. If evaluation of the Expression completes normally, producing a value V, then the return statement completes abruptly, the reason being a return with value V. If the expression is of type float and is not FP-strict (�15.4), then the value may be an element of either the float value set or the float-extended-exponent value set (�4.2.3). If the expression is of type double and is not FP-strict, then the value may be an element of either the double value set or the double-extended-exponent value set.
It can be seen, then, that a return statement always completes abruptly.
The preceding descriptions say "attempts to transfer control" rather than just "transfers control" because if there are any try statements (�14.19) within the method or constructor whose try blocks contain the return statement, then any finally clauses of those try statements will be executed, in order, innermost to outermost, before control is transferred to the invoker of the method or constructor. Abrupt completion of a finally clause can disrupt the transfer of control initiated by a return statement.
----
My two cents.
Thanks
Hello Shah,
This is what I could find out.
The GridLayout class has three constructors.
1. GridLayout()
2. GridLayout(int Rows, int Columns)
3. GridLayout(int Rows, int Columns, int Hrgap, int Vrgap)
Constructor 1 is equivalent to 1 row and 0 columns.
In constructors 2 and 3, either rows or columns can be zero but not both.
According to Khalid Mughal components are added left to right, top to bottom (row-major) in the container. The geometry of the grid is determined by the non-zero parameter (row or column) and the number of components added.
So
1. if the number of rows is non-zero then the number of columns is ignored and the JVM figures out the number of columns based on the number of components being added to the container
Example. if rows = 4 and 3 components are being added then you will see a gid layout with one column with 3 components and a blank row at the bottom
Example. if rows = 4 and 9 components are being added number 1 thru 9 then you will a grid with 4 rows and three columns and the components will be filled row first
1 2 3
4 5 6
7 8 9
blank row
2. if number of rows is zero and number of columns is non-zero then the number of columns stay fixed and number of rows will depend upon the number of components being added
Example. if columns = 2 and 3 components are added
then two rows will be needed and the components are added row-major so you will see
1 2
3 blank
Example if columns = 4 and 2 components are added then you will see
1 2 blank blank
3. If both rows and columns are specified then the number of rows stays fixed and number of columns is figured out based on number of components added.
I hope I got this one right
Thanks
Hello Prasanna,
I found this in JLS,
15.13.1 Runtime Evaluation of Array Access
An array access expression is evaluated using the following procedure:
First, the array reference expression is evaluated. If this evaluation completes abruptly, then the array access completes abruptly for the same reason and the index expression is not evaluated.
Otherwise, the index expression is evaluated. If this evaluation completes abruptly, then the array access completes abruptly for the same reason.
Otherwise, if the value of the array reference expression is null, then a NullPointerException is thrown.
Otherwise, the value of the array reference expression indeed refers to an array. If the value of the index expression is less than zero, or greater than or equal to the array's length, then an ArrayIndexOutOfBoundsException is thrown.
Otherwise, the result of the array access is the variable of type T, within the array, selected by the value of the index expression. (Note that this resulting variable, which is a component of the array, is never considered final, even if the array reference expression is a final variable.)
15.13.2 Examples: Array Access Evaluation Order
In an array access, the expression to the left of the brackets appears to be fully evaluated before any part of the expression within the brackets is evaluated. For example, in the (admittedly monstrous) expression a[(a=b)[3]], the expression a is fully evaluated before the expression (a=b)[3]; this means that the original value of a is fetched and remembered while the expression (a=b)[3] is evaluated. This array referenced by the original value of a is then subscripted by a value that is element 3 of another array (possibly the same array) that was referenced by b and is now also referenced by a.
Thus, the example:

class Test {
public static void main(String[] args) {
int[] a = { 11, 12, 13, 14 };
int[] b = { 0, 1, 2, 3 };
System.out.println(a[(a=b)[3]]);
}
}
prints:
14
because the monstrous expression's value is equivalent to a[b[3]] or a[3] or 14.