Found 4338 Articles for Java 8

Java program to check occurence of each vowel in String

Chandu yadav
Updated on 25-Jun-2020 14:16:42

538 Views

To count occurence of vowels in a string again use Map utility of java as used in calculating occurence of each character in string.Put each vowel as key in Map and put initial value as 1 for each key.Now compare each character with key of map if a character matches with a key then increase its corresponding value by 1.Examplepublic class OccurenceVowel {    public static void main(String[] args) {       String str = "AEAIOG";       LinkedHashMap hMap = new LinkedHashMap();       hMap.put('A', 0);       hMap.put('E', 0);       hMap.put('I', 0);       hMap.put('O', 0);       hMap.put('U', 0);       for (int i = 0; i

Print a 2D Array or Matrix in Java

George John
Updated on 14-Sep-2023 01:39:23

28K+ Views

In this post we will try to print an array or matrix of numbers at console in same manner as we generally write on paper.For this the logic is to access each element of array one by one and make them print separated by a space and when row get to end in matrix then we will also change the row.Example Live Demopublic class Print2DArray {    public static void main(String[] args) {       final int[][] matrix = {          { 1, 2, 3 },          { 4, 5, 6 },          { 7, 8, 9 }       };       for (int i = 0; i

Primitive Wrapper Classes are Immutable in Java

Arjun Thakur
Updated on 25-Jun-2020 14:06:49

1K+ Views

In Java Immutable class is a class which once created and it's contents can not be changed.On same concept Immutable objects are the objects whose state can not be changed once constructed.Wrapper classes are made to be immutable due to following advantages −Since the state of the immutable objects can not be changed once they are created they are automatically synchronized.Immutable objects are automatically thread-safe, the overhead caused due to use of synchronisation is avoided.Once created the state of the wrapper class immutable object can not be changed so there is no possibility of them getting into an inconsistent state.The ... Read More

POJO vs Java Beans

George John
Updated on 25-Jun-2020 14:07:32

4K+ Views

As we know that in Java POJO refers to the Plain old Java object.POJO and Bean class in Java shares some common features which are as follows −Both classes must be public i.e accessible to all.Properties or variables defined in both classes must be private i.e. can't be accessed directly.Both classes must have default constructor i.e no argument constructor.Public Getter and Setter must be present in both the classes in order to access the variables/properties.The only difference between both the classes is Java make java beans objects serialized so that the state of a bean class could be preserved in ... Read More

POJI in Java

Ankith Reddy
Updated on 25-Jun-2020 14:07:52

354 Views

POJI is an acronym for Plain Old Java Interface which corresponds to a Java standard interface which means that these interfaces are in the context of providing services in JEE. For example, OSGI service is offered through POJI in JEEIn other terms we can say that POJI is an ordinary interface without any specialty that is not inherited from any of the technology API specific interfaces or framework interfaces.Exampleinterface myCustomInterface {    public void myMethod(); } interface mySecondCustomInterface extends myCustomInterface {    public void mySecondMethod(); }Both interfaces would be called as POJI as they do not inherit any technology specific ... Read More

Passing and Returning Objects in Java

Chandu yadav
Updated on 25-Jun-2020 14:08:38

4K+ Views

As we know it is core concept that in Java there is always pass by value and not by pass by reference.So in this post we will focus on that how this concept get validated in case of passing primitive and passing reference to a method.In case when a primitive type is passed to a method as argument then the value assigned to this primitive is get passed to the method and that value becomes local to that method, which means that any change to that value by the method would not change the value of primitive that you have ... Read More

Constructor Chaining In Java programming

Rudradev Das
Updated on 29-Dec-2023 18:36:32

656 Views

The constructor chaining is a particular sequence of injecting constructors when an user initialize an object in a particular method. This process can be used when we invoke a bulk number of constructors one by one only on the basis of the instance class. This process is an another method linked with the inheritance where the task of a sub-class constructor to call a super class constructor. Constructor chaining can be performed in two ways in Java − Within same class − The process can be done by the using of this() keyword for the constructors present in the same class. From base class − by using the ... Read More

synchronized Keyword in Java

Ankith Reddy
Updated on 23-Jun-2020 15:32:55

2K+ Views

When we start two or more threads within a program, there may be a situation when multiple threads try to access the same resource and finally they can produce unforeseen result due to concurrency issues. For example, if multiple threads try to write within a same file then they may corrupt the data because one of the threads can override data or while one thread is opening the same file at the same time another thread might be closing the same file.So there is a need to synchronize the action of multiple threads and make sure that only one thread ... Read More

ListIterator in Java

Arjun Thakur
Updated on 23-Jun-2020 15:23:49

296 Views

The java.util.LinkedList.listIterator(int index) method returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list.DeclarationFollowing is the declaration for java.util.LinkedList.listIterator() methodpublic ListIterator listIterator(int index)Parametersindex − index of the first element to be returned from the list-iteratorReturn ValueThis method returns a ListIterator of the elements in this list (in proper sequence), starting at the specified position in the listExceptionIndexOutOfBoundsException − if the index is out of rangeExampleThe following example shows the usage of java.util.LinkedList.listIterator() method.Example Live Demopackage com.tutorialspoint; import java.util.*; public class LinkedListDemo {    public static void main(String[] args) { ... Read More

Java 8 Optional Class

Chandu yadav
Updated on 23-Jun-2020 15:24:33

275 Views

Optional is a container object used to contain not-null objects. Optional object is used to represent null with absent value. This class has various utility methods to facilitate code to handle values as 'available' or 'not available' instead of checking null values. It is introduced in Java 8 and is similar to what Optional is in Guava.Class DeclarationFollowing is the declaration for java.util.Optional class −public final class Optional extends ObjectClass MethodSr.No.Method & Description1static Optional empty()Returns an empty Optional instance.2boolean equals(Object obj)Indicates whether some other object is "equal to" this Optional.3Optional filter(PredicateRead More

Advertisements