View RSS Feed

All Blog Entries

  1. Javadoc tags

    by , 11-09-2011 at 06:40 PM (My Java Tips)
    JavaDoc comments start with a forward slash and two asterisks (/**) and ends with one asterisk and a forward slash (*/). Everything between the delimiters (even if it spans multiple lines) is a comment.

    * @author Gapper
    * @version 1.0

    One has to use javadoc tags. The following are special tags in Javadoc that have predefined purposes.

    It is used to create links to other javadoc documentation.
    Java SE
  2. Creating JavaDocs – An Example

    by , 11-09-2011 at 06:33 PM (My Java Tips)
    You are developing a software in a team and you are assigned to work on a particular package. You worked on it and submitted it after completion. The development team has to use the classes and methods written by you. To use them, they have to know a lot of things.

    For a class, they should know:
    - Constructors of class
    - Is class a static?

    For a method, they should know:
    - Is method static?
    - Return type of method.
    - Parameter ...
  3. Socket Programming (Server)

    by , 11-09-2011 at 06:14 PM (My Java Tips)
    Socket programming is easy and fun. In this post, I will create a simple Socket Server that will listen on a post for client requests. It will get data from the client and will send the acknowledgment.

    First step is to declare a server socket, a client socket and input/output streams. I assume that you are familiar with streams. Then we have to open a connection on a port. Usually it is not a wise decision to use port number that is less than 1023 because ports less than 1023 are ...

    Updated 11-09-2011 at 06:28 PM by Java Tip

    Network Programming
  4. Socket Programming (Client)

    by , 11-09-2011 at 06:04 PM (My Java Tips)
    I will write a simple socket client, that will connect to the server, send data to the server and well get connection time stamp from the server.

    In the example below, you will learn how to connect to a socket server and how to send and receive data.

    First part is to declare client socket and input/output streams. Then we have to connect to the server using socket. While declaring socket object, we have to mention the host name and the port on which the server is listening. ...
    Network Programming
  5. Abstract Classes/Methods

    by , 11-09-2011 at 05:58 PM (My Java Tips)
    The keyword abstract is used when a class is declared abstract. An abstract may or may not include abstract methods. These classes can be inherited (subclasses) but cannot be instantiated.

    Abstract classes comprise of concrete methods and abstract methods. Concrete methods are methods with body and abstract methods are without body methods. The class implementing the abstract class has to override abstract methods.

    Abstract methods are without implementation (without ...
    Java SE
  6. Performance Issues (String Concatenation)

    by , 11-09-2011 at 05:55 PM (My Java Tips)
    String concatenation is a task that is overlooked by the programmers. In this post, I will write about the performance issues related to string concatenation.

    Strings are immutable objects and to concatenate strings, java has to perform a lot of operations in the background. Consider the following code segment:

    Java Code:
    String a=  "a";
    String b=  "b";
    String str = a + b;
    This is compiled to

    Java Code:
  7. Performance Issues (StringTokenizer)

    by , 11-09-2011 at 05:46 PM (My Java Tips)
    StringTokenizer is a very useful class that is used by developers while parsing text. It works fine and produces the required results.

    Java Code:
    StringTokenizer st = new StringTokenizer(s,",");

    StringTokenizer is very powerful and can handle large sets of delimiters at once. This makes it powerful but a little slow. What if we have a single character delimiter? Should we still use StringTokenizer? If we want to make life easy, the answer is yes. But ...
  8. Performance Issues (adding element to a Vector)

    by , 11-09-2011 at 05:43 PM (My Java Tips)
    Adding elements to a Vector is a normal practice but there are few performance issues related to this which should be considered.

    Elements can be added to Vector using any of the following:

    - insertElementAt(e, index)
    - addElement(e)
    - add(e)
    - add(index,e)

    The addElement(e) and add(e) methods are used to add elements at the end of Vector whereas insertElementAt(e, index) and add(index, e) methods are used to insert element at any ...
  9. An Introduction To JUnit

    by , 11-08-2011 at 07:51 PM (My Java Tips)
    In a big project programmer needs to test his code as a unit, Separately from other part of project. So there was a need of some framework which can provide testing for implementing testing in Java.

    JUnit provides a simple way to explicitly test specific areas of a Java program. It can be used to test a hierarchy of program code either as individual or as multiple units. Using JUnit framework is beneficial because it forces us to explicitly declare the expected results of specific ...
    Tags: junit Add / Edit Tags
    Java SE
  10. Execute An External Program From Java

    by , 11-08-2011 at 07:49 PM (My Java Tips)
    A Java programmer may need to access the environment under which the application is running. It is supported by “ getRuntime ” method in Runtime Class. Programmer need not create an instance of Runtime class, Instead the Java application has a single instance of class Runtime environment in which the application is running.

    Runtime class has several methods that are useful to execute an external program, getting Information about processors, Memory Information etc.

    Java SE
  11. File Operations In Java

    by , 11-08-2011 at 07:48 PM (My Java Tips)
    Through file handling, we can read data from and write data to files besides doing all sorts of other operations. Java provides a number of methods for file handling through different classes which are a part of the “” package.

    The question can arise in the mind of a new programmer as to why file-handling is required. The answer of this question would be in two parts, why do we need to read data from the files and why do we need to save it (write it) to a file.

  12. TCP IP Using Socket Programming

    by , 11-08-2011 at 07:46 PM (My Java Tips)
    TCP is a connection-oriented protocol that addresses numerous reliability issues to provide a reliable byte stream. It ensures that the data arrives in-order, duplicate data is discarded and lost/discarded packets are re-sent. It includes traffic congestion control meaning that if there is too much traffic on the network, appropriate measures are taken which include telling the transmitting hosts to slow down the rate at which the data is being sent out and telling the receiving hosts to increase ...
  13. Threads In Java

    by , 11-08-2011 at 07:43 PM (My Java Tips)
    Threads are small processes that are part of a larger process. A single process may have many threads and even if one of these threads is waiting for input from the user or is blocked or is carrying out a lengthy process, the rest of the threads can continue. An example of this can be a word processor which is a process with many threads such as the spell checker, the grammar checker, the user typing area etc.In Java, thread is just the path of execution.
    In Java, threads are created by two ...
    Tags: sleep, thread Add / Edit Tags
    Java SE
  14. 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
    Java SE
  15. How To Modify A JAR File

    by , 11-08-2011 at 07:40 PM (My Java Tips)
    This assumes a basic understanding about the JAR API's provided by Sun, To know more click here. Now this is a step ahead of that, by which you will be able to add or delete a particular file to the JAR archive.

    Listed below is an example that adds a file to an existing JAR or ZIP file. In the program an intermediate file is created first that will be later replaced with an existing one. To be more precise the intermediate file will be renamed to original one after deleting the old ...
    Tags: jar file Add / Edit Tags
    Java SE
  16. KeyBoard Input Class

    by , 11-08-2011 at 07:39 PM (My Java Tips)
    Taking input from keyboard involves various steps. Lot of people ask for some ready made class which will serve the purpose. Following class is a good choice. You can use "readInt()", "readDouble()", "readChar()" and "readString()" methods according to your needs.

    Java Code:
    public class KeyboardInput {
    	static BufferedReader stdin =
    		new BufferedReader( new InputStreamReader(;
    Java SE
  17. Connectiong To MS Access And Fetching Records

    by , 11-08-2011 at 07:37 PM (My Java Tips)
    JDBC (Java Database Connectivity) is designed to allow user to use SQL(Structured Query Language) to query databases. JDBC makes our tasks easy as it handles all low-level concerns about particular database types. It allows you to query an Access database with exactly the same source code as with an Oracle database.

    JDBC is similar to Microsoft's ODBC with the plus point "Platform Independence". To use JDBC, you need to have database driver to communicate with the database. ...
    Tags: jdbc, sql Add / Edit Tags
  18. How To List Contents Of A JAR File In A Java Program

    by , 11-08-2011 at 07:35 PM (My Java Tips)
    "jar" command line tool is used to create or list contents of a jar file. In a Java Program it is also possible to edit contents of a jar file. In "java.util.jar" package there are five ways to create a JAR file using JarFile.
    Java Code:
        JarFile(File file) .
        JarFile(File file, boolean verify) .
        JarFile(File file, boolean verify, int mode) .
        JarFile(String name) .
        JarFile(String name, boolean verify) .
    Tags: jatfile Add / Edit Tags
    Java SE
  19. Working With Interfaces

    by , 11-08-2011 at 07:33 PM (My Java Tips)
    Interface is very much similar to the Abstract class in Java but the difference is that in interfaces, members (methods) cannot be implemented, member(fields) defined will be treated as constants.
    A class becomes more formal about its behavior after implementing an interface. Interfaces are actually a contract between the class and the outside world. While implementing an interface in a concrete class, you have to implement all the methods defined by that interface. If you miss any method, ...
    Java SE
  20. Enumerations and Iterators

    by , 11-08-2011 at 07:31 PM (My Java Tips)
    An Enumeration is used for iterating over a given collection, Usually of unknown size. Iterator also has the same purpose but Enumeration does not allow modification of the collection, Which can be achieved using Iterator.

    Iterator’s "remove" method removes from the underlying collection the last element returned by the iterator. This method can be called only once per call to the Iterator's "next" method.

    Following code sample will help you understand ...
  21. 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
  22. Taking inputs from users

    by , 11-08-2011 at 07:28 PM (My Java Tips)
    There are a number of ways to take input from user in Java.
    Following code sample helps you in taking input as a character, as a stream and from GUI.
    Required Packages: import and javax.swing packages.

    Java Code:
    // reading character from user
    char a = (char);
    System.out.println("Character read is: " + a);
    // taking input from GUI
    String input = JOptionPane.showInputDialog("What is your name?");
  23. Using Vectors

    by , 11-08-2011 at 07:26 PM (My Java Tips)
    When using arrays, you have to give their size at declaration. So arrays do not expand dynamically. Vectors expand automatically when data is added to them. Vector class is included in java.util package. Vectors are used to store Objects.

    Vector is thread safe. It means Vectors are synchronized, means you can use Vectors even if your object might be shared by two or more threads at a same time. This makes Vector slower than ArrayList which is not thread safe.

    Following ...
  24. Using Arrays in Java

    by , 11-08-2011 at 07:24 PM (My Java Tips)
    Arrays are simply a sequence of memory locations for storing data. The index of an array starts from zero. We have to mention the size of an array while declaring it. Once declared, we cannot change the size at any stage.

    While working with arrays, you will encounter ArrayIndexOutOfBoundsException. This exception is raised if you try to access an element from the array with negative index, or with index greater than the length of index.

    Sorting an array is easy in Java ...
    Tags: array, size fixed Add / Edit Tags
    Java SE
  25. Rotating Elements In a List using Collections.rotate Method

    by , 11-08-2011 at 07:22 PM (My Java Tips)
    Collections have very useful methods. Let us see how to rotate objects in a given list. The method "rotate" has two inputs, a list and a distance parameter which defines rotation distance. The distance can be positive, negative or zero. Objects in the list will be rotated by the specified parameter. Let us take an example to rotate objects of Car class.

    For example, suppose list comprises [t, a, n, k, s]. After invoking

    Collections.rotate(list, 1) ...
  26. How to Sort Objects Using Collections.sort method

    by , 11-08-2011 at 07:19 PM (My Java Tips)
    A programmer usually needs to sort a given set of inputs. Java has inbuilt set of API's for sorting. There is a Comparable interface in java that needs to be implemented by class whose object needs to be compared. Java classes like "Integer", "Date" implements this interface, so object of these classes can be sorted easily by Collection's sort method. We can make a class that implements Comparable interface so that it's objects can be sorted by "Collections.sort" method. ...
  27. Java Reflection API - Overview

    by , 11-08-2011 at 07:08 PM (My Java Tips)
    Concept of Java reflection is very powerful. It gives you access to internal information about the classes (sub classes, methods, attributes) loaded into the JVM. This concept is not available in other programming languages like C and C++.

    Consider the following example. I have displayed the complete signatures of “ MyClass " methods using reflection. First of all, you should obtain a java.lang.Class object for the class that you want to manipulate. “ java.lang.Class " is ...
  28. Java Serialization Overview

    by , 11-08-2011 at 07:04 PM (My Java Tips)
    Serialization is the process of saving the state of an object onto any storage medium. Storage medium can be a file or a memory buffer. Then you can transmit it across a network, either in binary form, or in some human-readable text format such as XML. The object in the form of bytes or any other format can be recreated to its internal state easily. The process of serializing an object is also called “ Marshalling ” an object. Extracting a data structure from a series of bytes, is “ Deserialization ...
    Java SE
  29. Autoboxing And Unboxing in Java 5

    by , 11-08-2011 at 07:01 PM (My Java Tips)
    Java 5 supports automatic conversion of primitive types (int, float, double etc.) to their object equivalents (Integer, Float, Double,...) in assignments, method and constructor invocations. This conversion is know as autoboxing.

    Java 5 also supports automatic unboxing, where wrapper types are automatically converted into their primitive equivalents if needed for assignments or method or constructor invocations.For example:

    Java Code:
    	int inative = 0;
    Java SE
  30. Exception Handling In Java

    by , 11-08-2011 at 06:58 PM (My Java Tips)
    Exception handling is an integral part of programming. In Java exceptions are itself defined as objects in other words throwing an exception is throwing an object. “ Throwable ”, declared in “java.lang package” is the parent class for all the classes that a program can instantiate and throw.

    Basically Throwable has two direct subclasses.


    Exceptions (means members of the Exception family) are thrown to indicate abnormal ...
    Java SE
Page 9 of 17 FirstFirst ... 7891011 ... LastLast