Java Lobby Announcements

Subscribe to Java Lobby Announcements feed
Recent posts in Java on
Updated: 11 hours 13 min ago

Quick Access to Eclipse IDE Features

Mon, 2016-04-11 11:31

As Lars points out on the ide-dev mailing list, a lot of Eclipse IDE users aren’t aware of some very handy features, especially the one-feature-to-rule-them-all: Quick Access.

In an Eclipse IDE, Quick Access will take you quickly to the feature you need. To activate Quick Access, type Ctrl+3 and start typing (or click in the entry field in the toolbar and start typing).

Categories: Java

Currying Functions in Scala

Mon, 2016-04-11 09:31

For a long time I couldn’t understand currying functions in Scala and how they work. That was really horrible! Occasionally I met the currying functions in the code and wasted too much time on reading them. So finally I decided to learn how they work and where they could be applied.

Let’s start from a definition. A currying function is a function which could accept a fewer number of parameters than are declared, then it returns a function with unused parameters. This definition is totally weird. In order to understand it we need to go through several examples. And be sure that you already know how simple Scala functions work.

Categories: Java

Java 8 – Default Methods in Interfaces

Mon, 2016-04-11 06:31

In this article we will explore the Java 8 default methods feature in interfaces. The Java 8 says “Default methods enable new functionality to be added to the interfaces in libraries and ensure binary compatibility with code written for older versions of those interfaces”.

As Java evolved over the years, the interfaces introduced in the Java library require adding new functionality. If you add new methods in the interface without having default methods feature, all the classes which already implemented the interfaces should undergo for a change. This results in changing thousands of lines of code. To avoid this, the Java 8 introduced default method feature. That is, if you want to add any functionality to the existing interface, you can add it by using default method feature without affecting the implementations.

Categories: Java

Patterns, 20 Years Later: The Constructor Function Explained

Sun, 2016-04-10 11:31
tl;dr Patterns, 20 Years Later: A Constructor Function is a function designed specifically to construct instances of entities (typically objects, although in languages which do not support objects as native types, this will typically be something that masquerades as an object). It is often seen as a variation on a Factory Method, though there is enough variation on the intent that it is worth calling this out as a standalone pattern.Problem

We want to define an easy interface for creating an object, but defer the actual decision of what object type to instantiate. (In this respect, it is very very similar to Factory Methods and the main decision point on which to use will vary on the context.)


A class can’t anticipate the class of objects it must create. In other words, either the system is deliberately designed to be “open,” allowing types that weren’t known at the time of the framework’s creation to be created (which is the case in most application frameworks, for example), or the system is deliberately drawing an encapsulatory barrier between the class representing the abstract type and the implementations, in order to help facilitate better decoupling. Most systems or platforms that support some notion of “plugins” are in the former category, although often at a binary level of interoperability, rather than a source-language level of interop. (Most Component Object Model (COM) developers will remember CoCreateInstance, for example, which is the classic example of a Factory Method.)

Categories: Java

Introduction to Java 8 Streams

Sun, 2016-04-10 08:01

In Java 8, we have a new feature called “Streams.” These “Streams” are similar to collections, but there are some differences. Primarily the collections are the data structures which will hold the data. To process the data, we need to get the data from the collections and execute some logic. For example, we have a list of students. We need to sort the students based on the marks secured, in descending order. To perform the above-said logic, we have to follow these steps.

Create a Comparatorpackage org.smarttechie; import java.util.Comparator; public class MarksComparator implements Comparator<Student>{ @Override public int compare(Student student1, Student student2) { if (student1.getTotalMarks() > student2.getTotalMarks()) { return -11; } else if (student1.getTotalMarks() < student2.getTotalMarks()) { return 1; } else { return 0; } } }Call the Method Collections.sort(students, new MarksComparator());

With Streams we can do this in a simple way. The code snippet is given below.

Categories: Java