View RSS Feed

All Blog Entries

  1. Creating a Thread (extending Java Thread Class)

    by , 11-13-2011 at 11:41 AM (My Java Tips)
    There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started. The other way to create a thread is to declare a class that implements the Runnable interface. That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started.


    In case, ...
  2. Creating a Thread (implementing Java Runnable Interface)

    by , 11-12-2011 at 06:58 PM (My Java Tips)
    A better way to create a thread in Java is to implement Runnable interface. A thread can be created by extending Java Thread class also. Now the question arises why implementing Runnable interface is a better approach? Answer is, if the thread class you are creating is to be subclass of some other class, it canít extend from the Thread class. This is because Java does not allow a class to inherit from more than one class. In such a case one can use Runnable interface to implement threads.
    ...
  3. Implementing ActionListener interface

    by , 11-12-2011 at 06:54 PM (My Java Tips)
    ActionListener interface is used to perform actions on a performed event. In this post, I will write about its importance and usage.


    ActionListener interface is part of java.awt.event package. It has only one abstract method that has to be implemented in the class implementing this interface.

    Method signature:
    void actionPerformed(ActionEvent e)

    Consider the following scenario: you developed an GUI form for an application comprising of text fields, ...
  4. Creating ZIP files

    by , 11-12-2011 at 06:49 PM (My Java Tips)
    We all use ZIP files in daily routine. They are of great use specially when we want to transfer the files over the network. In this post, I will write about how to create zip files in Java.


    Java.util.zip package provides classes to play with zip files. So first step is to import the package. We will need ZipOutputStream and ZipEntry class from this package. Import the complete package or just these classes - it depends on you. It does not have any affect on the performance.
    ...
    Categories
    Java SE
  5. Using PostgreSQL JDBC driver

    by , 11-12-2011 at 06:45 PM (My Java Tips)
    PostgreSQL is a popular open source object-relational database management system that is being used for small and medium sized applications. We have two options to connect to PostgreSQL. One is to use odbc/jdbc connection and the other is to use PostgreSQL JDBC driver. In this post, I will write about how to use PostgreSQL JDBC driver to connect to PostgreSQL database.


    First of all, you will need PostgreSQL database driver. It can be downloaded from
    http://jdbc.postgresql.org/download.html ...
    Categories
    JDBC
  6. Incorporating native code (C/C++)

    by , 11-12-2011 at 06:42 PM (My Java Tips)
    JNI (Java Native Interface) is a powerful feature that provides the developers to call legacy code written in C/C++ and Java. In the post, I will briefly introduce how JNI helps us in doing so.


    First step is to create a Java class that declares native method. Native methodís signature contains keyword native and it indicates that this method is implemented in another language. Native method declaration is terminated with a semicolon. Also note that native method does not contain implementation. ...
    Categories
    Java SE
  7. Using PreparedStatement

    by , 11-12-2011 at 06:36 PM (My Java Tips)
    SQL statements are executed on a database tables using Statement object. If the sql statement takes parameter, then it is a wise decision to use PreparedStatement as they are more flexible and makes coding easier.


    Creating SQL statements that take parameters provides flexible statements to work with. We can use the same statement and supply it with different values each time we execute it.

    We use place holders (question marks) in the query, which are supplied values ...
    Categories
    JDBC
  8. Internationalization

    by , 11-12-2011 at 06:31 PM (My Java Tips)
    Internationalizing Java applications is of great importance if you are planning to develop an application to be used in different parts of the world. In this post, I will try to develop a simple internationalized application.


    Different regions of the world have different languages, currency and time zone. Developing a Java application that can be used throughout the world without much changes is the requirement of this age. Internationalized applications are the solution. Internationalized ...
  9. Creating JAR files

    by , 11-12-2011 at 06:25 PM (My Java Tips)
    JAR (Java Achieve Files) are compressed files that are used to bundle multiple files into a achieve file so the distribution can be managed easily. In this post, I will write about how to create JAR files.


    JDK includes a JAR tool that is used for creating JAR files. Command to use is:
    jar cf jar-file input-file(s)

    c indicates that we want to create a JAR file.
    f indicates that ouput should go to the file
    jar-file is the name of the jar file that ...
    Categories
    Java SE
  10. Calling stored procedures

    by , 11-12-2011 at 06:21 PM (My Java Tips)
    Stored procedures contain set of SQL statements and are stored on the database server. Their query execution plan is already define, so they run faster and improve the performance. In this post, I will talk about how to call stored procedures.


    An object of CallebleStatement (extends PrepareStatement) is used to execute store procedures. PrepareCall() method is use to create CallebleStatementís object.

    Java Code:
    CallebleStatement cst;
    Cst = conn.prepareCall(ď{call
    ...
  11. Simple JSF Application

    by , 11-12-2011 at 06:15 PM (My Java Tips)
    Java Server Faces (JSF) defines three layers of architecture: component architecture, a standard UI widget, and application infrastructure. Where architecture allows standard JSF UI widgets and provide platform for third party components. JSF strictly follow MVC2 pattern, with a more stress on view side. It uses standard jsp with customized tags.


    Here we will develop a simple web application to demonstrate JSF.

    Consider the following jsp file called welcome.jsp
    ...
  12. Types of JDBC drivers

    by , 11-11-2011 at 06:44 PM (My Java Tips)
    There are 4 different types of JDBC drivers that can be used in Java database applications. Which driver to use, depends on the requirements and available resources. I will briefly talk about each driver.


    Type 1 is JDBC-OBC bridge driver. It is pure Java and is include in java.sql.*. The client needs ODBC driver manager and ODBC driver for data source. It is ideal in situations, when ODBC driver is available for the database and is already installed on the client machine.
    ...
  13. Batch updates

    by , 11-11-2011 at 06:41 PM (My Java Tips)
    Updating a record from Java using executeUpdate() method of Statement object is used commonly by JDBC programmers. Thing to note is that this is a costly activity in terms of time, as a database trip is made. As a programmer/developer, our aim should be to write efficient Java code. In this post, I will write about how you can efficiently make several updates.


    Batch update allows us to execute several update statements in a batch. It means only one database trip will be make, thus ...
    Categories
    JDBC
  14. Random Access File

    by , 11-11-2011 at 06:38 PM (My Java Tips)
    Instances of this class support both reading and writing to a random access file. A random access file behaves like a large array of bytes stored in the file system. There is a kind of cursor, or index into the implied array, called the file pointer; input operations read bytes starting at the file pointer and advance the file pointer past the bytes read. If the random access file is created in read/write mode, then output operations are also available; output operations write bytes starting at ...
  15. Data Streams

    by , 11-11-2011 at 06:35 PM (My Java Tips)
    Data streams support binary I/O of primitive data type values (boolean, char, byte, short, int, long, float, and double) as well as String values. All data streams implement either the DataInput interface or the DataOutput interface.


    If you need to work with data that is not represented as bytes or characters then you can use Data Streams. These streams filter an existing byte stream so that each primitive data types can be read from or written to the stream directly.

    ...
  16. Buffered Streams

    by , 11-11-2011 at 06:33 PM (My Java Tips)
    When we use unbuffered I/O, each read or write request is handled directly by the underlying OS. This can make a program much less efficient, since each such request often triggers disk access, network activity, or some other operation that is relatively expensive. To reduce this kind of overhead, the Java platform implements buffered I/O streams.


    Class BufferedReader reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, ...
    Categories
    Streams
  17. Character Streams

    by , 11-11-2011 at 06:31 PM (My Java Tips)
    Character Streams handle I/O of character data, automatically handling translation to and from the local character set. All character stream classes are descended from Reader and Writer. As with byte streams, there are character stream classes that specialize in file I/O: FileReader and FileWriter. The Java platform stores character values using Unicode conventions Character stream I/O automatically translates this internal format to and from the local character set. In Western locales, the local ...
  18. Byte Streams

    by , 11-11-2011 at 06:27 PM (My Java Tips)
    Java IO programs use byte streams to perform input and output of 8-bit bytes. All byte stream classes are descended from InputStream and OutputStream.


    There are many byte stream classes. To demonstrate how byte streams work, we'll focus on the file I/O byte streams, FileInputStream and FileOutputStream. Other kinds of byte streams are used in much the same way; they differ mainly in the way they are constructed.

    A FileInputStream obtains input bytes from a file in a ...
    Tags: byte, java io, streams Add / Edit Tags
    Categories
    Streams
  19. System class

    by , 11-10-2011 at 07:23 PM (My Java Tips)
    The System class is a very useful which contains static fields and methods. It cannot be instantiated. In this post, I will briefly write about System class and will explore few interesting methods.


    System class belongs to java.lang package, so it can be used in any Java class without importing any package. System class provides static methods that are very useful. For example to get current time in milliseconds:

    Java Code:
    static long currentTimeMillis()
    ...
  20. Introduction to Standard Widget Toolkit

    by , 11-10-2011 at 07:18 PM (My Java Tips)
    AWT (the Abstract Windowing Toolkit) was the first Java GUI toolkit, introduced with JDK 1.0 as one component of the Sun Microsystems Java standard. The relatively primitive AWT wrapped Java code around native (operating system-supplied) objects to create GUI elements, such as menus, windows and buttons. AWT was a very thin wrapper around native widgets, exposing developers to platform specific code, quirks and bugs that limited how portable and native-looking applications could be across different ...
  21. SWT Text

    by , 11-10-2011 at 07:12 PM (My Java Tips)
    Text is a selectable user interface objects that allow the user to enter and modify text. Events associated with Text are: DefaultSelection, Modify, Verify. Different Text styles are CENTER, LEFT, MULTI, PASSWORD, SINGLE, RIGHT, READ_ONLY, WRAP. Please note that only one of the styles MULTI and SINGLE may be specified.


    The following are the important constructors of Text class.

    Text(Composite parent, int style)
    Constructs a new instance of this class given its ...
  22. SWT Menu

    by , 11-10-2011 at 07:10 PM (My Java Tips)
    Menu are user interface objects that contain menu items. The Menu support styles BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP, LEFT_TO_RIGHT, RIGHT_TO_LEFT. Please note that only one of BAR, DROP_DOWN and POP_UP may be specified. Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.


    The following are the important constructors of Menu class.

    Menu(Control parent)
    Constructs a new instance of this class given its parent, and sets the style for the instance so ...
    Tags: menu, menu items, swt Add / Edit Tags
    Categories
    SWT / JFace
  23. SWT List

    by , 11-10-2011 at 07:07 PM (My Java Tips)
    List is a selectable user interface object that displays a list of strings and issues notification when a string selected. A list may be single or multi select. Events associated with List are Selection, DefaultSelection. Please note that only one of SINGLE and MULTI style may be specified.


    The following are the important constructors of List class.

    List(Composite parent, int style)
    Constructs a new instance of this class given its parent and a style value describing ...
    Categories
    SWT / JFace
  24. SWT Label

    by , 11-10-2011 at 07:02 PM (My Java Tips)
    A label displays a string or an image. The string can be changed by the application, but a user cannot edit it directly. For Label, when SEPARATOR is specified, displays a single vertical or horizontal line.


    The following are the important constructors of Label class.

    Label(Composite parent, int style)
    Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

    The following are the important ...
    Tags: label, separator, swt Add / Edit Tags
    Categories
    SWT / JFace
  25. SWT Group

    by , 11-10-2011 at 06:59 PM (My Java Tips)
    A group is also a control that can contain other controls. A group is surrounded by a border and may, optionally, contain a title. As with composites, the position of each control inside a group is relative to the group, so if the group is moved on the shell, the controls inside the group retain their relative positions.


    Group provide an etched border with an optional title. Shadow styles are hints and may not be honored by the platform. To create a group with the default shadow style ...
    Tags: control, group, swt Add / Edit Tags
    Categories
    SWT / JFace
  26. SWT Dialog

    by , 11-10-2011 at 06:57 PM (My Java Tips)
    Dialog class is the abstract superclass of the classes that represent the built in platform dialogs. A Dialog typically contains other widgets that are not accessible. A Dialog is not a Widget.


    This class can also be used as the abstract superclass for user-designed dialogs. Such dialogs usually consist of a Shell with child widgets. The basic template for a user-defined dialog typically looks something like this:

    Java Code:
     import org.eclipse.swt.*;
     import org.eclipse.swt.widgets.*;
    ...
    Tags: dialog, subclass, swt Add / Edit Tags
    Categories
    SWT / JFace
  27. SWT Composite

    by , 11-10-2011 at 06:53 PM (My Java Tips)
    Composite are controls which are capable of containing other controls. Controls are placed inside a composite in the same manner that Controls are placed on a shell. The position of each widget inside a composite is relative to the composite, so if the composite is moved on the shell, the Controls inside the composite retain their relative positions.


    The styles supported by composites are NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED. ...
    Categories
    SWT / JFace
  28. SWT Combo

    by , 11-10-2011 at 06:50 PM (My Java Tips)
    Combo are controls that allow the user to choose an item from a list of items, or optionally enter a new value by typing it into an editable text field. Often, Combos are used in the same place where a single selection List widget could be used but space is limited. A Combo takes less space than a List widget and shows similar information.


    The following are the important constructors of Combo class.

    Combo(Composite parent, int style)
    Constructs a new instance ...
    Tags: combo, controls, swt Add / Edit Tags
    Categories
    SWT / JFace
  29. SWT Canvas

    by , 11-10-2011 at 06:47 PM (My Java Tips)
    Canvas provide a surface for drawing arbitrary graphics. It supports no styles and events. This is a subclass of class Composite.


    This class may be subclassed by custom control implementors who are building controls that are not constructed from aggregates of other controls. That is, they are either painted using SWT graphics calls or are handled by native methods.

    The following are the important constructors of Canvas class.

    Canvas(Composite parent, ...
    Tags: canvas, swt Add / Edit Tags
    Categories
    SWT / JFace
  30. SWT Button

    by , 11-10-2011 at 06:44 PM (My Java Tips)
    Button is a selectable user interface object that issues notification when pressed and released. It is a widget that is clicked by the user in order to initiate some processing.


    The following are the important constructors of Button class.

    Button(Composite parent, int style)
    Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

    The following are the important methods of Button class. ...
    Categories
    SWT / JFace
Page 38 of 48 FirstFirst ... 283637383940 ... LastLast