Using Google Guava For Cache With Timeout – Java

If you need a list to keep your objects for a while and then automatically delete/expire them, you can use caches from Google Guava.

The Guava project contains several of Google’s core libraries that we rely on in our Java-based projects: collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O, and so forth.

The latest release is 18.0, released August 25, 2014.

First, let’s write a class based on LoadingCache.

Click to read more…


Communication Between Java Applications (2) – JGroups

JGroups is a library which may serve some APIs to communicate between java applications. Unfortunately it is a little bit complex and has some advanced configurations, so I just show quick and simple example to introducing.

Project Explorer is going to looks like this:

Click to read more…


Communication Between Java Applications (1) – Socket Programming

There are too many ways to send a message from one java application to another. Most known method is using a socket.

Let’s assume that we have a server which receive a message from a client and reverse that message text and then send it back.

Click to read more…


JSP Hello World on Jetty 9

Running a JSP file on Jetty is quite simple. There is only a trick officially reported to add JSP support to Jetty.

Let’s make an example.

Click to read more…


Ehcache with Hibernate

Simple application that just get some records via Hibernate from database and add these records to cache which supplied by EhCache.

There is “Contact” table in database which includes ID, NAME and ADDRESS values.

“Contact” class for mapping this table:

Click to read more…

Video Playlist for Flowplayer with Javascript

Even Flowplayer gives you some plugin for playlist attribute, maybe you just want a simple playlist with just javascript.

For this purpose we can use “playlist” option.
Click to read more…

Illegal Access Error with Mock Private Methods in JUnit

When I write some unit test with Junit and JMockit, I make a mock for some private methods as

MockUp<MyClass> myMethod = new MockUp<MyClass>() {
     private void mockMethod() {

however when it runs I got this error.

java.lang.IllegalAccessError: tried to access method path-to-test-file(;path-to-file-which-tested)
	at ...

Click to read more…

Tagged ,

How to Mock a Hibernate Session with JMockit

I’m writing some unit tests with JUnit but my tests crash with NullPointerException in the line

Session session = sessionFactory.getCurrentSession();

There are also some session functions like flush and clear.

So I decided to write a mock object for that session, therefore tests can pass that line without got an exception.

Click to read more…

Tagged , ,

Gödel’in Eksiklik Teoremi’ne Başlarken

Bugün internette Gödel’in Eksiklik Teoremi ile ilgili çok sayıda İngilizce kaynak bulunabiliyor. Türkçe kaynaklar ise sayıları biraz kısıtlı olsa da, teoremin genelini anlamak için yeterli görülebilirler. Ancak bu konuda yeni araştırma yapmaya başlamışsanız, teoremin kendisinden çok teoremle ilişkili olan diğer bazı kavramlara aklınızın takılması çok normal bir durumdur. Bu yazı, teoremi açıklamaya çalışmaktan daha çok konuyu yeni araştırmaya başlamış olanların, daha hızlı yol almaları ve karşılaştıkları bazı kavramları daha kolay anlamalarını sağlamak amacıyla yazılmıştır.
Devamını oku…

Tagged , , ,

Time measuring by miliseconds in UNIX – C++

If you want to measure time in miliseconds in Unix, you can use this code. This program returns 2 miliseconds as a result related with usleep function with value of 2000. You can replace your function which you want to measure runtime with this usleep function.
Click to read more…

Tagged , ,