JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label core java interview question. Show all posts
Showing posts with label core java interview question. Show all posts

What is difference between Overloading and Overriding in Java

3:48 AM
Overloading vs Overriding in Java 1) First and major difference between Overloading and Overriding is that former occur during compile time while later occur during runtime. 2) Second difference between Overloading and Overriding is that, you can overload method in same class but you can only override method in sub class. 3) Third difference is that you can overload static method in Java but you can not override static method in Java. In fact when you declare same method in Sub Class it's known as method hiding because it hide super class method instead of overriding it. 4) Overloaded methods are bonded using static binding and Type of reference variable is used, while Overridden method are bonded using dynamic bonding based upon actual Object. 5) Rules of Overloading and Overriding is different in Java. In order to overload a method you need to change its method signature but that is not required for overriding any method in Java. 6) Another difference between meth

ArrayList vs Vector in Java

3:44 AM
Common property of Vector and ArrayList in Java 1) Bother Vector and ArrayList are derived from AbstractList and implements List interface, which means both of them are ordered collection and allows duplicates. 2) Another similarity between Vector vs ArrayList is that both are index based Collection and you can use get(index) method to retrieve objects from Vector and ArrayList. Vector vs ArrayList in Java 1) First and most common difference between Vector vs ArrayList is that Vector is synchronized and thread-safe while ArrayList is neither Synchronized nor thread-safe. Now, What does that mean? It means if multiple thread try to access Vector same time they can do that without compromising Vector's internal state. Same is not true in case of ArrayList as methods like add(), remove() or get() is not synchronized. 2) Second major difference on Vector vs ArrayList is Speed, which is directly related to previous difference. Since Vector is synchronized, its slow and Arra

Can you make an abstract class/method final in Java?

3:34 AM
No, you cannot make an abstract class or method final in Java because abstract and final are the mutual exclusive concept . An abstract class is incomplete and can only be instantiated by extending a concrete class and implementing all abstract methods, while a final class is considered as complete and cannot be extended further. This means when you make an abstract class final, it cannot be extended hence it cannot be used and that's why Java compiler throws a compile time error when you try to make an abstract class final in Java Can we make an Abstract method final in Java Now that, you know there is no way you can make an  abstract class final  in Java, let's try to make an abstract method final in Java. As I said above, this time also Java compiler should complain because both  final  and  abstract  are mutual exclusive keywords: abstract class ImAbstract{ public final abstract void anAbstractMethod (); } class ImConcrete extends ImAbstract{ @Overrid

Difference between Heap and Stack Memory in Java JVM ?

3:31 AM
Difference between Heap and Stack Memory in Java JVM Heap memory is shared by all threads of Java application but Stack memory is local to each thread.  Objects are created in heap memory but method frames are stored in Stack memory, and size of heap space is much bigger than the small size of Stack in Java Stack vs Heap in Java As I told, both Stack and Heap space are part of JVM but they are used for different purpose, let's see some more points to understand the difference between stack and heap memory better. 1) Size One of the significant difference between Stack and heap comes from their size. Heap space in Java is much bigger than the Stack memory. This is partly due to the fact that whenever a new thread is created in JVM, a separate stack memory is allocated to them. 2) Resizing JVM allows you to resize both heap and stack in Java, though you need to use different JVM flags for that. You can use -Xms and -Xmx to specify the starting and maximum he

.