View RSS Feed

Most Popular Blogs

  1. Java ArrayList : Generics & Sorting

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


    Abstract

    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){
                    System.out.println(vk);
    ...

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

    Categories
    AWT and Swing
  3. 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 ...
    Categories
    Java ME
  4. 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.
    ...
    Categories
    EJB
  5. 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:

    Trident:
    Project Kenai — We're More Than Just a Forge

    FRC:
    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{
      ...code...
    }

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

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

    Declaring a Class with Fields
    Java Code:
    class ClassName{
      public
    ...

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

    Categories
    Cheat Sheet
  7. 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>();
    ...
  8. 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?
    ...
    Categories
    Uncategorized
  9. The Decorator pattern

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

    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

    Categories
    Uncategorized
  10. 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
    Categories
    Java SE
  11. Recursion

    by , 06-20-2011 at 04:39 AM
    Recursion:


    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

    Categories
    Uncategorized
  12. 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 ...
    Categories
    Uncategorized
  13. 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
    ...
  14. 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 ...
  15. 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.



    Client

    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.

    Presentation

    Filters, Java Servlets, JavaServer Pages, JavaBeans and other utility classes ...
  16. 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 ;
    		System.out.println(middle);
    
    		if(middle==arrayToSort.length-1)
    		{
    			if(arrayToSort[middle] == numberToFind) {
    				return middle;
    			}
    			else
    				return -1;
    		}
    		
    		if(arrayToSort[middle] == numberToFind) {
    			return
    ...
    Categories
    Uncategorized
  17. 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)

    Categories
    Patterns
  18. 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)
    			mySize="Medium";
    		else if(size==3)
    			mySize="Large";
    ...
    Categories
    Uncategorized
  19. 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;
    		setChanged();
    		notifyObservers();
    	}
    	
    	public int getInt() {
    		return integerToBeObserved;
    	}
    
    }
    
    
    package observerPatternBuiltIn;
    
    import
    ...
    Categories
    Uncategorized
  20. 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(){
    ...
    Categories
    Uncategorized
  21. 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
    Categories
    Eclipse
  22. XML Prolog

    by , 11-01-2011 at 06: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.

    Example:

    <!--?xml ...
    Categories
    XML
  23. Unary operators

    by , 11-02-2011 at 07: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. ...
    Categories
    Java SE
  24. Example - HashMap

    by , 11-02-2011 at 07: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.
    ...
    Categories
    Java SE
  25. LinkedList (Generics)

    by , 11-03-2011 at 01: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();
    ll.add("Str1");
    ll.add("Str2");
    ll.addFirst("Str3");
    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. ...
    Categories
    Java SE
  26. Object Pointer In Java

    by , 11-08-2011 at 06: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 ...
    Categories
    Java SE
  27. Tracking Class Loading and Garbage Collection

    by , 11-08-2011 at 07: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
    Categories
    Java SE
  28. Plugin project - Overview page

    by , 11-17-2011 at 07: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 ...
  29. GPS location / Cell id / Placing a call

    by , 11-22-2011 at 06:16 PM (My Java Tips)
    This post presents miscellaneous tasks that you can do in your J2ME application.


    Firstly, how to get GPS location. javax.microedition.location.Location provides support for this. Review the snippet below:

    Java Code:
    LocationProvider loc = LocationProvider.getInstance(null);
    loc.setLocationListener(ll,0,-1,-1);
    Location location = loc.getLocation(60*3);
    String lat = location.getQualifiedCoordinates().getLatitude();
    String lon = location.getQualifiedCoordinates().getLongitude();
    ...
  30. A simple GUI code

    by , 12-18-2011 at 02:25 PM
    Java Code:
    package myPackage;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import javax.swing.*;
    @SuppressWarnings("serial")
    public class SamsLearning extends JFrame {
    	public SamsLearning() {
    		super();
    		this.setTitle("My Title");
    		this.setLookAndFeel();
    		this.setSize(500,500);
    		MyButtonClass myButton = new MyButtonClass("Play");
    		MyButtonClass myButton2 = new MyButtonClass("Stop");
    ...
    Categories
    Uncategorized
Page 1 of 2 12 LastLast