Java 8 for loop

Posted Posted in Core Java, Java 8

For loop in Java has changed a lot from the way it first appeared in jdk 1.   Here is an example of the classical for loop :  

  Java 5 added the forEach loop that made looping with collections easier as it removed declaration of the looping variable and checking length of […]

How to split a string in java

Posted Posted in Core Java

Here are some approaches to split a String in Java.   Using String.split() method Using StringTokenizer   Splitting a string using the split() method   Here is the syntax of the split() method :   public String[] split(String regex, [int limit])   Here, regex is a regular expression that will act as separator for the […]

Immutable in Java

Posted Posted in Core Java

  This articles focuses on the following : What is meant by an Immutable class in Java ? What is the advantage of an Immutable class ? How to create an Immutable class ? What happens when a variable or class is marked final ?   Immutability in Java An object is considered immutable if […]

Binary Search in Java

Posted Posted in Core Java, Java

This post explains : – Java code for binary search in list – searching lists in java – java code for recursive binary search – java code for iterative binary search   Searching List in Java If a list is not sorted, searching can only be done by element by element by comparison. So, its […]

Reverse a string in java

Posted Posted in Core Java, Java

If you are looking for the following, this article will be of help : – Reverse a string in Java without library functions – String reversal algorithm in java – Reverse a string using StringBuffer or StringBuilder   Reverse a String in Java   Java provides library methods in StringBuffer and StringBuilder to reverse a […]

fibonacci series in java

Posted Posted in Core Java, Java

This post addresses the following : – What is Fibonacci sequence – Write a java program for Fibonacci sequence – Fibonacci sequence in java   Fibonacci Series   Fibonacci series is a list of numbers, where next value in the series is the sum of previous two values.   In function notation, it is represented […]

Encapsulation in Object Oriented programming

Posted Posted in Core Java, Java

This article explains following concepts : What is encapsulation ? How is encapsulation different from abstraction ?   Encapsulation: Encapsulation means working as a container for data or objects. In Java, Classes encapsulate properties and method by working as a container for them. Packages work as encapsulation for related classes.   Encapsulation can be used […]