Skip to content
András Vörös edited this page Nov 30, 2015 · 12 revisions

Popular Java libraries

There are numerous Java libraries which can spare you a lot of hassle -- it's useful to keep the most popular in mind: http://blog.takipi.com/we-analyzed-60678-libraries-on-github-here-are-the-top-100/

Running JUnit test in a specific order

From JUnit 4.11, the following works:

@FixMethodOrder(MethodSorters.NAME_ASCENDING)

Comparing integers

int vs. long

Long l = 1L;
Integer i = 1;
System.out.println(l.equals(i)); // false
System.out.println(1 == 1L); // true

Outputs:

false
true

See also http://cubussapiens.hu/2012/05/java-primitive-type-comparison-a-wat-look/.

Log4j

Add a log4j.properties file. For Maven projects, it should be in the src/main/resources directory:

log4j.rootLogger=debug, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log

log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

Clone this wiki locally