View RSS Feed

Most Popular Blogs

  1. Detached Views in Eclipse

    by , 05-21-2011 at 11:07 PM (My Java Tips)
    Eclipse provides an option to detach a view so that it can be moved to the desired place. Detached views are used if you are not comfortable with the placing of a view and want it to be move to someplace that is more feasible.

    This is done as follows:

    • Right-click on the view
    • Select "Detached" from the menu
    • Place the view where you choose

    Name:  detachedview.PNG
Views: 673
Size:  6.3 KB

    Thing to remember is that one can also drag and drop ...
  2. Costs of Unit Testing

    by , 05-21-2011 at 11:09 PM (My Java Tips)
    Unit testing brings a lot of benefits but there is some cost for this. Lets talk about this.

    Unit tests require skill and time. Often managers dont appreciate unit tets because they regard it something othere than development. Ofcource client in not interested in unit tests but management needs to understand that these tests will save a lot of debugging effort in future.

    For unit testing to really deliver, all developers need to use it. Mostly due to lack of communicationm ...
    Tags: unit testing Add / Edit Tags
  3. Final keyword improves performance

    by , 05-21-2011 at 11:10 PM (My Java Tips)
    Its right to say that final keyword improves performance. For example, if you declare a method as final, then you cannot override it in derived classes. When this is told to compiler in advance using final keyword, it improves performance.

    Java Code:
    public final void doSomethng()
    Knowing that a method cannot be overridden, complier inline that method into its derived classes.
    Final variables, especially static final variables, ...
    Tags: final Add / Edit Tags
  4. Memory Leaks

    by , 05-25-2011 at 11:04 AM (My Java Tips)
    You are aware of the fact that garbage collection collects and removes all the unwanted objects from memory without used intervention. But sometimes, you run into memory leaks problems that demands investigation. I will shed some light on this issue in the next few posts.

    The Java GC process is a low-priority thread and it constantly searches memory for unreachable objects that are not reachable by any live thread. Different JVMs use different algorithms to determine how to collect ...
  5. Java ArrayList : Generics & Sorting

    by , 07-21-2011 at 07:20 AM


    Java ArrayList (ArrayList (Java 2 Platform SE 5.0)) class is a fastest and easiest way to represent one-dimensional array. ArrayList not synchronized, that is cross thread access may cause problems. It holds an ordered item sequence of items (objects) like an array, but there are differences:

    • Size of an ArrayList could change dynamically, by adding or removing elements
    • An ArrayList can hold only object references, not primitives

    Attached Thumbnails Attached Files
  6. Adding "Global" KeyListener

    by , 10-17-2011 at 07:00 PM
    Want to add a so called "Global" Keylistener to your Java application even if it is a JWindow or JFrame without having focus on it. Just download the file in the link and extract, add the jhook.jar file to your project library and use this demo code to get the keys pressed.

    Java Code:
    Keyboard kb=new Keyboard();
            kb.addListener(new KeyboardListener() {
                public void keyPressed(boolean keydown, int vk){

    Updated 10-19-2011 at 09:33 AM by DuvanSlabbert

    AWT and Swing
  7. Fetching contact field (PIM)

    by , 11-06-2011 at 07:07 PM (My Java Tips)
    Each contact entry in a PIM Contact database is represented by Contact. This post is all about retrieving contact fields from PIM.

    The supported field list for a Contact depends on vCard specification from the Internet Mail Consortium. These set of fields included in this Contact class provides relevant information about a contact. ContactList restricts what fields a Contact can retain. This reflects that some native Contact databases do not support all o the fields available in a ...
    Java ME
  8. Asynchronous method calls

    by , 11-07-2011 at 07:52 PM (My Java Tips)
    Methods called on the asynchronous proxy will be executed asynchronously, and the results can be obtained later on.

    To execute methods asynchronously in EJB 3.0, one can use asynchronous proxy. This allows calling methods at an instance, and collecting the results later. Good thing is that there exist a JBoss extension to EJB 3.0, which allows obtaining asynchronous proxy from the remote or local interface of a stateful session bean, stateless session bean or service bean.
  9. Simple Frame Transitions without Complex Code

    by , 03-22-2012 at 08:18 PM
    I've spent the past few days looking up Java window transitions that work with Swing components & containers (JFrame, JPanel, etc.).

    Yes, there are packages such as JavaFX which includes a Timeline & Transition framework. I also came across these:

    Project Kenai — We're More Than Just a Forge

    Filthy Rich Clients (find the Animation jar (org.jdesktop.animation))

    However, I've been impatient lately ...
    Tags: 1'", 1, transition, window Add / Edit Tags
  10. Class and Method Cheat Sheet

    by , 10-17-2012 at 11:42 PM
    Declaring a Class
    Java Code:
    class ClassName{

    Declaring a Class with Parent
    Java Code:
    class ClassName extends parentClassName{

    Declaring a class with Interface
    Java Code:
    class ClassName implements interface1, interface2, interface3{

    Declaring a Class with Fields
    Java Code:
    class ClassName{

    Updated 10-18-2012 at 01:30 AM by penguinCoder

    Cheat Sheet
  11. String Cheat Sheet

    by , 10-18-2012 at 01:05 AM
    A string is a piece of text, that is zero or more characters in length. In Java, strings are considered to be pre-built objects. The variable for a string does not store the value of the string, rather it is a reference point, or pointer, to the storage location of where the string is kept.

    Declaring a String:
    Java Code:
    String s1;
    Assigning a Value On Declaration:
    Java Code:
    String s1 = "Hello World!";
    Assigning ...

    Updated 10-18-2012 at 01:29 AM by penguinCoder

    Cheat Sheet
  12. Scanner Class Cheat Sheet

    by , 10-18-2012 at 01:26 AM
    The Scanner class can be used for many things other then just getting input from the user; however this cheat sheet/tutorial is just going to be about getting input from the user.

    Defining the Scanner Class
    Java Code:
    import java.util.Scanner;
    public class ClassName{
    It will tell the translator to look in that directory for the code defining the Scanner class.

    Declaring the Scanner
    If you ...

    Updated 10-18-2012 at 01:29 AM by penguinCoder

    Cheat Sheet
  13. ArrayList Cheat Sheet

    by , 10-29-2012 at 12:17 PM
    Importing the Library
    Before you can use an ArrayList, you must first import the necessary library.
    Java Code:
    import java.util.ArrayList
    Creating a Generic ArrayList
    Generic ArrayList is an ArrayList with a type; no other type is allowed to be inserted into the ArrayList.
    Java Code:
    ArrayList<type> listName = new ArrayList<type>();
    Example of this would be:
    Java Code:
    ArrayList<String> myArrayList = new ArrayList<String>();
  14. The Life-Cycle Methods of a JavaFX Application

    by , 12-09-2016 at 07:51 PM (A JavaFX Blog)
    The methods of the javafx.application.Application class that define the life cycle of a JavaFX application are the following:

    • public void init()
    • public abstract void start(Stage primaryStage)
    • public void stop()

    The init() method is called right after an Application object is instantiated, and can be used for application-specific initializations; however, GUI operations such as creating stages or scenes cannot be done from within this method, because at the time ...

    Updated 12-11-2016 at 07:16 PM by JavaFX

    JavaFX Application
  15. How to Filter JavaFX Events in a Scene Graph

    by , 12-11-2016 at 07:45 PM (A JavaFX Blog)
    JavaFX has a powerful event dispatch mechanism that allows different Node elements in a scene graph to intercept GUI events before and after they are delivered to their target node. Every time a new event is generated, an event dispatch chain is built for that event: this chain starts from the stage of the application window, continues with the scene displayed on that stage, and then follows the scene graph down to the target node of the event. For example, when a user clicks on a button in an application, ...
  16. Reflection example - accessing private data

    by , 05-21-2011 at 06:28 PM (My Java Tips)
    If you think that you cannot access private data members of a class from some other class, then think again. With Reflection, this is possible.

    Using reflection, we can see / view / access a private member, private variable, private method. Some people will not like this with argument that this actually means messing up the laws of encapsulation. I use it for unit testing private methods.

    Example follows:

    Java Code:
    import java.lang.reflect.Field;
    Tags: reflection Add / Edit Tags
    Java SE
  17. Book Recommendations

    by , 06-20-2011 at 10:34 PM
    In this article I plan to create a quick, easy to locate post about good books that I have encountered. Feel free to comment and add your book recommendations. I plan to include more than just Java books in this post. I will start with Java, moving onto c++, and other languages. The end of the post with books I have on my short list. These books will be finished shortly and I will put them here, and update my thoughts as the books are finished.

    Starting out - Which book to get?
  18. The Decorator pattern

    by , 07-23-2011 at 03:42 PM (JosAH's blog)

    the previous blog article talked a bit about the Visitor design pattern. This article talks a bit about additional functionality that is sometimes wanted, i.e. the functionality is optional. Assume there is a lot of optional functionality that people want.

    This article discusses the Decorator (or 'Wrapper') pattern. For the sake of the example we'll use array manipulation. People always fiddle diddle with arrays, i.e. they copy values from one array to another, ...

    Updated 07-23-2011 at 03:45 PM by JosAH

  19. Override/Implement methods

    by , 05-21-2011 at 11:14 PM (My Java Tips)
    Eclipse provides an easy way to generate stubs for the parent classes and implemented interfaces.

    Right click the your class and select Source > Override/Implement methods. You will be presented a window where you can select all the methods that you want to override/implement. This methods will be from the implemented interface or extended class.

    Name:  eclipseoverride.jpg
Views: 559
Size:  20.1 KB

    Really saves time. Do try this.
  20. Recursion

    by , 06-20-2011 at 05:39 AM

    Recursion is defined as:
    1. the act or process of returning or running back
    2. logic, maths the application of a function to its own values to generate an infinite sequence of values. The recursion formula or clause of a definition specifies the progression from one term to the next, as given the base clause f (0) = 0, f ( n + 1) = f ( n ) + 3 specifies the successive terms of the sequence f ( n ) = 3 n

    In this article, I hope to make ...

    Updated 06-20-2011 at 05:48 AM by sunde887

  21. jmap - jdk provided heap observation utility

    by , 06-25-2011 at 02:15 PM
    jmap is one of the lesser known jdk provided utilities, which are worth mentioning. Very oftenly we feel the need to peek into the jvm and see which thread is taking how much of heap space - jmap is jdks answer to this.

    This utility was introduced in jdk1.5 and is as an experimental utility (oracle may discontinue to ship this utility with future releases)

    Some of the notable features of jmap are:

    1. can print shared object memory maps or heap memory ...
  22. Difference Between Comparable And Comparator Interface

    by , 11-08-2011 at 07:29 PM (My Java Tips)
    Programmers are usually confused between "Comparable" and "Comparator" interface. Comparable interface has "compareTo" method which is normally used for natural ordering but Comparator interface has "compare" method which takes two arguments. It can be used where you want to sort objects based of more then one parameter. Following example will make it more clear.

    Java Code:
    package test;/*
     ** Use the Collections.sort to
  23. Fetching HTML content of a Web Page

    by , 11-10-2011 at 05:46 PM (My Java Tips)
    Sometimes you are required to fetch and store data from web pages. If there are too many pages to parse, then obviously this cannot be done manually. Java provides support for web text extraction.

    The approach is simple. You have to fetch all the HTML contents of a webpage and then you can write your own parser to extract the required info. For example: you might be asked to only store the text in table data tag with caption Hobbies. So you will store all the HTML contents of web ...
  24. The Five Tiers in Java EE

    by , 11-19-2011 at 06:57 PM (My Java Tips)
    This post briefly explains the 5 tiers in Java Enterprise Edition.


    A web browser, a hand held device or an application which remotely accesses the services of an enterprise application are examples of a Client tier. In other words a Client tier can consists of all the types of components that are clients of an enterprise application.


    Filters, Java Servlets, JavaServer Pages, JavaBeans and other utility classes ...
  25. A recursive method for searching an array of integers...

    by , 03-08-2012 at 09:49 PM
    Java Code:
    public class ArrayLister {
    	private static int arraySearcher(int[] arrayToSort,int numberToFind,int left,int right){
    		int middle = (left + right) / 2 ;
    			if(arrayToSort[middle] == numberToFind) {
    				return middle;
    				return -1;
    		if(arrayToSort[middle] == numberToFind) {
  26. Create SQL File in Eclipse

    by , 05-21-2011 at 11:03 PM (My Java Tips)
    SQL files can be created manually in any existing eclipse project. It's simple and useful. I'll list the required steps.

    • Open Database Development perspective
    • Select File > New > Other, expand SQL Development, select SQL File, and click Next
    • This will open the New SQL File wizard.
    • To create a new project, click "Create Project" and follow the wizard instructions. Now provide the SQL file name.
    • Select a connection profile type from the Connection profile
    Tags: eclipse, sql Add / Edit Tags
  27. The Singleton pattern

    by , 08-12-2011 at 05:29 AM
    In mathematics a singleton (not to be confused with a simpleton) is a set with exactly one element.
    In computer science Singleton is a pattern which enforces the existence of only up to one instance of a class.

    Singleton is sometimes considered an anti-pattern, and it's famous for being considered unnecessary in the world of Python (where you duck type).
    Singleton is however useful, it is a nice and clean why to restrict the number of instances, to only one.
    In ...

    Updated 08-12-2011 at 07:13 PM by Hibernate (typo)

  28. Decorator Pattern Example

    by , 03-03-2012 at 10:27 PM
    Java Code:
    package decoratorPattern;
    public abstract class Beverage {
    	String description;
    	int size;
    	public Beverage(int size) {
    		this.size = size;
    	public String getDescription() {
    		String mySize = null;
    		if(size == 1)
    			mySize = "Small";
    		else if(size==2)
    		else if(size==3)
  29. Using the Observable - Observer class , interface in JAVA. Observer Pattern example.

    by , 03-03-2012 at 11:00 PM
    Java Code:
    package observerPatternBuiltIn;
    import java.util.Observable;
    public class MyObservable extends Observable {
    	int integerToBeObserved;
    	public void setInt(int i) {
    		integerToBeObserved = i;
    	public int getInt() {
    		return integerToBeObserved;
    package observerPatternBuiltIn;
  30. java (7) equivalent of .Net timespan

    by , 07-28-2012 at 08:03 AM
    Quote Originally Posted by .paul. View Post
    i used Dates in this particular case, as they were better suited to the application.

    but i also created a java TimeSpan class, similar to the .Net Framework TimeSpan class:

    Java Code:
    package javaTimeSpans;
     * @author Paul
    public class TimeSpan {
        private int _days;
        private int _hours;
        private int _minutes;
        private int _seconds;
        public int Days(){
Page 1 of 2 12 LastLast