☕️JAVA Language Community
2.91K subscribers
144 photos
7 videos
31 files
42 links
☕️ Software, IT, Java, news
💻 IT highlights
🎯 AI update
🖥⌨️🖱
Download Telegram
#Java_Interview_Question

129) What is transient keyword?

If you define any data member as transient,it will not be serialized.

👉more details

▪️Java Transient Keyword

Java transient keyword is used in serialization. If you define any data member as transient, it will not be serialized.

Let's take an example, I have declared a class as Student, it has three data members id, name and age. If you serialize the object, all the values will be serialized but I don't want to serialize one value, e.g. age then we can declare the age data member as transient.

@javaCode☕️
#Java_Interview_Question

130)What is Externalizable?

Externalizable interface is used to write the state of an object into a byte stream in compressed format.It is not a marker interface.

@javaCode☕️
#Java_Interview_Question

131)What is the difference between Serializalble and Externalizable interface?

Serializable is a marker interface but Externalizable is not a marker interface.When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process.

@javaCode☕️
#Java_Interview_Question

132)How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com?

By InetAddress.getByName("192.18.97.39").getHostName() where 192.18.97.39 is the IP address.

@javaCode☕️
#Java_Interview_Question

133) What is reflection?

Reflection is the process of examining or modifying the runtime behaviour of a class at runtime.It is used in:

IDE (Integreted Development Environment) e.g. Eclipse, MyEclipse, NetBeans.
Debugger
Test Tools etc.

@javaCode☕️
#Java_Interview_Question

134) Can you access the private method from outside the class?

Yes, by changing the runtime behaviour of a class if the class is not secured.

@javaCode☕️
#Java_Interview_Question

👉Java Networking Terminology

The widely used java networking terminologies are given below:

1️⃣IP Address

2️⃣Protocol

3️⃣Port Number

4️⃣MAC Address

5️⃣Connection-oriented and connection-less protocol

7️⃣Socket

@javaCode☕️
#Java_Interview_Question

135) What is the difference between ArrayList and Vector?

1️⃣ArrayList is not synchronized.
Vector is synchronized.

2️⃣ArrayList is not a legacy class.
Vector is a legacy class.

3️⃣ArrayList increases its size by 50% of the array size.
Vector increases its size by doubling the array size.

@javaCode☕️
#Java_Interview_Question

136) What is the difference between ArrayList and LinkedList?

1️⃣ArrayList uses a dynamic array. LinkedList uses doubly linked list.

2️⃣ArrayList is not efficient for manipulation because a lot of shifting is required. LinkedList is efficient for manipulation.

3️⃣ArrayList is better to store and fetch data. LinkedList is better to manipulate data.

@javaCode☕️
#Java_Interview_Question

137) What is the difference between Iterator and ListIterator?

Iterator traverses the elements in forward direction only whereas ListIterator traverses the elements in forward and backward direction.

1) Iterator traverses the elements in forward direction only. ListIterator traverses the elements in backward and forward directions both.
2) Iterator can be used in List, Set and Queue. ListIterator can be used in List only.

@javaCode☕️
👍1
#Java_Interview_Question

138) What is the difference between Iterator and Enumeration?

1) Iterator can traverse legacy and non-legacy elements.
Enumeration can traverse only legacy elements.
2) Iterator is fail-fast.
Enumeration is not fail-fast.
3) Iterator is slower than Enumeration.
Enumeration is faster than Iterator.

@javaCode☕️
#Java_Interview_Question

139) What is the difference between List and Set?

List can contain duplicate elements whereas Set contains only unique elements.

@javaCode☕️
👍1
#Java_Interview_Question

140) What is the difference between HashSet and TreeSet?

HashSet maintains no order whereas TreeSet maintains ascending order.

@javaCode☕️
#Java_Interview_Question

141) What is the difference between Set and Map?

Set contains values only whereas Map contains key and values both.

@javaCode☕️
👍2
#Java_Interview_Question

142) What is the difference between HashSet and HashMap?

HashSet contains only values whereas HashMap contains entry(key,value). HashSet can be iterated but HashMap need to convert into Set to be iterated.

@javaCode☕️
#Java_Interview_Question

143) What is the difference between HashMap and TreeMap?

HashMap maintains no order but TreeMap maintains ascending order.

@javaCode☕️
#Java_Interview_Question

144) What is the difference between HashMap and Hashtable?

1) HashMap is not synchronized. Hashtable is synchronized.
2) HashMap can contain one null key and multiple null values.

@javaCode☕️
👍1
#Java_Interview_Question

145) What is the difference between Collection and Collections?

Collection is an interface whereas Collections is a class.
Collection interface provides normal functionality of data structure to List, Set and Queue.
But, Collections class is to sort and synchronize collection elements.

@javaCode☕️
#Java_Interview_Question

👉The rules for #overriding a method are as follows:

* The argument list must exactly match that of the overridden method. If they don't match, you can end up with an overloaded method you didn't intend.

* The return type must be the same as, or a subtype of, the return type declared in the original overridden method in the superclass.

* The access level can't be more restrictive than the overridden method's.

* The access level CAN be less restrictive than that of the overridden method.

* Instance methods can be overridden only if they are inherited by the subclass. A subclass within the same package as the instance's superclass can override any superclass method that is not marked private or final. A subclass in a different package can override only those non-final methods marked pub- lic or protected (since protected methods are inherited by the subclass).

* The overriding method CAN throw any unchecked (runtime) exception, regardless of whether the overridden method declares the exception.

* The overriding method must NOT throw checked exceptions that are new or broader than those declared by the overridden method. For example, a method that declares a FileNotFoundException cannot be overridden by a method that declares a SQLException, Exception, or any other non-runtime exception unless it's a subclass of FileNotFoundException.

* The overriding method can throw narrower or fewer exceptions. Just because an overridden method "takes risks" doesn't mean that the overriding subclass' exception takes the same risks. Bottom line: an overriding method doesn't have to declare any exceptions that it will never throw, regardless of what the overridden method declares.

* You cannot override a method marked final.

* You cannot override a method marked static.

* If a method can't be inherited, you cannot override it. Remember that overriding implies that you're reimplementing a method you inherited!

@javaCode☕️
#Java_Interview_Question

👉The rules for #overloading a method are as follows:

■ Overloaded methods MUST change the argument list.

■ Overloaded methods CAN change the return type.

■ Overloaded methods CAN change the access modifier.

■ Overloaded methods CAN declare new or broader checked exceptions.

■ A method can be overloaded in the same class or in a subclass. In other words, if class A defines a doStuff(int i) method, the subclass B could define a doStuff(String s) method without overriding the superclass version that takes an int. So two methods with the same name but in different classes can still be considered overloaded, if the subclass inherits one version of the method and then declares another overloaded version in its class definition.

@javaCode☕️
👍2