Category Archives: Java

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.
Continue reading

Advertisements

Local and Anonymous 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:

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

Continue reading

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

Continue reading

Book Review: Head First Java

Book: Head First Java (Website)Head First Java

Authors: Kathy Sierra, Bert Bates

There are many people around aspiring to learn Java- One of the most powerful OO Languages. But Alas!!!! how to go about the learning process??? Which book is suited for my style of learning??? All these questions pop in one’s mind. Even they were my questions once upon a time. But thanks to my tutor friend who introduced me to Head First Java. Head First Java is one of the books in Head First Series.

The book has everything in it. It is a must read book for any beginner in Java programming. But the reader must have certain programming background i.e the reader must be familiar with either C or the Object Oriented concepts pf C++. The author runs through the initial few chapters which will be sort of revision for programmers with C++ background. The Java concepts are explained in the best possible way. They are explained in such a way that reader will be in a position to explain the same to others. There are nice exercises at the end of each chapter and some brain ticking questions in the chapter. The author has used visual aids in explaining the concepts. The book is more unorthodox in its presentation with more amount of images than text. Initially the reader my find that the book is not serious regarding the concepts but this book is best for starters. It has just what is required for beginners to know. Its not just theory, the author has also given code examples and has also during the course of the book designed one complete software package and also designed some small applications which i feel will help the reader in long way. The exercises are not mere answer the following questions but they include Crossword puzzles – aimed at puzzlers, match the following, find the errors, find the output, fill in the blanks and some mystery related questions.

I think no matter how much i write here but i don’t think one can actually feel the book’s benefits until one reads the book. Its a must for all Java beginners and must for the shelf of Java Programmer.

Know more about Head First Formula here

Interface Vs Abstract Class

There are three differences between an interface and an abstract class:

  • you can implement multiple interfaces at the same time, but only extend one class,
  • an abstract class is allowed to contain implementation (non-abstract methods, constructors, instance initializers and instance variables) and non-public members, and
  • abstract classes may be a tiny bit faster (or they may not.)

Actually the first point is the reason for the existence of interfaces in Java: to provide a form of multiple inheritance. In languages with multiple implementation inheritance, an interface would be equivalent to a fully abstract class (a class with only public abstract members).

The above differentiation suggests when to use an abstract class and when to use an interface:

  • use an abstract class, if you want to provide common implementation to subclasses,
  • use an abstract class, if you want to declare non-public members,
  • use an abstract class, if you want to be free to add new public methods in the future,
  • use an interface if you’re sure the API is stable for the long run
  • use an interface if you want to provide the implementing classes the opportunity to inherit from other sources at the same time.

In general, prefer interfaces if you don’t need to use an abstract class, because they provide more design flexibility.

Resources:
MindProd

Source: JavaRanch

Call By Reference and Call By Value

Java always makes a copy of the argument and passes the copy. The called method has a local copy of the data. If the method changes the data it changes the copy, so the original value is not changed. When we pass a primitive like int this make perfect sense. The method gets its own int variable, a copy of the original.

When we pass an object we have to think very precisely. The value that is copied and sent along is a reference or pointer to the object. The method gets its own copy of the pointer, but it doesn’t get its own copy of the object. If the method changes its copy of the pointer to point to a different object the original pointer is not affected. If the method changes some of the attributes of the object, it changes the original object.

In short in java, object references are passed by reference and primitive types are passed by value.

Source: JavaRanch