Core java
- 06 February
Java FileWriter Example
The FileWriter class of java.io package makes writing to files in Java as easy as A-B-C. The FileWriter class writes to files as a stream of characters instead of bytes(as in FileOutputStream). Like its input-oriented counterpart FileReader, the FileWriter class is intended for writing “text” based files one character at a time. Let us look […]
- 05 February
Java program to find permutation and combination (nCr nPr)
In this tutorial, we will see java program to find permutation and combination. Permutation is represented as nPr and Combination is represented as nCr.It is simple program which involves factorial of the numbers. Here is formula to find permutation and combination (nCr nPr). nPr = factorial(n) / factorial(n-r) nCr = factorial(n)/(factorial(n-r) * factorial(r)) [crayon-67427e7f282f9258138845/] Output: Enter […]
- 30 January
Difference between early binding and late binding in java
Binding in Java refers to the process of associating a method or function body with a method or function call by the Java Compiler. In simpler words, when a function is called by the Java compiler the task of correctly locating the method for the respective function is binding. Depending on when the compiler is […]
- 24 October
Invoke Getters And Setters Using Reflection in java
In this post, we will see how to call getters and setters using reflection in java. We have already seen how to invoke method using reflection in java. There are two ways to invoke getter and setter using reflection in java. Using PropertyDescriptor You can use PropertyDescriptor to call getters and setters using reflection. Getter: […]
- 24 October
Java add to array
In this post, we will see how to add elements to the array. Using Apache’s common lang library You can use varargs add method to add elements to array dynamically. Here are the few add overloaded methods provided by ArrayUtils class If you want to add more than one element, you can use ArrayUtils’s addAll […]
- 22 October
Why wait(), notify() And notifyAll() methods are in Object Class
In this post, we will see why wait(), notify() And notifyAll() methods are in Object Class And Not in Thread Class. This is one of the most asked java multithreading interview questions. You might know that wait(), notify() And notifyAll() Methods are in Object class and do you know the reason for the same? Let’s […]
- 21 October
How to Sort HashSet in Java
In this post, we will see how to sort HashSet in java. HashSet is a collection which does not store elements in any order. You might come across a situation where you need to sort HashSet. There can be many ways to sort HashSet, we will see two methods here. Using TreeSet You can use […]
- 21 October
Difference between equals() and == in java
In this post, we will see about the difference between equals and == in java. This is most asked java interview question for fresher or 2-year experienced java developer and it might be confusing sometimes. Let’s try to understand each quickly. Equality operator “==” Equality operator can be used to compare primitives but when you […]
- 20 October
Java Array to Set
In this post, we will learn java array to set conversion. There are many ways to convert array to set. 1. Using Java 8’s Stream If you are using Java 8, I would recommend using Java 8 Stream. [crayon-67427e7f28d49307503463/] Output [John, Martin, Mary] 2. Using HashSet constructor() We can directly call HashSet‘s constructor for java […]