Showing posts with label Concepts. Show all posts
Showing posts with label Concepts. Show all posts

Interface Illustrated

  • 0
     Via interfaces, one can specify what a class must do, but not how it should do it. An interface is just like a class and is defined in almost same way.

     access interface_name
     {
          return_type method_name1(parameter_list);
          return_type method_name2(parameter_list);

          type final_var_name = value;
     }
    When no access specifier is given, access is understood to be default. Default access restricts the use of interface to the current package only.

Access Mechanism in Packages Demystified

  • 0
     Packages in java are both, a naming and a visibility control mechanism,. In this article, I will try to show the behaviour of access modifiers in different situations. We have 4 type of access in Java, they are public, private, protected and default. Out of these, only public and default can be used with classes. When no access modifier is explicitly written before a member, is is supposed to be in default access.

Abstract Class Illustrated

     An abstract class is the one having an abstract method in its definition. Abstract class puts a restriction that subclass must implement its own version of abstract methods. Programmer does not has the freedom to create object of an Abstract class. One can not declare abstract constructors or abstract static methods. One can not instantiate an Abstract class object with new operator. However, Java provides us the freedom to create an reference of Abstract class type. This reference can be used to store the reference of subclass object references.

Constructor Chaining in Java

  • 0
     In the professional language, A constructor is a subroutine which is called at the time of creation of object of a class. Well, Constructor is a very special method that does not has a return type, not even void. The job of this special method is to initialise the object with default values. If you don't create it explicitly, Java does it for you. This special method is called as soon as an instance of the class.

Methods with Variable Number of Arguments

     In my last article, I discussed how before the introduction of VarArgs, programmers had to deal with the requirement of methods. Here, I am going to discuss the VarArgs Methods, that allow you to deal with the requirement of variable number of arguments in a method. A variable length argument is specified by three periods. For example
static void VarMethod(int...v)

Super Keyword in Java

Super keyword is one of the most confusing an exciting features of Java. In this article, I will try to demonstrate the two uses of super keyword. The two uses of super keyword are
  1. to call the constructor of immediate Superclass of subclass. Subclass is the one who has has inherited, and Superclass is the one who has been inherited.
  2. to call and access hidden members of Superclass.

Old School Variable Argument Method

     Before introduction of Varargs(which is going to be our next topic of discussion in Java Journal), two appraoches were used to create methods with variable number of arguments. They are
First approach invloved the use of overloaded method. The method simply involved creating all poosible set of input arguments and define a separate method with same name. This approach gaurantees to push you onto edge.
Second approach was to use a single method with on;y one argument array of the required type. We will discuss this method in here. However, the problems associated with this approach was that each time, preparing for a call to a method, an array was supposed to be created. This method can be extremely complex and errorprone if number of calls are large.

Nested Class Concept

  • 0
      Java language allows nesting of classes. When one class in defined in another class, then, enclosed class is called nested class. A nested class can access the methods and variables of the enclosing class, even private members, like they all are members of its own.

Static Block Demystified

  • 0
     Static keyword in Java has unusual properties. A variable flagged as static acts like a global variable, a class maintains a single copy of the static variables in the memory which is shared by all the class instances or objects of that class. A method tagged as static can be called without the creation of class object at first. Being a static method also puts some restrictions on the method, for example, it can only access static variables, can call only static methods and can not refer to "this" or "super" keyword in any way. In this article, I will try to clear some concepts regarding Static Block.

Java Program to swap values of two numbers without temporary variable

A typical value swapping progran involves use of a temporay storage to store the value of either of the two variables whose values is to be swapped. In here, I would try to make you understand the true logic of the oprogrm. This program is simply based on the fact that java assignment statement, for example,
a = 1 +3;
would add first 1 and 3, after the addition, the value is stored in the left hand value of the storage variable. Now, the program swapping vales is.

How to return Objects from Methods

  • 0
      Java enables us to return objects from the methods as well. Returning and passing objects need to consider the  parent child relationship among the classes. This relationship holds importance because, as a matter of fact, Object of parent class can hold the address of object of child class.

Fibonacci series program in Java

  • 0
Fibonacci series is one the most series es in the world. In a Fibonacci series, each term is the sum of last two terms. For the first two terms, 1st is taken as 0 and second is taken as 1. Fibonacci series has attracted a lot of attention and research. So. let us devote a JAVA program to print the Fibonacci series.

How to use Objects as Parameter

     The first thing that anyone needs to know is the difference between argument and parameters. Arguments are the variables that are passed to the functions and parameters are the variables that receive the value of the arguments. Java rich Object Oriented Features allow us to use Objects as the parameter.

Method Overloading Demystified

  • 0
Method Overloading is one of the best features of the Object Oriented Language. With Method Overloading, Java implements Polymorphism.

Garbage Collector Program in JAVA

  • 0
Java language dynamically allocates the memory to the objects of the classes being used in the program. Unlike C++ where a destructor is needed to free the memory, JAVA employs Garbage Collector Mechanism to reclaim the allocated memory. When no referance to the object exists in the memory, it becomes eligible to be collected by Garbage Collector. The finalize method provided by java sees to it that this method is executed just before the memory allocated to the object is being reclaimed. There is no gurantee that a finalize method would be executed. My aim was to observe the functioning of the garbage collector. So, I created a program. And here it is.