Getting Rid of Getters and Setters in your POJO
We all have read in Java books about encapsulation of fields in Java class and also when ever you code you are asked to take special care in encapsulating the fields and providing explicit Getters and Setters. And these are very strict instructions. Lets step back a bit and find out the reason behind encapsulating the fields. Its all done to have a control over the access and modification of the fields. One might want to allow the user of the class to access data from only few fields or control the update of data of the fields in the class and so on. And on other occassions the frameworks would need these getters and setters to populate your POJOs(Plain Old Java Objects).
Everything You Need To Know About Default Methods
So, default methods… yesterday’s news, right? Yes but after a year of use, a lot of facts accumulated and I wanted to gather them in one place for those developers who are just starting to use them. And maybe even the experienced ones can find a detail or two they didn’t know about yet.
Avoiding Null Checks In Java
One of the worst nightmares for Java developers (from junior to expert) is null object reference checking. I’m pretty sure you have seen code like this several times...
An Opinionated Guide to Modern Java Development, Part 1
How to handle Unsupported Class Version Error
In this tutorial we will discuss about Java’s UnsupportedClassVersionError and how to deal with it. The UnsupportedClassVersionError is a sub-class of the LinkageError class and specifically, of the ClassFormatError class. This error is thrown by the Java Virtual Machine (JVM) when it tries to read a class file whose major and minor version numbers are not supported. This error exists since the Java 1.2 release and is thrown only at runtime and especially during the linking phase.
Searching made easy with Apache Lucene 4.3
Lucene is a Full Text Search Engine written in Java which can lend powerful search capabilities to any application. At heart of Lucene lies a file based Full Text Index. Lucene provides APIs to create this index and then add and delete contents to this index. Further it allows search and retrieval of information from this index using powerful search algorithms. The data stored can be pulled from disparate sources like a database, filesystem and as well as the websites. Before beginning let us ponder on few terms.
Finding long tail suggestions using Lucene’s new FreeTextSuggester
Lucene’s suggest module offers a number of fun auto-suggest implementations to give a user live search suggestions as they type each character into a search box. For example, WFSTCompletionLookup compiles all suggestions and their weights into a compact Finite State Transducer, enabling fast prefix lookup for basic suggestions. AnalyzingSuggester improves on this by using an Analyzer to normalize both the suggestions and the user’s query so that trivial differences in whitespace, casing, stop-words, synonyms, as determined by the analyzer, do not prevent a suggestion from matching.
Java 8 Lambda Expressions Tutorial
In this article we are going to explain what Lambdas are, why are they important and how do they look like in Java. We are going to see also a couple of examples and real life applications. All examples are being implemented using Eclipse Luna version 4.4 and Java version 8.
Simplifying ReadWriteLock with Java 8 and lambdas
Considering legacy Java code, no matter where you look, Java 8 with lambda expressions can definitely improve quality and readability. Today let us look at ReadWriteLock and how we can make using it simpler. Suppose we have a class called Buffer that remembers last couple of messages in a queue, counting and discarding old ones. The implementation is quite straightforward:
Introduction to Java lambdas
The main theme of Java 8 is lambdas. I have noticed that for many Java programmers lambdas are pretty tough material. So let’s try to get a basic understanding of them. First of all, what exactly is a lambda? A lambda is an anonymous function that is, unlike a regular function, not bound to an identifier (i.e. it has no name). These functions can be passed as arguments to other functions (known as higher-order functions).
Lambda Expressions and Stream API: basic examples
This blog post contains a list of basic Lambda expressions and Stream API examples I used in a live coding presentation I gave in June 2014. Lambda expressions let you express instances of single-method classes more compactly. Single-method classes are called functional interfaces and can be annotated with @FunctionalInterface...
Socket programming for scalable systems
From simple I/O to non-blocking asynchronous channels in the Java socket model. Socket programming boils down to two systems communicating with one another. Network communication comes in two flavors: Transport Control Protocol (TCP) and User Datagram Protocol (UDP). TCP and UDP are used for different purposes and both have unique constraints:
Getting started with invokedynamic and java.lang.invoke
In a dynamic language, type-checking typically occurs at runtime. Developers must pass appropriate types or risk runtime failures. It's often the case that java.lang.Object is the most accurate type for a method argument. This situation complicates type checking, which impacts performance.
Java – Read from File
In this tutorial we’ll explore different ways to read from a File in Java; we’ll make use of BufferedReader, Scanner, StreamTokenizer, DataInputStream, SequenceInputStream and FileChannel. Then, we will discuss how to read a UTF-8 encoded file and how to create String from contents of a file.
Timer and TimerTask are java util classes used to schedule tasks in a background thread. In a few words – TimerTask is the task to perform and Timer is the scheduler. Let’s start by simply running a single task with the help of a Timer:
In this tutorial, we’ll illustrate how to use the Java Scanner to read input and find and skip patterns with different delimiters. First – let’s see how to read a file using Scanner...
Reset the Notification Area Icons Cache
The notification area is a part of the taskbar that provides a temporary source for notifications and status. It can also be used to display icons for system and program features that are not on the desktop. This will show you how reset the Notification Area Icons cache to fix any currupted icons and remove any old icons of uninstalled programs from the Notification area Icons hide or show settings in Windows 7/8 and Vista.
How to Clean Install an OEM Windows 7
A clean reinstall is often better than getting a new computer since most PC's come larded with sponsors' bloatware and duplicate utilities that interfere with much better versions built into Windows 7. For this reason most tech enthusiasts clean reinstall using the Product Key on the COA sticker affixed to machine. This guide compiles everything that works best in tens of thousands of installs we've directly helped with here.
How to Tell Whether Your Windows PC is Using a Proxy Server
Almost all applications use the system proxy, which is actually in the Internet Options panel. This proxy works for applications like Google Chrome and Internet Explorer, as well as many or most other applications that require Internet access. Certain apps, like Firefox, can set their own proxy settings differently.
Why Does Every Camera Put Photos in a DCIM Folder?
Every camera — whether it’s a dedicated digital camera or the Camera app on Android or iPhone — places the photos you take in a DCIM folder. DCIM stands for “Digital Camera Images.” The DCIM folder and its layout come from DCF, a standard created back in 2003. DCF is so valuable because it provides a standard layout.