Found 2616 Articles for Java

Can a diamond operator be used with an anonymous inner class in Java 9?

raja
Updated on 21-Feb-2020 12:18:26

102 Views

Yes, we can use the diamond operator with an anonymous inner class since Java 9.The purpose of using a diamond operator is to avoid redundant code and make it more readable by no longer using a generic type on the right side of an expression. The diamond operator used only for normal classes but not for anonymous inner classes in Java 7. If we try to use it for anonymous inner classes, the compiler throws an error.In the below example, we have used a diamond operator with an anonymous inner class.Exampleimport java.util.*; public class DiamondOperatorTest {    public static void main(String args[]) {       String[] str = ... Read More

What are the new features added to Stream API in Java 9?

raja
Updated on 21-Feb-2020 12:20:30

96 Views

In Java 9, Oracle Corporation has added four useful new methods to Stream API. Those methods are iterate(), ofNullable(), takeWhile() and dropWhile().iterate()The iterate() can be used as stream version replacement of traditional for-loops. This method has improved by adding another parameter, the Predicate interface that allows us to stop these endless numbers based on conditions defined with the Predicate interface.Exampleimport java.util.stream.Stream; public class StreamIterateMethodTest {    public static void main(String[] args) {       Stream.iterate(1, i -> i < 5, i -> i + 1).forEach(System.out::println); // iterate()    } }Output1 2 3 4ofNullable()The ofNullable() method returns the stream object of an element if it ... Read More

What are the new methods added to an Optional class in Java 9?

raja
Updated on 21-Feb-2020 12:21:47

170 Views

An Optional class provides a container that may or may not contain a non-null value. This Optional class introduced in Java 8 to reduce the number of places in the code where a NullPointerException can be generated. Java 9 added three new methods to Optional class: or(), ifPresentOrElse() and stream() that help us to deal with default values.Optional.or()The or() method introduced in Java 9 and the parameter of this method is a functional interface Supplier. This method always gives us an Optional object that is not empty. If the Optional object is not empty, it returns the Optional object itself. Otherwise, it returns an Optional ... Read More

What are the rules for private methods in an interface in Java 9?

raja
Updated on 21-Feb-2020 12:43:46

755 Views

Java 9 added a new feature of private methods to an interface. The private methods can be defined using a private modifier. We can add both private and private static methods in an interface from Java 9 onwards.Rules for private methods in an interface:A private method has a body in an interface means that we can’t be declared as a normal abstract method as usually do in an interface. If we are trying to declare a private method without a body then it can throw an error says that "This method requires a body instead of a semicolon".We can't be used both private and abstract modifiers together in an interface.If ... Read More

What are the main features and enhancements introduced in Java 9?

raja
Updated on 11-Feb-2020 08:00:28

106 Views

Oracle has released Java 9 version with a rich set of new features and brings a lot of new enhancements.Below are a few important features and enhancements introduced in Java 9.Factory Methods for Collections: Factory methods are special kinds of static methods that can be used to create unmodifiable instances of collections, which means we can use these methods to create a list, set, and map.Java Platform Module System (JPMS): A Java Module is a mechanism to bundle java applications and java packages into a Java module. It specifies which of the java packages that contain visible to other java modules by using ... Read More

Difference between ArrayBlockingQueue and ArrayDeque

Mahesh Parahar
Updated on 27-Jan-2020 10:35:13

354 Views

ArrayBlockingQueue stores elements in FIFO order. Insertion of element always happened at the tail of the queue and removal of the element always happened from the head of the queue.  It is thread safe and It is bounded array queue therefore once created, the capacity cannot be changed. It is the implementation of the Blocking queue.As per Java Docs −Resizable-array implementation of the Deque interface. Array deques have no capacity restrictions; they grow as necessary to support usage. They are not thread-safe; in the absence of external synchronization, they do not support concurrent access by multiple threads. Null elements are ... Read More

Difference between ArrayBlockingQueue and LinkedBlockingQueue

Mahesh Parahar
Updated on 27-Jan-2020 10:32:34

360 Views

Blocking queue interface is the part of Java.util.concurrent package. Blocking queue is specially designed for producer consumer queues and also support collection. This interface is divided into four parts of methods to support all types of operation which can be performed over the queue. It doesn't accept null keys. ArrayBlockingQueue and LinkedBlockingQueue both implements Blocking queue interfaceArrayBlockingQueue and LinkedBlockingQueue both stores elements in FIFO order. In both queues Insertion of element always happened at the tail of the queue and removal of the element always happened from the head of the queue.  Sr. No.KeyArrayBlockingQueueLinkedBlockingQueue1BasicIt is backed by ArrayIt is backed ... Read More

Difference between OpenId and OAuth

Mahesh Parahar
Updated on 27-Jan-2020 10:29:12

337 Views

OAuth is designed for providing authorization of the third party without providing password. It is http based. OAuth provides an access token that can be exchanged for any supported assertion via an API.OpenId is designed for authentication. In openId third-party authenticate your users for you, by using accounts they already have. It is used to authenticate single sign-on identitySr. No.KeyOAuthOpenId1BasicOAuth is designed for providing authorization of the third party without providing passwordOpenId is designed for authentication.2SessionIt does not initiate user's session.OpenId initiate user's session3Access TokenIt used token concept to provide authorizationIn openId third-party authenticate your users for you, by using ... Read More

How to Install Rundeck on a Debian 8 (Jessie) Server

Sharon Christine
Updated on 22-Jan-2020 07:16:25

193 Views

Rundeck allows you to run commands/scripts on a remote computer. It is used to create a job by defining a single step or a workflow that can execute any set of commands, scripts, or tools on any number of local or remote nodes. Jobs can be triggered by the scheduler or on-demand via the web interface or API. This article explains about ‘How to install Rundesk on Debian 8 server’Rundeck is written in java programming language, so it requires you to install java in your machine. To install Java programming on Debian, use the following commands –$ sudo dpkg --add-architecture ... Read More

How to Install Java with Apt-Get on Ubuntu 16.04

Sharon Christine
Updated on 22-Jan-2020 06:15:40

893 Views

Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core a component of Sun Microsystems’ Java platform (Java 1.0 [J2SE]).The latest release of the Java Standard Edition is Java SE 8. With the advancement of Java and its widespread popularity, multiple configurations were built to suit various types of platforms. Ex − J2EE for Enterprise Applications, J2ME for Mobile Applications.The new J2 versions was renamed as Java SE, Java EE and Java ME respectively. Java is guaranteed to be a Write Once, Run Anywhere.This article explains about ‘How to ... Read More

Advertisements