View RSS Feed

All Blog Entries

  1. Object references

    by , 11-21-2011 at 04:58 PM (My Java Tips)
    In this post, I will be talking about how to refer to an object. I will present a simple example to make things obvious.


    We have a class called Student. It had 2 attributes, getter setter methods and a method named showAll() to show the contents of both the attributes.

    Java Code:
    public class Student {
    
    	private int id;
    	private String name;
    
    	public Student(int id, String name) {
    		this.id = id;
    		this.name = name;
    ...
  2. Method signatures

    by , 11-21-2011 at 04:52 PM (My Java Tips)
    In this post, I will present an interesting example related to method signature.


    Method signature comprise of the following:

    - method name
    - return type
    - input parameters
    - access modifier

    For example:

    Java Code:
    public Vector processText(String test, int id)
    Two methods in a class can have same name provided then have different parameters. Different parameters means different no of parameters and ...
  3. Using static and final attributes An example

    by , 11-21-2011 at 04:47 PM (My Java Tips)
    In this post, I will present an example which used static and final keywords with attributes in meaningful way. I hope after going through this, you will develop good understanding of these.


    As may know, that we may access static member of class without using any object of that class. Final field/attribute means that you cannot change its value. If you try to change the value of final attribute, you will get an error some this like this:


    Exception in thread ...
  4. Java Data Object (basics)

    by , 11-21-2011 at 04:42 PM (My Java Tips)
    Java Data Object (JDO) can be used to build an application that creates, reads, updates, and deletes persistent instances of Java classes. These objects can be persisted on to relation database, object oriented database or on to XML files. This depends on the implementation of JDO you are using.

    One needs to get the basics before starting working with JDO. Once you have the basics, you can map java objects to the data source transparently.

    JDO allows you to map your ...
    Categories
    JDO
  5. JDO Byte Code Enhancement

    by , 11-21-2011 at 04:39 PM (My Java Tips)
    In order to store instances of a class into data store, a class has to be persistence capable. There are different ways to make a class persistence capable. One of the way is Byte Code Enhancement.


    When a Java class is compiled, a class file is generated. It contains the byte code. To make a class persistence capable, some extra code will surely be added to our source. In order to make the process transparent, byte code modification can be done. So this works even, if you dont have ...
  6. @SuppressWarnings annotation

    by , 11-21-2011 at 04:34 PM (My Java Tips)
    In this post, I will be talking briefly about SuppressWarnings annotation.


    Java compiler gives you warnings to assure that you know what is happening. Sometimes, you want dont want the warnings. Java 5.0 provides a way for this.

    One had to use SuppressWarnings annotation to ignore the warnings. Annotations are followed by @.

    For example: consider the following code:
    Java Code:
    int a;
    Object object = new Object();
    I declared two variables ...
  7. Singleton - Creational Design Pattern

    by , 11-20-2011 at 06:14 PM (My Java Tips)
    The Singleton Design Pattern is the most commonly used design pattern in Java. The Singleton Design Pattern is a Creational Design Pattern. It governs the instantiation process. Sometimes in programming only one object is required across the system. The Singleton Design Pattern is used to achieve exactly that, that is to restrict instantiation of a class to one object. The Singleton Design Pattern ensures a class has only one instance, and provides a global point of access to it.


    ...
  8. Adapter design pattern

    by , 11-20-2011 at 06:10 PM (My Java Tips)
    A Adapter design pattern is Structural design pattern. It is also called as wrapper pattern or just a wrapper. Some classes could not work together because of incompatible interfaces. An adapter allows classes to work together by wrapping its own interface around that of an already existing class. The adapter also handles the logic necessary to transform data into an appropriate form.


    The adapter design pattern is useful in circumstances where an already existing class provides some ...
  9. The Facade Design Pattern

    by , 11-20-2011 at 06:05 PM (My Java Tips)
    The Facade Design Pattern is a structural design pattern amongst the design patterns. A facade is actually an object. It provides an uncomplicated interface to a larger body of code, for example a class library.


    As a facade has simple and tailored methods for common tasks. A facade can make a software library easier to use and understand. A facade also makes the code that uses the library more readable. A facade assists in developing a more flexible system. It reduces dependencies ...
  10. The Observer Design Pattern

    by , 11-20-2011 at 06:00 PM (My Java Tips)
    The Observer design pattern is a Behavioral design pattern. It is used to observe the state of an object in the program. In Observer pattern object(s) are registered to observe an event that may be raised by the observed object. Simply put the Observer pattern allows one object called the observer to watch another object called the subject.


    The observer pattern can listen to an external event, for example a user action. The observer pattern is also used to create a loose coupling ...
  11. Extract superclass

    by , 11-20-2011 at 05:49 PM (My Java Tips)
    Inheritance is a very useful feature that object oriented languages provide. Normally you write parent class first and then the child class. When the design of the application is not final, you tend to put more code in a class than required. At some instance, you realize, that you may make a super class and put some methods in it. Eclipse provide an easy way to do this.


    Lets take an example. We have following class:


    Java Code:
    public class CSVFile{
    ...
  12. Extract Interface

    by , 11-20-2011 at 05:43 PM (My Java Tips)
    Eclipse provides the possibility to extract interface from a class. You may call it reverse engineering since rule of thumb is to write the interface first and then write the classes implementing it. But sometimes, its the other way around. You write a class and then you want to generate the appropriate interface for it. Lets see how to do this.


    I wrote a class that has to do with text extraction from CSV files. I named it CSVFile.

    Java Code:
    import java.util.ArrayList;
    ...
  13. An interface extending an interface

    by , 11-20-2011 at 05:37 PM (My Java Tips)
    The subject topic is very interesting and I decided to write something on it. I hope it will be useful.


    You know about the interfaces. They do not contain the implementation details, rather they contain the method signatures. The class implementing an interface, has to provide the implementation for each interface method. An interface in implemented using the keyword implements.


    Java Code:
    Class Room implements IOffice
    {
    
    The keyword extends ...
  14. The Strategy Design Pattern in Java

    by , 11-20-2011 at 05:25 PM (My Java Tips)
    The strategy design pattern is one of the most fundamental design pattern. The strategy pattern is a design pattern with the help which algorithms can be selected in a real time. The Strategy pattern is behavioral design pattern. The strategy pattern is very useful when it is needed to swap the algorithms used in an application at runtime.


    The strategy pattern is used to define a family of algorithms, encapsulate each one, and make them interchangeable. The strategy design pattern ...
  15. JSP implicit Session object

    by , 11-20-2011 at 05:19 PM (My Java Tips)
    Session Object is another implicit JSP object that denotes the data associated with a specific session of a user. It is associated to Javax.servlet.http.httpsession.


    The connection between client and the server is provided by the session object. It maintains states when there are multiple page requests. If the user is navigating between multiple pages, and you need to store some data associated with that user, then session object helps you in this.

    Some useful session ...
  16. Enhanced for-loop (Java 5.0)

    by , 11-20-2011 at 05:14 PM (My Java Tips)
    Java 5.0 introduced an enhanced for-loop. In this post, I'll write about it.


    The enhanced for loop provides a simple structure allows one to simplify code by presenting for-loops that visit each element of an array/collection without explicitly expressing how one goes from element to element.

    The new for loop makes programming simpler. For example, if you want to print each element for an array, you used to do that with a for loop in the following way:

    ...
    Categories
    Java SE
  17. Handling Cookies in JSP

    by , 11-20-2011 at 05:04 PM (My Java Tips)
    Cookies are text files that are downloaded onto a visitor's hard drive to store the visitor's actions in order to better
    customize their following visits. We may handle cookies in JSP and I will show you how to do that.


    JSP provides an implicit response object which is used to add cookies. To add a cookie to the response, addCookie method is used.
    We may store useful information in cookies for later use and this method is perfect for our needs.
    Java Code:
    response.addCookie(Cookie
    ...
    Categories
    Java EE , JSP
  18. Checking if Session is new

    by , 11-19-2011 at 06:26 PM (My Java Tips)
    Sessions are used to keep track of the user in applications. Specifically talking about web applications (JSP), we may store objects in the session as well for using them later. Sometimes we wish to know if the session is new or not. This post will show how to do that.


    If a session is new, then isNew method of session object will return true otherwise false. When a server creates a session and client has not yet acknowledged the session, the server marks it with new. When the client ...
    Tags: isnew, sessions Add / Edit Tags
    Categories
    Java EE , JSP
  19. Startup time

    by , 11-19-2011 at 06:22 PM (My Java Tips)
    Java programming language is undoubtedly one of the leading programming languages amongst new breed of programming languages. Though it is considered to be the best in the industry, it too has its own limitations, flaws due to certain unavoidable programming constraints which Java follows.


    Execution of Java program is said to be slow and it requires more memory when compared with programming languages such as C, C++ etc. Programs written in C, C++ are natively compiled, where as Java ...
  20. Performance issues related to trigonometric functions , floating point arithmetic and

    by , 11-19-2011 at 06:19 PM (My Java Tips)
    I have briefly listed the performance issues related to trigonometric functions, floating point arithmetic functions and Java Native Interface. I hope these will be helpful.



    Trigonometric functions

    In Java, results got from trigonometric functions and calculations may not be as accurate as that of results got from trigonometric functions and calculations of C language. This is because because Java has strict specifications for the results of mathematical operations.This ...
  21. Performance issues related to Look and Feel of GUI

    by , 11-19-2011 at 06:15 PM (My Java Tips)
    When you use Java Swing or Java Foundation Classes (JFC) for your GUI application development the look and feel of GUI application is not the same as the look and feel of your operating system as JFC or Java Swing has its own built in look and feel. Although, if you want you can achieve the same look and feel as of your operating system's by using Java's Abstract Window Toolkit (AWT), the AWT toolkit is unable to meet advanced GUI programming requirement.


    The Java Foundation Classes ...
    Tags: awt, java swing, jfc, swt Add / Edit Tags
    Categories
    Performance
  22. Handling ASCII character set in Java

    by , 11-19-2011 at 06:11 PM (My Java Tips)
    In this post, I will talk about ASCII character set and how to deal with ASCII codes in Java.


    ASCII character uses 7 bits for character representation. This means that there are total of 128 characters supported by ASCII set. Point to note is that there are only 93 printable characters in ASCII whose ASCII codes are from 33 till 126.

    Java supports all popular character including UTF. But sometimes you only want the input to comprise of ASCII printable characters. This ...
  23. IDL Plugin for Eclipse

    by , 11-19-2011 at 06:06 PM (My Java Tips)
    Developers working on CORBA often complains that writing IDL takes time. If you are new to it, you are bound to make a lot of mistakes. You need something to assist you in writing IDL. Fortunately, Eclipse has a plugin for this.



    Eclipse CORBA plugin can be downloaded from:
    http://sourceforge.net/project/showf...roup_id=111345

    You need Eclipse 3.2 or higher to use this plugin.

    ...
  24. Design Patterns - Basics

    by , 11-19-2011 at 06:01 PM (My Java Tips)
    A design pattern is an abstraction at a very high level. It is to create common and reusable solutions to the recurring problems. Design Patterns provide solutions to design problems which arise again and again in a certain design situations. As a result design patterns have become immensely popular and are very useful to known design issues and problems.


    There are several ways to use and implement these design patterns. These implementation details are called strategies.
    ...
  25. 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.



    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 ...
  26. Creating and visualizing graphs - JGraphT

    by , 11-19-2011 at 05:54 PM (My Java Tips)
    Graphs are used to represent knowledge in a visual form. There are many types and forms of graphs. Java provides support for graphical structures. In this post, I will talk about JGraphT which is a free Java graph library.


    You may download the library from:
    http://prdownloads.sourceforge.net/j...3.zip?download

    Creating and visualizing the graph is very easy:
    Java Code:
    // create a JGraphT graph
    ListenableGraph g = new ListenableDirectedGraph(
    ...
    Categories
    Graphs
  27. The Intercepting Filter

    by , 11-19-2011 at 05:50 PM (My Java Tips)
    In a client-server environment, a system must be able to handle client requests with different processing needs before sending them to server.


    - The system receives requests from a client with different protocols such as HTTP, FTP, SMTP etc.
    - The system must authorize and authenticate some requests, where as for some requests it is not necessary to authorize and authenticate requests and system can handle such requests directly.
    - From certain requests and responses ...
  28. Applets with parameters

    by , 11-19-2011 at 05:37 PM (My Java Tips)
    Applets may accept parameters. This post briefly shows how to do that.


    Applet in included in HTML using APPLET tag. You have to specify the parameters in APPLET tag in the following form:
    Java Code:
    <applet code="AppletSubclass.class" width="anInt" height="anInt">
    <param name="parameter1Name" value="aValue"></param>
    <param name="parameter2Name" value="anotherValue"></param>
    ...
    Categories
    Java SE
  29. MVC Model

    by , 11-19-2011 at 05:18 PM (My Java Tips)
    The Model is the one which is responsible for managing data storage as well as retrieval of the data from the data source. When data changes it notifies all its Views about change in data. A model holds part of the current state of the application. The model represents enterprise data and the business rules that govern access to and updates of this data. The Model knows everything about the data that need to be displayed. However, it does not know anything about the View, that is the manner in ...
  30. MVC Controller

    by , 11-19-2011 at 05:07 PM (My Java Tips)
    In this post, I will briefly talk about MVC controller.


    Controller manages users interaction with the system. The component Controller is perhaps the most important component in the MVC architecture. It invokes the component Model and the component View and also couples these two that is View with the Model. If the application requires, it may invoke multiple Views and may couple them with the same Model. It listens to the user actions and according to business rules manipulates the ...
Page 34 of 48 FirstFirst ... 24323334353644 ... LastLast