Inter thread communication in Java

Arjun Thakur
Published on 19-Sep-2018 08:49:57
If you are aware of interprocess communication then it will be easy for you to understand interthread communication. Interthread communication is important when you develop an application where two or more threads exchange some information.There are three simple methods and a little trick which makes thread communication possible. All the ... Read More

instanceof operator vs isInstance method in java

Chandu yadav
Published on 19-Sep-2018 08:44:33
isInstance method is equivalent to instanceof operator. The method is used in case of objects are created at runtime using reflection. General practice says if type is to be checked at runtime then use isInstance method otherwise instanceof operator can be used. See the example below −Example Live Demopublic class Tester{ ... Read More

instanceof Keyword in Java

George John
Published on 19-Sep-2018 08:34:17
This operator is used only for object reference variables. The operator checks whether the object is of a particular type (class type or interface type). instanceof operator is written as −( Object reference variable ) instanceof (class/interface type)If the object referred by the variable on the left side of the ... Read More

instance variable hiding in Java

Ankith Reddy
Published on 19-Sep-2018 08:25:32
A local variable of same name will hide the instance variable. In order to use the instance variable, we should use the this operator. See the example below −Example Live Demopublic class Tester{    int a = 1;    public static void main(String[] args) {       Tester t ... Read More

Instance variable as final in Java

Arjun Thakur
Published on 19-Sep-2018 08:20:25
final is a non-access modifier for Java elements. The final modifier is used for finalizing the implementations of classes, methods, and variables. A final instance variable can be explicitly initialized only once.A final instance variable should be initialized at one of the following occasions −At time of declaration.In constructor.In instance ... Read More

Inner class in Java

George John
Published on 19-Sep-2018 08:09:32
Nested ClassesIn Java, just like methods, variables of a class too can have another class as its member. Writing a class within another is allowed in Java. The class written within is called the nested class, and the class that holds the inner class is called the outer class.SyntaxFollowing is ... Read More

Initialize HashSet in Java

Ankith Reddy
Published on 19-Sep-2018 07:50:51
A set is a collection which does not allows duplicate values. HashSet is an implementation of a Set. Following are the ways in which we can initialize a HashSet in Java.Using constructor − Pass a collection to Constructor to initialize an HashSet.Using addAll() − Pass a collection to Collections.addAll() to ... Read More

Infinity or exception in Java when divide by 0?

Arjun Thakur
Published on 19-Sep-2018 07:46:44
Consider the following code snippet where we divide a number by 0.Example Live Demopublic class Tester{    public static void main(String[] args) {       double d = 100;       System.out.println(d/0);    } }OutputInfinityNow consider the following code snippet.Example Live Demopublic class Tester{    public static void main(String[] args) ... Read More

Implement Runnable vs Extend Thread in Java

Chandu yadav
Published on 19-Sep-2018 07:26:59
We can create Thread by either by implementing a runnable interface or by extending Thread class. Below are the detailed steps of using both ways to create Thread.Create a Thread by Implementing a Runnable InterfaceIf your class is intended to be executed as a thread then you can achieve this ... Read More

C# program to find Intersection of two lists

Samual Sam
Published on 19-Sep-2018 07:17:10
To find intersection of two lists in C#, use the Intersect() method.The following is our list 1.List<int> list1 = new List<int>(); list1.Add(2); list1.Add(3); list1.Add(5); list1.Add(7);The following is our list 2.List<int> list2 = new List<int>(); list2.Add(5); list2.Add(4); list2.Add(6); list2.Add(8);The following is the code to find the intersection of two lists in ... Read More
Advertisements