JB Ramesh

Greenhorn
+ Follow
since Jan 09, 2007
Merit badge: grant badges
For More
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 JB Ramesh

Thanks Eric for the valuable information.
Hi,

I want to know the solution for an issue I am facing. I am using modal window in my application. I am using following snippet to open a modal window.




I am passing status as 0 in attributes. so that the window will not show status bar. this is working perfectly when i deployed into windows machine. But the status will get shown when I deploy the application into a solaris machine.

In both cases I am accessing the application from my local machine using IE 6.0 . This is driving me nuts.....

I dont know why the pop-up status bar shown when it is deployed into solaris server. The application code is same in both servers.

Please let know if you any idea on this issue.


Thanks in advance.
[ October 01, 2007: Message edited by: JB Ramesh ]
Hi,

Can anyone suggest good book for preparing SCEA exam ? I am having 3.5 years of experience and worked with J2EE projects.
Hi,

Can anyone suggests me a good book for "Software Design Patterns". I want to know the book dealing design pattenrs in Object oriented manner.


Thanks in advance.
17 years ago
does anyone know the reason behind this ?

Why arithmetic exception happens for int and not for float ?
[ March 28, 2007: Message edited by: JB Ramesh ]

class Program {
public static void main(String[] args) {
Integer i1 = 20;
Integer i2 = 20;
Integer i3 = 201;
Integer i4 = 201;
System.out.println(i1 == i2);
System.out.println(i3 == i4);
}
}

it is giving an output

true
false

why so?




You executed this code in JDK 5.0. Please refer "Boxing" concept which is a new feature in 5.0

While boxing same reference is used if the range is from -128 to 127. Thats why i1 and i2 refers same Object. i3 and i4 are more than 127. So refers different objects.

Consider this code:
public class Boxing3 {
public static void main(String[] args) {
int i = 10;
method(i);
}
static void method(Long l){
System.out.println("Widening conversion");
}
}



The rule here is "primitive values should be boxed and then widened. Not widened and then Boxed"

int i is boxed into Integer. And Integer tries to find method having Integer as parameter or widened reference(eg: object) as paramter. As it cant find method,compilation fails.
[ March 21, 2007: Message edited by: JB Ramesh ]

Secondly we are not making gc smarter by explicitly calling gc. In your simple program the code would generally complete much earlier if you remove the explicit calls.



Correct. you are concerning about the performance. But Garbage collection deals with JVM Memory.


I mean what would you do with the free memory when you do not need it?



Yes. when we dont need free space, we dont need to worry about GC. What about when you need it ? if we consider Data and memory, it makes difference. Consider about data structures and manupulation on data. If a program constructs huge number of objects and operates on that, then memory plays important role there. Ther we can optimize the program to address problem with free space and memory leake by using GC.

[ March 21, 2007: Message edited by: JB Ramesh ]
[ March 21, 2007: Message edited by: JB Ramesh ]

explicit gc call is not required for and gc is generally smart enough to figure out when to gc



Absolutely correct . GC is smart enough. But explicit call to Systme.gc() always makes chance for GC to become more smart

Here is the code suggested by srinivasan



Here the explicit call System.gc() makes GC more smart
and gives us more free space. If we very much concern about memory free space, explicit GC call will make difference.
[ March 21, 2007: Message edited by: JB Ramesh ]

base b = new a();
System.out.println("m " + b.method() + " x " + b.x);



Here method() is overridden in child class. And method invocation is based on Runtime Object which is "new a()". So child class method is executed.

Overridden applicable only to methods. not variables. Instance plays main role when variables are accessed. so b.x gives parent class variable.
The reason is all arrays are implicitly object. So the first assignment is compatible.

Second line gives error becoz of incompatibility.
[ March 20, 2007: Message edited by: JB Ramesh ]
I also want to know why empty file is allowed by compiler. Anyway while runnning it will give runtime error.

And that file can not be referred as an object also. Then why java creaters allow the empty file ? The compiler can ignore it right ?

Is there any technical funda behind this ??
[ March 20, 2007: Message edited by: JB Ramesh ]

-------------------------------------------------------------
i am confused regarding order of execution?
is it:
static initializers and static variables first and then instance initializers and instance variables?please clear my doubt or is it in the order of declaration?
--------------------------------------------------------------



Consider the following program

class Parent{

static int statVar=10;
int initVar=100;

static {
System.out.println("static1 - parent "+statVar);
}

{
System.out.println("instance init1 - parent "+initVar);
}

Parent(){
System.out.println("Constructor - parent");
}

static {
System.out.println("static2 - parent");
}

{
System.out.println("instance init2 - parent");
}


}

public class Child extends Parent{

static {
System.out.println("static1 - Child");
}

{
System.out.println("instance init1 - child");
}

Child(){
System.out.println("Constructor - child");
}

static {
System.out.println("static2 - child");
}

{
System.out.println("instance init2 - child");
}


public static void main(String[] args) {
new Child();
}
}


The output will be

static1 - parent 10
static2 - parent
static1 - Child
static2 - child
instance init1 - parent 100
instance init2 - parent
Constructor - parent
instance init1 - child
instance init2 - child
Constructor - child

We can have conclusion about order of execution like following

1. static variables and then Static initializers throghout the inheritance hienrarchy as per coding order.
2. Following will happen for individual classes from the top of the hierarchy
a. instance variables and then instance inializers
b. constructor
----------------------------------------
12. void doStuff3() {
13. X x = new X();
14. X y = doStuff(x);
15. y = null;
16. x = null;
17. }
18. X doStuff(X mx) {
19. return doStuff2(mx);
20. }//here answer is not sure when object created at line 13 is garbage collected but outside the method we have made the references null so why is it not garbage collected?
-------------------------------------------

Yes. The answer is "not sure when object created at line 13 is garbage collected" because we dont know about doStuff2() method. And refernce 'mx' is passed into that method. within that method that reference may or may not be retained. So answer is right.
-------------Code----------------------------------------------------
package bindaas1;

public class Animal {

protected void eat() {
System.out.println("Animals prefer idali vada");
}
}

package bindaas2;
import bindaas1.Animal;

class Dog extends Animal {

}


public class Beagal extends Dog{

public static void main(String ... args) {
Dog d1 = new Beagal(); // Line 1
d1.eat();// Line 2
((Beagal)d1)).eat(); // Wroks ??? - Line 3
}
}
-----------------------------------------------------------

in the above code Line 2 does not compile. This is fine as eat() method is protected and available only in child class Dog. But Why Line 3 compiles fine ? d1 is casted int Beagal. But protected is not visible below one child level. Then how it compiles ?

Thanks in advance.
[ March 17, 2007: Message edited by: Ramesh J ]