View RSS Feed

All Blog Entries

  1. Java stack and heap memory

    by , 01-08-2012 at 12:43 PM
    Heap is used to store new objects created by Java. Stack is used to store primitive data types like int and double when they are declared locally. These primitive data types are stored on heap when they are declared globally. Whenever a Java method is called, all the local variables are pushed to stack and its pointer is decremented after completion of that method call. In a multithreaded application only one heap is used and each thread contains its own stack. So do not declare your data globally ...
    Categories
    Stack
  2. Java I/O performance

    by , 01-08-2012 at 12:40 PM
    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.
    ...
    Categories
    Performance
  3. Final, finally and finalize

    by , 01-08-2012 at 12:38 PM
    • 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 ...
    Categories
    Access Modifier
  4. Shallow cloning Vs Deep cloning

    by , 01-08-2012 at 12:36 PM
    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 ...
  5. Serialization

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

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

    Serialization


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

    by , 01-08-2012 at 12:31 PM
    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. ...
  7. String vs. StringBuffer

    by , 01-08-2012 at 12:26 PM
    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
    //More
    ...

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

    Categories
    String , StringBuffer
  8. Java collection Best Practices?

    by , 01-08-2012 at 12:22 PM
    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 09:35 AM by Java Collection

    Categories
    Tutorial
  9. Java Collection Framework

    by , 01-08-2012 at 12:19 PM
    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. ...
    Categories
    Tutorial
  10. Abstract class vs Interface

    by , 01-08-2012 at 12:15 PM
    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 ...
    Categories
    Interface
  11. Encapsulation

    by , 01-08-2012 at 12:14 PM
    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 07:39 PM by Java Basic

    Categories
    Tutorial
  12. Inheritance

    by , 01-08-2012 at 12:11 PM
    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
    Categories
    Inheritence
  13. Polymorphism

    by , 01-08-2012 at 12:07 PM
    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
    Categories
    Tutorial
  14. Inheritance vs. Composition

    by , 01-08-2012 at 11: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: 1339
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 ...
    Categories
    Inheritence
  15. How does the Object Oriented approach improve software development?

    by , 01-08-2012 at 11: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.
    Categories
    Tutorial
  16. Static initialize

    by , 01-08-2012 at 11: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;
    else
    B = 5;
    ...

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

    Categories
    Tutorial
  17. Explain java class loaders

    by , 01-08-2012 at 11: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: 720
Size:  29.8 KB
    ...
    Categories
    Class Loader
  18. Difference between java and C++

    by , 01-08-2012 at 11: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
    ...
    Categories
    Java and C++
  19. Difference between java and other platforms

    by , 01-08-2012 at 11: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: 1749
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
    Categories
    Tutorial
  20. JSF Disadvantages

    by
    JSF
    , 01-02-2012 at 07: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.
    Categories
    Tutorial
  21. JSF Life Cycle

    by
    JSF
    , 01-02-2012 at 07: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 ...
    Categories
    Tutorial
  22. JSF Method Binding

    by
    JSF
    , 01-02-2012 at 07: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 ……
    actionListener=“#{customer.loginActionListener}”
    ……… />

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

    Categories
    Binding
  23. JSF Value Binding

    by
    JSF
    , 01-02-2012 at 07: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.
    Categories
    Binding
  24. JSF Managed Bean

    by
    JSF
    , 01-02-2012 at 07: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 07:30 PM by JSF

    Categories
    Managed Bean
  25. JSF Validators

    by
    JSF
    , 01-02-2012 at 07: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 ...
    Categories
    Validator
  26. JSF Events Handling

    by
    JSF
    , 01-02-2012 at 07: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“
    actionListener=“#{customer.loginActionListener}”
    ...

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

    Categories
    Event
  27. JSF vs Struts Framework

    by
    JSF
    , 01-02-2012 at 07: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
    Categories
    Tutorial , Frameworks
  28. JSF Framework

    by
    JSF
    , 01-02-2012 at 07: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 ...
    Categories
    Tutorial
  29. Why to use the RMI when same benefits can be achieved from EJB?

    by
    RMI
    , 01-02-2012 at 07: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
    Categories
    Tutorial
  30. What is HTTP tunneling? How to make RMI calls, across firewalls?

    by
    RMI
    , 01-02-2012 at 07: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: 2267
Size:  19.3 KB

    HTTP Tunneling

    • When HTTP requests may be forwarded by firewall proxy server just to some known HTTP port: ...
    Categories
    Tutorial
Page 27 of 48 FirstFirst ... 17252627282937 ... LastLast