Home » Tag Archives: Google Guava

Tag Archives: Google Guava

Google Guava: 5 Things You Never Knew It Could Do

java-logo

What are some of the lesser known features of Google Guava that every developer could use? It’s one of the most popular libraries out there, it’s open source, you probably know it already, and it comes from a place where people play Quidditch as a real sport (At least on The Internship). It’s not the Hogwarts library from Harry Potter ...

Read More »

Using Google Guava Cache for local caching

java-logo

Lot of times we would have to fetch the data from a database or another webservice or load it from file system. In cases where it involves a network call there would be inherent network latencies, network bandwidth limitations. One of the approaches to overcome this is to have a cache local to the application. If your application spans across ...

Read More »

Spring Caching abstraction and Google Guava Cache

spring-interview-questions-answers

Spring provides a great out of the box support for caching expensive method calls. The caching abstraction is covered in a great detail here. My objective here is to cover one of the newer cache implementations that Spring now provides with 4.0+ version of the framework – using Google Guava Cache In brief, consider a service which has a few ...

Read More »

Testing code for excessively large inputs

java-logo

When writing unit tests we mostly focus on business correctness. We do our best to exercise happy path and all edge cases. We sometimes microbenchmark and measure throughput. But one aspect that is often missed is how our code behaves when the input is excessively large? We test how we handle normal input files, malformed files, empty files, missing files… ...

Read More »

Building extremely large in-memory InputStream for testing purposes

java-logo

For some reason I needed extremely large, possibly even infinite InputStream that would simply return the samebyte[] over and over. This way I could produce insanely big stream of data by repeating small sample. Sort of similar functionality can be found in Guava: Iterable<T> Iterables.cycle(Iterable<T>) and Iterator<T> Iterators.cycle(Iterator<T>). For example if you need an infinite source of 0 and 1, simply sayIterables.cycle(0, 1) and get 0, 1, 0, 1, 0, 1... infinitely. ...

Read More »

Determining Presence of Characters or Integers in String with Guava CharMatcher and Apache Commons Lang StringUtils

java-logo

A recent Reddit post asked the question, “Is there a predefined method for checking if a variable value contains a particular character or integer?” That question-based title was also asked a different way, “A method or quick way for checking if a variable contains any numbers say or (‘x’,2,’B’) like a list?” I am not aware of any single method ...

Read More »

Extending Guava caches to overflow to disk

java-logo

Caching allows you to significantly speed up applications with only little effort. Two great cache implementations for the Java platform are the Guava caches and Ehcache. While Ehcache is much richer in features (such as its Searchable API, the possibility of persisting caches to disk or overflowing to big memory), it also comes with quite an overhead compared to Guava. ...

Read More »

Proxies done right with Guava’s AbstractInvocationHandler

java-interview-questions-answers

Not too often but sometimes we are forced to write custom dynamic proxy class using java.lang.reflect.Proxy. There is really no magic in this mechanism and it’s worth knowing even you will never really use it – because Java proxies are ubiquitous in various frameworks and libraries. The idea is quite simple: dynamically create an object that implements one or more ...

Read More »

Object-based micro-locking for concurrent applications by using Guava

java-logo

One of the presumably most annoying problems with writing concurrent Java applications is the handling of resources that are shared among threads as for example a web applications’ session and application data. As a result, many developers choose to not synchronize such resources at all, if an application’s concurrency level is low. It is for example unlikely that a session ...

Read More »

Fine-Grained Concurrency with the Guava Striped Class

java-logo

This post is going to cover how to use the Striped class from Guava to achieve finer-grained concurrency. The ConcurrentHashMap uses a striped locked approach to increase concurrency and the Striped class extends this principal by giving us the ability to have striped Locks, ReadWriteLocks and Semaphores. When accessing an object or data-structure such as an Array or HashMap typically ...

Read More »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close