View RSS Feed

All Blog Entries

  1. Java I/O performance

    by , 01-08-2012 at 11:40 AM
    Java has always issues with its I/O performance. To handle large amount of data, it will take significant amount of time. So you must tune and improve your I/O performance. It should be done on high priority by the developer.

    Follow these rules to improve I/O performance.

    • Minimize hard disk access.
    • Minimize OS access.
    • Minimize processing of individual bytes

    Also you can consider following to improve your I/O performance.
  2. Final, finally and finalize

    by , 01-08-2012 at 11:38 AM
    • final – It’s a constant declaration.

    • finally – It handles exception. It is an optional block to write at the end of your exception handling block. It is usually used to close files, close database connections and statements. Also release all other resources in this block.

    • finalize – This method is called by the garbage collector. Garbage collector always called this method before it performs garbage collection on that object. It should not be used to release ...
    Access Modifier
  3. Shallow cloning Vs Deep cloning

    by , 01-08-2012 at 11:36 AM
    By default an object’s clone() yields a shallow copy. You must edit your class to get a deep copy of the cloned object.

    • Shallow copy: As shown in figure, when an object is shallow copied, it does not copy its internal objects. Shallow cloning is supported by default in Java. Implement the interface java.lang.Cloneable to implement shallow cloning.
    • Deep copy: In deep cloning, all the internal objects of the class are also copied as shown in figure below. Serialization supports ...
  4. Serialization

    by , 01-08-2012 at 11:33 AM
    Reading or writing an object is called serialization. It saves an object sate which can be restored at a later stage. Implement the interface to make a class serializable. This interface is also called marker interface. It supports object persistence to a file.

    Name:  56.JPG
Views: 928
Size:  19.3 KB


    If you do not want to serialize an object then mark it as transient. Serialization can affect performance in following ways:
  5. Pass-by-reference vs Pass-by-value

    by , 01-08-2012 at 11:31 AM
    In other languages like C++ you can pass a value by reference or by pointer. In Java when you pass a parameter, the receiving object always gets a copy of the passed parameter. It is also known as pass by value concept. To pass a reference of an object in java as an argument, the passed in object is first copied and then passed to other method. In such cases both will be pointing to same object in memory. Also in this case, you will be modifying the original object for which a reference is passed. ...
  6. String vs. StringBuffer

    by , 01-08-2012 at 11:26 AM
    Following are the major differences between these 2:

    • String is immutable as compared to StringBuffer. You need to create a new instance to replace an object.

    Java Code: This is an example of immutable string
    //Inefficient version using immutable String
    String output = “Some text”
    Int count = 100;
    for(int I =0; i<count; i++) {
    output += i;
    return output;
    • StringBuffer is mutable. Also it is not synchronized.

    Java Code: This is an example of mutable string

    Updated 01-14-2012 at 06:42 PM by Java String

    String , StringBuffer
  7. Java collection Best Practices?

    by , 01-08-2012 at 11:22 AM
    Following are the best practices related to collection framework.

    • Use ArrayLists, HashMap when required to avoid thread synchronization overhead. Also you can use arrays when possible. You can achieve thread synchronization by:

    Java Code: This is an example of list and map
    Map myMap = Collections.synchronizedMap(myMap);
    List myList = Collections.synchronizedList(myList);
    • Specify the initial values for ArrayList and HashMap because these grow periodically to get space for ...

    Updated 01-15-2012 at 08:35 AM by Java Collection

  8. Java Collection Framework

    by , 01-08-2012 at 11:19 AM
    List, Map and Set are the core interfaces supported by collection framework. Collection interface is extended by List and Set. There is also a Collections class in java that is a utility class and does not confuse it.
    A Set contains only unique elements and prevents duplication. Set is implemented by HashSet and TreeSet. List is a collection of ordered elements and it may contain duplicates. List is implemented by ArrayList, LinkedList and Vector.

    Map supports key value mapping. ...
  9. Abstract class vs Interface

    by , 01-08-2012 at 11:15 AM
    Base classes are used to present interface to its child classes in design. It supports that base class cannot be instantiated. It can be only up casted and its interface is used only. To achieve this, mark the base class as abstract. Compiler gives an error, if you try to create an object of abstract class.

    The interface helps and improves the concept of abstract class. In interfaces, you can only declare methods and cannot provide implementation. The child class which is implementing ...
  10. Encapsulation

    by , 01-08-2012 at 11:14 AM
    To store all the variables and methods in an object is called encapsulation. Variables are declared private to hide them and getter methods are provided to access those variables. It is concept of hiding internal functionality. It helps in improving code modularity and re usability which supports refactoring. It is also important for integrity of application to encapsulate it internal variables and methods. Below code explains process of encapsulation in depth where different objects are kept hidden ...

    Updated 01-14-2012 at 06:39 PM by Java Basic

  11. Inheritance

    by , 01-08-2012 at 11:11 AM
    Process of including methods and variables of base class into its child class is known as Inheritance. The core benefit of Inheritance is code reusability. In case of shared code, move it to base class to refractor and improve the code. It is also a process in which characteristics of one object are transferred into another object.
    Two main forms of inheritance are as following:

    • Implementation inheritance: Functionality of the parent class is reused in the child or derived
    Tags: inheritance Add / Edit Tags
  12. Polymorphism

    by , 01-08-2012 at 11:07 AM
    It allows using objects of different types by using or calling object of only one type. This concept is called polymorphism. It will automatically call the method of desired object. It is also referred as “bottom up” method call. It helps you to add new classes of derived objects without major changes in code and breaking the code call sequence.

    Below image explains the concept of polymorphism. Send a message to a method without knowing its type. It is also known an dynamic binding ...
    Tags: polymorphism Add / Edit Tags
  13. Inheritance vs. Composition

    by , 01-08-2012 at 10:55 AM
    The concept of inheritance is based on “is a” relationship. Composition is based on “has a” relationship. Both of these two concepts allow placing sub objects into your class. Below image explains this key relationship.

    Name:  48.JPG
Views: 1135
Size:  25.3 KB

    Inheritance Vs Composition

    Inheritance is based on one direction concept. You can not apply it in reverse. Extends keyword is used to specify inheritance.

    Composition is used in cases in which ...
  14. How does the Object Oriented approach improve software development?

    by , 01-08-2012 at 10:52 AM
    There are many key benefits of the object oriented approach. Some of those benefits are:

    • Reusability: Object oriented approach support reusability of code with the help of inheritance and composition.
    • Mapping to real world problems: Object oriented approach can map real world objects with encapsulation.
    • Modular Architecture: Object oriented approach supports modular architectures where these modules can be reused.
  15. Static initialize

    by , 01-08-2012 at 10:50 AM
    All the code blocks that do not have a function name and are declared as static are executed before the constructor is called. They are usually used to initialize static fields as shown in below code.

    Java Code: This is an example of static initialize
    public class StaticInitilaizer {
    public static final int A = 5;
    public static final int B;
    //Static initializer block, which is executed only once when the class is loaded.
    static {
    if(A == 5)
    B = 10;
    B = 5;

    Updated 01-14-2012 at 06:37 PM by Java Basic

  16. Explain java class loaders

    by , 01-08-2012 at 10:47 AM
    Classes are loaded into JVM when there are referenced by already running classes in JVM. It’s a hierarchical process. First class that is loaded contains a static main method. All the remaining classes are loaded when they are referenced by main class or any other class that is running in JVM. A namespace is created by the class loaded. One class loader is embedded into JVM by default and it is called bootstrap class loader. Following figure explains the class loading process.

    Name:  45.JPG
Views: 672
Size:  29.8 KB
    Class Loader
  17. Difference between java and C++

    by , 01-08-2012 at 10:44 AM
    Java and C++ are almost similar in syntax. Following are the major differences between these:

    • Java has no support to C++ pointers.
    • Java has no support for multiple inheritances. Java has replaced multiple inheritances with multiple interface inheritance. Interface inheritance allows methods to be inherited from different interfaces. It is also referred to as polymorphism.
    • Java has replaced destructors with finalize methods. These methods are called by the garbage collector
    Java and C++
  18. Difference between java and other platforms

    by , 01-08-2012 at 10:41 AM
    Java is only software based platform. It runs on some specific hardware based operating systems like UNIX, Windows etc. Below diagram explains this process.

    Name:  44.JPG
Views: 1602
Size:  17.1 KB

    Java Compile and JVM

    The Java platform contains the following 2 components.

    • Java Virtual Machine (JVM): It can be deployed on any hardware specific platform. It generates byte codes for the java program.
    • Java Application Programming Interface
  19. JSF Disadvantages

    , 01-02-2012 at 06:58 PM
    Following are the main disadvantages of JSF framework.
    • When retrieving data from database and rendering it using JSF table component, it has performance issues.
    • Managed bean and phase listener has no strong coupling.
    • Error messages that are displayed by default are not good.
    • It is not scalable. Session object is used to store the component state.
  20. JSF Life Cycle

    , 01-02-2012 at 06:57 PM
    The JSF contains the following six phases as shown in figure as well.
    • Restore View Phase: It is used to retrieves the component tree.
    • Render Response Phase: When page is displayed first time and it has no query data, this phase is called.
    • Apply Request Values Phase: Object values are checked and applied in this phase.
    • Process Validations Phase: All the value validators are applied in this phase.
    • Update Model Phase: In this phase local values are updated ...
  21. JSF Method Binding

    , 01-02-2012 at 06:54 PM
    JSF method binding does not represent an accessor method like a value binding. An activation method is represented by this method binding. Following code shows an event handler to a method.

    Java Code: JSF action listener
    <h:commandButton ……
    ……… />

    Updated 01-14-2012 at 06:32 PM by JSF

  22. JSF Value Binding

    , 01-02-2012 at 06:52 PM
    JSF components uses JSF value binding expressions to support following:

    • Instantiate a bean and store it in request or session scope.
    • Java bean value is overridden
    • Map, List and array contents are retrieved quickly.
    • In a number of requests, content is synchronized.
  23. JSF Managed Bean

    , 01-02-2012 at 06:51 PM
    JSF managed beans are defined in configuration file and these are java beans to hold data from JSF components. They represent data model and are passed between JSF business logic and JSF pages.

    Following are the main features of managed beans.
    • They use declarative model
    • They provide an entry point
    • Beans with various states

    Following code shows a managed bean which has a session scope. Instance of this managed bean is created at the start ...

    Updated 01-14-2012 at 06:30 PM by JSF

    Managed Bean
  24. JSF Validators

    , 01-02-2012 at 06:49 PM
    JSF validators are used to support input validation and save lot of time of programmers in writing custom validation methods. JSF contains a large set of validator classes. Following are the some of built-in validators.

    • DoubleRangeValidator: Any numeric type, between specified maximum and minimum values
    • LongRangeValidator: Any numeric type convertible to long, between specified maximum and minimum values
    • LengthValidator: Ensures that the length of a component's ...
  25. JSF Events Handling

    , 01-02-2012 at 06:48 PM
    JSF components trigger events and these events are process by the JSF application. User generates these events by interacting with the application. For example, Click a button event is generated and triggered by the user. Programmer is responsible to handle all such events in code. You can write event listeners for this purpose.

    Following JSF code is written to create a button.

    Java Code: This is example of a JSF Button
    <h:commandButton value="Login“

    Updated 01-14-2012 at 06:28 PM by JSF

  26. JSF vs Struts Framework

    , 01-02-2012 at 06:45 PM
    Folowing points explain the key differences between these 2 frameworks.

    • Struts framework is matured and evolved over the years.
    • JSF is immature as compare to Struts.
    • Struts is based on a controller which uses Front Controller design pattern. Also it has only one event handler for a HTTP request.
    • JSF is based on Page Controller design pattern and front controller Servlet handles all requests.
    • Struts does not support RAD.
    • Struts supports ...
    Tags: jsf, struts Add / Edit Tags
    Tutorial , Frameworks
  27. JSF Framework

    , 01-02-2012 at 06:44 PM
    Recently, Java Server Faces has gained lot of popularity for building web applications in java. Following are the core features of java server faces.

    • It supports rapid application development with help of its core components like buttons, text fields, tree, tables etc. Programmer can build their applications using these components.
    • It has a support for JSP tags to access its interface components as explained in above step. Also it supports custom components.
    • It ...
  28. Why to use the RMI when same benefits can be achieved from EJB?

    , 01-02-2012 at 06:41 PM
    EJB makes use of the RMI framework to do the object distribution. EJB application server provides extra services for example object pooling, transaction, database connection pooling etc which is not provided by RMI. Programming efforts are simplified by these services that have been given by EJB server, at performance cost in comparison with plain RMI. Therefore, if performance is more important then go for pure MRI as a better solution.
    Tags: rmi benefits Add / Edit Tags
  29. What is HTTP tunneling? How to make RMI calls, across firewalls?

    , 01-02-2012 at 06:40 PM
    Direct sockets are opened into server by RMI transport layer. Firewalls are present in many intranets which doesn’t permit this. To make through some firewall, within firewall trusted HTTP protocol embed the RMI call. RMI uses HTTP tunneling and this is done by the encapsulation of RMI calls present in HTTP POST request.

    Name:  38.JPG
Views: 1984
Size:  19.3 KB

    HTTP Tunneling

    • When HTTP requests may be forwarded by firewall proxy server just to some known HTTP port: ...
  30. Passing parameters in RMI

    , 01-02-2012 at 06:36 PM
    • By value, primitive types get passed. For example, Boolean, char, int etc.
    • Being remote references, remote object references get passed which permits the client process to make the methods invoked.
    • By object serialization, non remote objects get passed by value. Implementation of the interface shall take place which shall allow objects to get serialized.

    Remote method’s invocation gets initiated by the client process, using calling method present ...
Page 27 of 48 FirstFirst ... 17252627282937 ... LastLast