Static Members: Static Methods and Static Variables

Why do we need Static members?

There are situations in which the method’s behaviour does not depend on the state of an object. So, there will be no use of having an object when the method itself will not be instance specific.

Let us consider another situation where in we want to keep a count of all the instances instantiated from a particular class. Suppose we declare an instance variable to do the job, it won’t work. Its because the instance variables are initialised back to their default value each time a instance is created. So we need some varaible which will be independent of the instances created.

The answer to both the situations is to use the “static” modifiers, in other words static members.

Read more

Java SE Update 10 Beta Available

Java SE 6 Update 10 Beta is an update release that introduces new features and enhancements aimed at providing an optimized consumer-end user experience. It is available for download as part of Java SE Early Access Downloads. Java SE 6 update 10 focuses on the following areas: Enhanced JRE Installation experience Improved performance and look … Read more

Casting Reference Variables- Downcasting, Upcasting

Let us consider two classes class Animal, a more generic class and class Cat, a more specific class i.e a more specific animal. Let us settle for simple definitions for both the classes so as to get the concept right.

/*
The definition for more generic class Animal
Notice the eat() method, which will be inherited by all Classes extending Animal
*/

class Animal
{

public void eat()
{

System.out.println(“AnimalĀ  Eating“);

}

}

Read more

Top Ten Errors Java Programmers Make

I read an article on ā€œTop Ten Errors Java Programmers Makeā€œ. The author has mentioned the errors which even the most programmers often commit or the New to Java programmers may commit in the future. Not only has he listed the errors but also given the possible solution for the same. I found the article … Read more

Things one has to know about Interfaces in Java

The following article is mainly focused at beginners who are not much familiar to Java. It can also be a quick recap tool for Java Developers.

What are Interfaces?

Interfaces are 100 percent abstract classes i.e it defines only abstract methods and constants. But while an abstract class can define both abstract and non-abstract methods, an interface can have only abstract methods. Interfaces can be implemented by any class from any inheritance tree.

Why do we need Interfaces?

Interfaces help in implementing “Multiple Inheritance” the Java Way. Now what exactly does it mean by “Multiple Inheritance”? The Multiple Inheritance, one in C++, is allowing a particular class to extend/inherit from more than one class. Multiple Inheirtance can be quite messy and lead to deadly situation at times.

Read more

Top Ten Errors Java Programmers Make

I read an article (linked below) on “Top Ten Errors Java Programmers Make“. The author has mentioned the errors which even the most experienced programmers often commit or the New to Java programmers may commit in the future. Not only has he listed the errors but also given the possible solution for the same. I found the article really informative šŸ˜‰

Read more

javaBLACKbelt- building better developers

About JavaBlackBelt (WebSite)
JavaBlackBelt
JavaBlackBelt is a community for Java & open source skills assessment. It is dedicated to technical quizzes about Java related technologies. This is the place where Java developers have their technology knowledge and development abilities recognized. Everybody is welcome to take existing and build new exams.

Read more

Inner Classes

Inner Classes are the classes which are declared inside an outer class i.e classes nesting with in outer class. They can be either static or non static. Static Inner classes are also called as Nested Classes. Inner classes come in Four flavors namely:
Inner Classes

1. Static Member Classes
2. Member Classes
3. Local Classes
4. Anonymous classes

Read more

%d bloggers like this: