View RSS Feed

Core Java

Core Java tutorials.

  1. Types of Garbage Collector in Java

    by , 03-02-2012 at 05:31 PM
    Java Runtime provides various Garbage collection types in Java. One may choose them according to the requirements of performance of your application. In Java 5, three garbage collectors are added except “serial” garbage collector. Each garbage collector is implemented to raise the throughput of application or to reduce the garbage collection’s pause time.

    1) Throughput Garbage Collector:
    Garbage collector used parallel version of the Young generation collector. JVM, -XX:+UseParallelGC ...
  2. Garbage Collection Disadvantages

    by , 03-02-2012 at 05:30 PM
    Garbage collection has certain disadvantages which are as following:

    • Garbage collection uses computing resources so that to take a decision that which memory shall be reconstruct or free the fact to which programmer is well-aware of. When object lifetime is not manually annotated in source code, penalty is overhead. It will reduce the performance. Overheads are not bearable or tolerable, when interaction is present to memory hierarchy effects. It is not easy to predict them during
  3. Garbage Collection Overview

    by , 03-02-2012 at 05:28 PM
    Garbage collection is automatic memory management in computer sciences. Garbage collector attempts to reclaim garbage or occupied memory of the object that is not in use of program. In 1959, Garbage collection was invented by John McCarthy to solve the Lisp problems.

    Usually garbage collection and manual memory management are considered opposite of each other. Objects are required by programmers which are returned or deallocated to the memory. Various approaches are taken into consideration ...
  4. Object Reference Type Casting

    by , 03-02-2012 at 05:27 PM
    In Java object typecasting, type cast of 1 object reference is possible to another object reference. Suck type of casting is done with superclass, subclass or class types. Compile time rules or runtime rules are present in Java for casting.

    Class relationship is the basic thing at which Object reference is dependent. Any object reference could be assigned to reference variable of type object because the object class is usually the superclass, for each Java class.

    Two ...
    Tags: type casting Add / Edit Tags
  5. Final Fields and Methods

    by , 03-02-2012 at 05:20 PM
    Fields and methods might be declared final. For final method possibilities are not there to be overridden, in subclasses. Final field is considered to be constant: Possibility of assigning once again is not present when a value is been provided already. For example, Constructor function of the List class does the item field initialization to size ten array. For array’s initial size, usage of constant is recommendable. For whole class only 1 constant copy is needed. Hence field static as well as ...
    Tags: final fields Add / Edit Tags
  6. Static Fields and Methods

    by , 03-02-2012 at 05:16 PM
    Methods and fields might be declared static. This is also possible for C++. Only one copy is present for the complete class when field is static, rather than one copy for all class instances. If class instance is not present even then field’s copy is available. For example, given field addition in List class:

    static int numLists = 0;

    And, the given statement addition in the List constructor:


    When new List object creation takes ...
  7. Fields, Methods, and Access Levels

    by , 03-02-2012 at 05:13 PM
    • Java classes consist of methods and fields. A field is same as a C++ data member & a method is similar to a C++ member function.
    • Each method & field possess an access level:

    o private: access is possible in this class only
    o (package): access is possible in this package only
    o protected: access is possible in this package only & also in all subclasses.
    o public: access is possible anywhere this class is present.
    • Every class consist of these
  8. Java Classes

    by , 03-02-2012 at 05:10 PM
    Various individual objects might be found of same kind, in real work. Thousands of similar bicycles might be present in world that have similar model or make. Same components or same blueprints set are used to build bicycles.

    Bicycle may be considered as class bicycle instance, in case of the object oriented programming. Class is basically the blue print which is involved in creation of the individual objects.

    This given Bicycle class is the possible bicycle implementation: ...
    Tags: java classes Add / Edit Tags
  9. Java garbage collector

    by , 01-08-2012 at 12:53 PM
    A new object is stored into heap when it is created by the Java Program. Heap is also call garbage collectable heap and it can be released by the garbage collector. Garbage collector is a JVM low priority thread and its execution cannot be forced. It is executed to release memory allocated to unused object. Also you can ask garbage collector to release memory by using System.gc()

    Object is unreachable when it has no other object that is referencing to this object. In such cases this ...
  10. Type casting

    by , 01-08-2012 at 12:50 PM
    When you treat a variable of one type to another type, it is called type casting. Up casting supports automatic conversion but in case of low casting you need to explicitly specify it.

    Java Code: Type Casting
    byte -> short -> int -> long -> float -> double
    int i = 5;
    long j = i; //Right. Up casting or implicit casting
    byte b1 = i; //Wrong. Compile time error “Type Mismatch”.
    byte b2 = (byte) i ; //Right. Down casting or explicit casting is required.

    Updated 01-14-2012 at 07:46 PM by Core Java

  11. Outer and Inner classes

    by , 01-08-2012 at 12:47 PM
    All the classes in Java are not defined separately from other classes. You can also write one class into another class. The inside class is referred as inner class and the class containing this inner class is called outer class. Inner class is a member of outer class similar to other attributes and methods.

    Avoid using inner classes when they are not required. It is hard to maintain and reuse code with inner classes. Only use it when it is required and relevant. They are used usually ...
  12. 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 ...
  13. Using Imports to Change Behaviour

    by , 11-29-2011 at 04:24 AM
    One thing that would be great to have is a feature that I know well from my previous experience coding in C. That is the possibility to conditional compile in order to modify the behaviour of the application. A feature that is missing from Java is C’s conditional compilation, which allows you to change a switch and get different behaviour without changing any other code. I think is was left out of Java is that I remember using this feature often to address issues related to compiling a program ...
  14. Managing Initialization and Class Loading

    by , 11-29-2011 at 04:20 AM
    Java avoids many of the problems found with other languages related to the startup and initialization of objects in the right order, by taking a different approach to loading. The key to this is that everything in Java is an object. Each class exists in its own separate file. Therefore files are not loaded until the code is needed. The expression of this is that “class code is loaded at the point of first use.” This is usually when the first object of that class is constructed, but loading also ...