View RSS Feed

Most Popular Blogs

  1. Java ArrayList : Generics & Sorting

    by , 07-21-2011 at 06: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
  2. Adding "Global" KeyListener

    by , 10-17-2011 at 06: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 08:33 AM by DuvanSlabbert

    AWT and Swing
  3. Fetching contact field (PIM)

    by , 11-06-2011 at 06: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
  4. Asynchronous method calls

    by , 11-07-2011 at 06: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.
  5. Simple Frame Transitions without Complex Code

    by , 03-22-2012 at 07: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 ...
  6. Class and Method Cheat Sheet

    by , 10-17-2012 at 10: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 12:30 AM by penguinCoder

    Cheat Sheet
  7. Scanner Class Cheat Sheet

    by , 10-18-2012 at 12: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 12:29 AM by penguinCoder

    Cheat Sheet
  8. ArrayList Cheat Sheet

    by , 10-29-2012 at 11:17 AM
    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>();
  9. The Life-Cycle Methods of a JavaFX Application

    by , 12-09-2016 at 06: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 06:16 PM by JavaFX

    JavaFX Application
  10. Book Recommendations

    by , 06-20-2011 at 09: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?
  11. The Decorator pattern

    by , 07-23-2011 at 02: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 02:45 PM by JosAH

  12. Reflection example - accessing private data

    by , 05-21-2011 at 05: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
  13. Recursion

    by , 06-20-2011 at 04: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 04:48 AM by sunde887

  14. jmap - jdk provided heap observation utility

    by , 06-25-2011 at 01: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 jdk’s 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 ...
  15. Difference Between Comparable And Comparator Interface

    by , 11-08-2011 at 06: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
  16. Fetching HTML content of a Web Page

    by , 11-10-2011 at 04: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 ...
  17. The Five Tiers in Java EE

    by , 11-19-2011 at 05: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 ...
  18. A recursive method for searching an array of integers...

    by , 03-08-2012 at 08: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) {
  19. The Singleton pattern

    by , 08-12-2011 at 04: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 06:13 PM by Hibernate (typo)

  20. Decorator Pattern Example

    by , 03-03-2012 at 09: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)
  21. Using the Observable - Observer class , interface in JAVA. Observer Pattern example.

    by , 03-03-2012 at 10: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;
  22. java (7) equivalent of .Net timespan

    by , 07-28-2012 at 07: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(){
  23. Create SQL File in Eclipse

    by , 05-21-2011 at 10: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
  24. XML Prolog

    by , 11-01-2011 at 05:15 PM (My Java Tips)
    Developer who are working with XML, should know about XML prolog. This post will brief you about the said topic.

    Its an optional component of the XML document. If you wish to include it, then it must appear before the root element. A prolog consists of two parts:

    Part 1 comprises of XML declaration
    Part 2 comprises of Document Type Declaration (DTD)

    You can include both depending on your needs.


    <!--?xml ...
  25. Unary operators

    by , 11-02-2011 at 06:09 PM (My Java Tips)
    I will present an an example that will show the use of following uniary operators: Unary minus operator, Increment operator, Decrement operator, Logical compliment operator

    Unary plus operator (+) indicates positive value. This (+) operator is used to perform a type conversion operation on an operand. The type of the operand must be an arithmetic data type i.e. if a value of the integer operand is negative then that value can be produced as a positively applying unary plus (+) operator. ...
    Java SE
  26. Example - HashMap

    by , 11-02-2011 at 06:11 PM (My Java Tips)
    Map is an object that stores key/volume pairs. Given a key, you can find its value. Keys must be unique, but values may be duplicated. The HashMap class provides the primary implementation of the map interface. The HashMap class uses a hash table to implementation of the map interface. This allows the execution time of basic operations, such as get() and put() to be constant.

    This code shows the use of HaspMap. In this program HashMap maps the names to account balances.
    Java SE
  27. LinkedList (Generics)

    by , 11-03-2011 at 12:07 PM (My Java Tips)
    Like Vectors and ArrayLists, LinkedList can also be made to deal with only one type of objects. Lets see how to do that.

    Java Code:
    LinkedList ll = new LinkedList();
    The LinkedList named ll can only store String objects. This is very useful and provides more control over collection. You are always sure that you will get objects of a specific type from the list. ...
    Java SE
  28. Object Pointer In Java

    by , 11-08-2011 at 05:43 PM (My Java Tips)
    Pointer in C/C++ denotes to the variables saving the reference, In Java there is only call by reference. But here the pointer refers to an object which itself has another reference within it.

    Java classes can have instance variables. If an instance variable is of class type, then it can hold instance of the class in it. This is called pointer to the object.

    In some cases, we need an object that contains an instance variable that can refer to another object of the same ...
    Java SE
  29. Tracking Class Loading and Garbage Collection

    by , 11-08-2011 at 06:41 PM (My Java Tips)
    When any Java program runs, In background some libraries are loaded by JVM (Java Virtual Machine) in order to execute the Java program. Java command line tool(”java”) has various options that might be helpful for a Java programmer to know more about the class loading mechanisms.

    For example “ –cp “ option that instructs JVM to find necessary classes other than system classes. An usage is shown below

    java -cp ExampleDir.ExampleTipIf ExampleTip.class is not found in ExampleDir ...
    Tags: command line, jvm Add / Edit Tags
    Java SE
  30. Plugin project - Overview page

    by , 11-17-2011 at 06:30 PM (My Java Tips)
    This post is about the overview page for plugin project.

    The Overview page is designed to be a quick reference on how to develop, test and deploy a plug-in. It is also a navigational center where you can follow the hyperlinks to navigate a particular page or execute a particular command.

    Plugin overview

    The Plug-in Content section explains the structure and content ...
Page 1 of 2 12 LastLast