Easiest way to print stack trace in Java
In a common method that is called from many difference places in the code, sometimes you want to know which one is calling it (and causing a problem).
This is just one line of code to show the stack trace.
new Exception().printStackTrace();
Simple, and no need to deal with an array of StackTraceElement.
Android Development Environment on Windows 7 (64bit)
This is a note when I've built the Android development environment on Windows 7 (64 bit) Premium Home.
- Eclipse
- JDK
- Android SDK
Used 32 bit version Galileo (version 3.5). This is due to that Android SDK doesn't support Helios yet.
Used 32 bit version of 1.6.0_21. The initial revision of that version doesn't work, so needed to download the latest one.
Running Java app on Ant script on Windows
You can run a Java app from the command line like this.
Java com/yourcompany/product/HelloWorld
?>or
Java com.yourcompany.product.HelloWorld
?>The separator can be either a forward slash or a dot. But when you try to run the same Java class on Ant, the separator has to be a dot.
So, the following Ant script should work.
Java Memorandum - How to make javac to reference user library BEFORE built-in library (rt.jar)
Here's the situation. I have a jar file, which is a library I need to use for an embedded Java application. Even though the embedded device only support Java 1.4, the library implements some 5.0 methods in org.w3c.dom.DOMImplementation. Because the same class is already in rt.jar for 1.4, just compiling a normal way doesn't work.
Java Memorandum - Modifying format (style) of Java code using Eclipse
Coding style is very much personal, and using your favorite style improves the coding productivity.
Say, for example, someone (many Java programmer, apparently) likes the following style.
class test(){
public main(args[]){
if(a == b){
System.out.println("Hello World!");
}
}
}
Java Memorandum - Using SSL Socket
I wrote a pair of code (server/client) to see how SSL on Java can be implemented.
In this sample, only the server certificate is used. The client validates the server certificate, but the server doesn't care the client's authenticity. That is OK because the most web server behave like that.
Client side of the code - SSLClient.java
import java.io.*;
import java.security.KeyStore;
Java Memorandom - How to create Eclipse Java project from NetBeans project
Sometimes you find a good reference Java code, or an open source project you want to use, but the project is written as a NetBeans project. To use the project in Eclipse, follow the steps below.
Modify NetBeans project
First, you need to modify the NetBeans project file to suit in Eclipse. Open nbproject\project.properties.
Replace the following 2 lines
Java Memorandom- Graphics.drawImage
In paint(Graphics g) call back, use drawImage() to draw an image. It is crucial to specify ImageObserver parameter.
I mistakenly passed a null to the parameter, and the drawing was not done properly. It renders only when any other event forces to repaint. When the parameter was properly set, the rendering happens correctly so that the image shows up from the beginning.
