java

Junit – Unrooted Test

If you have experienced “unrooted tests” title in your IDE while you are trying to run JUnit test method and as a result if it just runs all the cases you probably couldn’t handle Junit annotations with your test class.

After some googling i found the solution. Here a simple test class annotation applied and some details for preventing this situation.

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*; 

public class MyUnitTest{ // 1. Do not extend TestCase

  @Before
  public void setUp() {
    // 2. No super call
  }

  @After
  public void tearDown() throws Exception {
  }

  @Test
  public void caseOneTest() { // 3. No need "test" prefix

    // 4. Assert static imported
    assertTrue(true);
  }
}

JavaTip – Setting Java Name Service Providers Priorities

Today’s big thing is the following java property;

-Dsun.net.spi.nameservice.provider.<n>= file || dns || dnsjava || nis ||...

We have been troubling by host-name resolving problem with Apache Tomcat for a while. 5 min ago we found that property and applied

-Dsun.net.spi.nameservice.provider.1= file,dns,dnsjava

to Tomcat’s catalina.sh (Path = %CATALINA_HOME%/bin/catalina.sh)

And all is ok.

PS: For more Java networking properties you may take a look  http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html

Displaytag Tag Library

The display tag library is an open source suite of custom tags that provide high-level web presentation patterns which will work in an MVC model. The library provides a significant amount of functionality while still being easy to use.

Yukarıdan anlayacağınız gibi Displaytag MVC modelinde çalışan esnek, hızlı ve kolay entegre edilebilir bir frameworktür. Ayrıca kendilerinin en azılı hayranı olmuş bulunmaktayım.

Türk Telekom Ip/MPLS Omurga Sözleşmesi kapsamında geliştirdiğimiz uygulamalarda çok büyük verileri gayet hızlı şekilde istenilen biçimde kullanıcıya sunmamı sağladı bu framework. Hakkını ne yapsam ödeyemem :) Bu yazının devamını okuyun »

Devoxx

Devox yukarıdaki görselden de anlaşılacağı gibi bir java topluluğu konferansı. Ama öyle haybeye bir konferans değil… Bizim takımdan Barış ve Cenk bu konferansa katılacaklar…(evet çok şanslılar…) Herneyse… Sıradan bir konferans değil demiştik.

Konferans Bilgileri; Bu yazının devamını okuyun »

Reading .xls in Java with Apache Poi

Here is my sample java code explanation for accesing an microsoft excel file with apache’s framework poi;

First initiliaze the stream definitions;

InputStream myxls = new FileInputStream(myXlsFilePath);
HSSFWorkBook workBook = new HSSFWorkBook(myxls);

Now we are nearly ready to read some data from [filename].xls but before reading we need to reach the sheet via its name or index. (Don’t forget index numbers starts from 0)

And here we go;



for (int i = 0; i < 10; i++){

row = sheet0.getRow(i);
for (int j = 0; j < 10; j++)
switch (row.getCell((short) j).getCellType()){

case HSSFCell.CELL_TYPE_NUMERIC:

double number = row.getCell((short) j).getNumericCellValue();
System.out.println(”["+i+","+j+"] number = ” + number);
break;

case HSSFCell.CELL_TYPE_BOOLEAN:

boolean bool = row.getCell((short) j).getBooleanCellValue();
System.out.println(”["+i+","+j+"] bool = ” + bool);
break;

case HSSFCell.CELL_TYPE_STRING:

String string = row.getCell((short) j).getStringCellValue();
System.out.println(”["+i+","+j+"] string = ” + string);
break;

/* We may increase the options */

default: System.out.println(”cant recognize the cell type.”);

}

}

PS: sorry about the indentation, i couldn’t handle it…

Comment

While coding, make comments for “why” you are coding that part, not for “what the code does”!

Garbage Collector Logging

Novadays i have been working on a memory leak problem for a java application and i need to analyze the memory usage of 300 threads! The basic way and the best point to start analyzing is the garbage collector of java.

with the parameter of “-verbose:gc” java enables us to log the garbage collectors movements (logs it to sytem.out or any piped place). When we take a look to the log we face with such lines;

Besides there are some tools which analyze logs graphically, HP-Jmeter is the one of them and from this blog you can learn some ways of charting these logs with phyton.

112829.094: [GC 695486K->557348K(806720K), 0.0191830 secs]…
112776.534: [Full GC 690522K->551411K(817408K), 1.8249860 secs]…
^                         ^               ^                   ^                 ^                   ^
|                          |                 |                   |                 |                   +- time taken for this GC operation
|                          |                 |                   |                 +———– total JVM heap size (Kb)
|                          |                 |                   +——————- heap used after GC (Kb)
|                          |                 +————————– heap used before GC (Kb)
|                          +———————————– Full/Partial GC
+———————————————- Timestamp (sec) since JVM startup