Breaking News
Home / Java / Java Snippets (page 5)

Java Snippets

Find Files in Directory based on Extension

How about finding files of a given type (extension) in a given folder? The following snippets shows how to do so, it list all the files in the directory, then using Regex pattern it tries to match the extension within the file name. If a match is found, it adds …

Read More »

Invoke a method of class using Java Reflection API

This snippet shows how to invoke a method of class using Java Reflection API. The example uses a class called TargetClass that has a instance method named as runMe(). Now from the main method, this class will be loaded via the System Classloader and then instantiated using the newInstance() method. …

Read More »

Find the Calling Method in Java?

This snippet shows how to write a method whoCalledMe() which would be used to find the calling method. This example leverages the fact that the JVM maintains a stack wherein, it adds the method names as they are invoked, so the top method in the stack is one that would …

Read More »

How to Capture Screen Shot?

Have you wondered how tools like Snagit capture the display screen and create an image file. Doing that using java AWT is very easy. Just few lines of code. Also you can save the image as JPG, GIF, PNG etc. by just changing the file format input parameter.

Read More »
Advertisment ad adsense adlogger