Home » Java » Core Java (page 30)

Core Java

Reduce GC Overhead With These 5 Simple Hacks

Five simple ways to write code that’s more memory efficient, without spending more time on it or reducing code readability How much overhead does garbage collection add to your application? You might not know the exact number off the top of your head, but you do know that there’s always room for improvement. Although automated GC is a mostly efficient ...

Read More »

Applying New JDK 11 String Methods

In the posts “New Methods on Java String with JDK 11” and “String#repeat Coming to Java?“, I discussed six new methods coming to the Java String with JDK 11. The available early access JDK 11 builds already include these new methods and I use one of those early access builds to demonstrate them in this post. I am using OpenJDK ...

Read More »

Java 8 Stream examples

This post will help you to understand some of the important and frequently used Stream operations in Java 8 which makes your programming with Java easy. Let’s take our traditional example, Employee and Department. public class Employee { private String name; private Integer age; private String city; private Department department; public Employee(String name, Integer age, String city, Department department) { ...

Read More »

Launch Single-File Source-Code Programs in JDK 11

JEP 330 – Launch Single-File Source-Code Programs is one of the exciting features in the upcoming JDK 11(18.9) release. This feature allows executing your java source code directly using the java interpreter. The source code is compiled in memory and then executed by the interpreter. The limitation is that all the classes have to be defined in the same file. ...

Read More »

Java 8 map(), flatMap() examples

Using map () method When programming, it is very common, processing data in order to collect some information from a collections of objects. Let’s say, we wanted find out the cities from all the employees in a particular company. Our employee class will be as follows. public class Employee { private String name; private Integer age; private String city; private ...

Read More »

How to use filter() method in Java 8

Java 8 Stream interface introduces filter() method which can be used to filter out some elements from object collection based on a particular condition. This condition should be specified as a predicate which the filter() method accepts as an argument. The java.util.function.Predicate interface defines an abstract method named test() that accepts an object of generic type T and returns a ...

Read More »

Java 8 Language Features in Nutshell – Part 2

Editorial Note: You can also check Part-1 here. Hi Friends, this is a part-2 of Java 8 Language Features in nutshell series. Here we will discuss following features of Java 8: Static methods in Interface Streams 1. Static methods in Interface What is Static Method? Static methods are the methods which belong to the class rather than to object or instance. ...

Read More »

Java 8 Stream API Examples

Hello Friends, in this post, we will discuss Java 8 Stream API Examples. So what we are going to do is, we will create a Player class, create multiple objects of Player class and then create a test class where will retrieve data of players using Stream API. First example is with normal Stream(which we can call Serial Stream) and ...

Read More »

Looking into Java’s Future: Empty Value Types

Although the promising Java value types are not imminent, I still enjoy nosing around occasionally in the OpenJDK valhalla-dev mailing list to see how things appear to be progressing and to get an idea of what is to come. Admittedly, there are some discussions that are beyond my understanding given my limited exposure to the terms used and the low-level ...

Read More »