Deprecated: Assigning the return value of new by reference is deprecated in /home/w3hja33/public_html/wp-includes/cache.php on line 99

Deprecated: Assigning the return value of new by reference is deprecated in /home/w3hja33/public_html/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/w3hja33/public_html/wp-includes/theme.php on line 576
Orkut | w3hJava

w3hJava

What, Why, When and How of Java, JavaFX and related technologies


Published January 4th, 2009

JavaFX and Java Community for orkut users.

For JavaFX enthusiastic developer and designers, I have created one Orkut community, please feel free to share your experience or problem.

Here is the link for “JavaFX Developers And Designers”

For Java, I already have a 4-5 year old community. Feel free to discuss Java topics here.
I am very happy with the strength of this community now, which is around 20000. We worked continuously to remove all spams and useless topics.

Published June 4th, 2008

Final can improve performace !

Last month, me and Abhishek was discussing about some performance issue. Finally we came on a good conclusion and so I decided to write a blog. One of the Orkut users posted a question on our community

“As we know that by declaring method as final, we cant override them. By performing this function, it provides a performance enhancement but i unable to understand how ????? can anyone help me out…… “

(I don’t know why people are using so many of dots and question marks)

Yes this is correct, writing final (can) improve the performance. WHY ?
When you define a method final, that means it can’t be overridden into its derived classes. Knowing that into the fact complier (can) inline that method into its derived classes. But but but, this is not a safe way to inline a method. WHY AGAIN ?
Because, if by any chance if method will not be final (fool the VM) in base class, then inline entry in derived class will be wrong and things can be screwed. Now very rare but this is possible in Java. Remember in Java you can write your own ClassLoader and you can make a ClassLoader where you can ignore(any how) the final declaration.
So, for those compiler in which final method be inlined before loaded into VM(unlike JIT), there is quite a high risk and hence compiler can’t do this. But in JIT compiler, this is what is happening !

In 2 line, I want to write about JIT(Just in time compiler) - at the time of interpretation,interpreter saw there is a for loop, for say 50 times. It takes the code out from interpreter and give it to runtime compiler(c1 and c2 compiler). As we know compilation is faster than interpreter. Compiler do the work and then control goes back to Interpreter. Details are quite interesting.

And this is how we finally ended our discussion :). Correct me if I am wrong.

In next post, we will discuss how to write a custom ClassLoader.

Published May 23rd, 2008

Java - Pass by Reference(Not possible)

I had a big time fight on my Orkut community with the concept that Java do things with Pass by Reference. Here is the one for Orkut users :

Here

But for non-orkut users let me recap the point again, its very important for a person who is new in java:

There is NO CONCEPT OF CALL BY REFERENCE IN JAVA, ONLY CALL BY VALUE IS POSSIBLE. We generally get confused in pass the object reference by value and passing by reference. Both are completely different.

Here is a small code, to get a more clear picture:

class MyClass {

String name;
int nameCode;

public MyClass(String name, int nameCode) {
this.name = name;
this.nameCode = nameCode;
}

public String toString() {
System.out.println(name + " : " + nameCode);
return (name + nameCode);
}
}

public class NoCallByReference {

public static void swap(MyClass a, MyClass b) {
MyClass temp = a;
a = b;
b = temp;
}

public static void main(String[] args) {
MyClass myclass = new MyClass(”Ramu”, 7);
MyClass yourclass = new MyClass(”Mohan”, 1);
swap(myclass, yourclass);
myclass.toString();
yourclass.toString();
}
}

A very simple code where I tried to swap two object of myClass. But you will surprise to see the output because after swapping even the value of myclass and yourclass will remain the same. Because the copy of myclass and yourclass has been created and get swapped rather than actual myclass and yourclass. It’s like

myclass — copyofmyclass
yourclass — copyofyourclass

Swapping is done on copyofmyclass and copyofyourclass. Better to go for a homework and run the command

javap -c NoCallByReference and try to figure our how assemble is going on :-).