background preloader

Java

Facebook Twitter

Java Warmup-1. JUnit best practices. JUnit is a typical toolkit: if used with care and with recognition of its idiosyncrasies, JUnit will help to develop good, robust tests.

JUnit best practices

Used blindly, it may produce a pile of spaghetti instead of a test suite. This article presents some guidelines that can help you avoid the pasta nightmare. The guidelines sometimes contradict themselves and each other -- this is deliberate. In my experience, there are rarely hard and fast rules in development, and guidelines that claim to be are misleading. We'll also closely examine two useful additions to the developer's toolkit: A mechanism for automatically creating test suites from classfiles in part of a filesystemA new TestCase that better supports tests in multiple threads When faced with unit testing, many teams end up producing some kind of testing framework.

Do not use the test-case constructor to set up a test case Setting up a test case in the constructor is not a good idea. Don't assume the order in which tests within a test case run. Slf4j performance. What is SLF4J?

slf4j performance

SLF4J is a simple facade for logging systems allowing the end-user to plug-in the desired logging system at deployment time. When should SLF4J be used? In short, libraries and other embedded components should consider SLF4J for their logging needs because libraries cannot afford to impose their choice of logging framework on the end-user. On the other hand, it does not necessarily make sense for stand-alone applications to use SLF4J. Java - Problem with Commons Logging / Log4j setup in spring webapp with tomcat 6. Maurice Naftalin's Lambda FAQ.

GUI

Generics. JAXB Reference Implementation — Java.net. Maven. Tomcat Configuration Reference (6.0.35) - The Realm Component. Open Source Integration with Apache Camel and How Fuse IDE Can Help. Take any integration project and you have multiple applications talking over multiple transports on multiple platforms.

Open Source Integration with Apache Camel and How Fuse IDE Can Help

As you can imagine, in large enterprise applications this can get complex very fast. Much of the complexity stems from two issues: 1. dealing with the specifics of applications and transports, and 2. coming up with good solutions to integration problems. Making your applications speak transports and APIs is relatively easy on its own. Ignoring the mechanics of how to connect with multiple transports and APIs, we can focus on the high level design of how applications interact.

Apache Camel was created with the intention of addressing these two issues. What is Camel? Apache Camel is an open source Java framework that focuses on making integration easier and more accessible to developers. . • concrete implementations of all the widely used EIPs • connectivity to a great variety of transports and APIs Figure 1 shows how these three items actually map to Camel concepts. . • Java DSL.

Spring

Journal - October 2005 Volume 4 Issue 2. The Secret Life of JavaServer Pagesby Bear Bibeault "How do I call a bean method from a Javascript onclick handler?

Journal - October 2005 Volume 4 Issue 2

" "When I write to a file in my JSP, why does it appear on the server? I want to write to the client system! " "Why does everyone tell me to use a servlet to send binary data to the browser? I wanna use a JSP! " To those that frequent the JSP Forum of the JavaRanch Big Moose Saloon, these questions may appear hauntingly familiar as they are among some of the most recurring questions asked by new-comers to the Ranch and to JSP.

VM

Java theory and practice: Where's your point? While nearly every processor and programming language supports floating point arithmetic, most programmers pay little attention to it.

Java theory and practice: Where's your point?

This is understandable -- most of us rarely require the use of non-integral numeric types. With the exception of scientific computing and the occasional timing test or benchmark, it just doesn't come up. The arbitrary-precision decimal numbers provided by java.math.BigDecimal are similarly ignored by most developers -- the vast majority of applications have no use for them. However, the vagaries of representing non-integral numbers do occasionally sneak into otherwise integer-centric programs. For example, JDBC uses BigDecimal as the preferred interchange format for SQL DECIMAL columns. IEEE floating point The Java language supports two primitive floating point types: float and double, and their wrapper class counterparts, Float and Double.

IEEE 754 represents floating point numbers as base 2 decimal numbers in scientific notation. Figure 1. Java IAQ: Infrequently Answered Questions. By Peter Norvig Q: What is an Infrequently Answered Question?

Java IAQ: Infrequently Answered Questions

A question is infrequently answered either because few people know the answer or because it is about an obscure, subtle point (but a point that may be crucial to you). I thought I had invented the term, but it also shows up at the very informative About.com Urban Legends site. There are lots of Java FAQs around, but this is the only Java IAQ. (There are a few Infrequently Asked Questions lists, including a satirical one on C.) Q:The code in a finally clause will never fail to execute, right?

Security

The need for BigDecimal (Core Java Technologies Tech Tips) By John Zukowski Working with floating point numbers can be fun.

The need for BigDecimal (Core Java Technologies Tech Tips)

Typically, when working with amounts, you automatically think of using a double type, unless the value is a whole number, then an int type is typically sufficient. A float or long can also work out, depending upon the size of a value. When dealing with money, though, these types are absolutely the worst thing you can use as they don't necessarily give you the right value, only the value that can be stored in a binary number format. Here is a short example that shows the perils of using a double for calculating a total, taking into account a discount, and adding in sales tax. The Calc program starts with an amount of $100.05, then gives the user a 10% discount before adding back 5% sale tax. Using a double type for all the internal calculations produces the following results: Subtotal : $100.05 Discount : $10.00 Total : $90.04 Tax : $4.50 Tax+Total: $94.55 The other available modes in the RoundingMode enumeration are:

Concurrency