Posts

Showing posts with the label Java

Java - Class, Object, String

Understanding Class, Object:   Concept - Consider the following analogy: A  class  is a blueprint to make  object s. For example, suppose you have a class House. The class House is the blueprint that explains exactly how to make a specific House object. Your own house, or your sister's house, are instances of class House - they are the concrete House objects that are made using the blueprint. So, a class is like a recipe, or a set of instructions, or a plan, that explains how to make a specific kind of object.   or you can think of a class as a 'Reference' for making the 'real' objects! Every time you look at the reference/guide before you create an object in existence as it serves you the basic information of 1. What actually constitutes an object? Other way, what will the object be having with it? If it is a House object, it would be having doors, windows etc., If it is a Person object, it would be having eyes,ears, nose etc., -- They are called as  ...

Quick Refresh : Java 1.5 : Generics

  Why Use Generics? In a nutshell, generics enable  types  (classes and interfaces) to be parameters when defining classes, interfaces and methods. Much like the more familiar  formal parameters used in method declarations, type parameters provide a way for you to re-use the same code with different inputs. The difference is that the inputs to formal parameters are values, while the inputs to type parameters are types. It was introduced in java 1.5. Benefits of Code that uses generics over non-generic code: Type-safety:  We can hold only a single type of objects in generics. It doesn't allow to store other objects. Without Generics, we can store any type of objects. List list =  new  ArrayList();     list.add( 10 );   list.add( "10" );   With Generics, it is required  to specify the type of object  we need to store.   List...