Keep it Rolling – Java

Moving towards Java generation

  • Top Clicks

    • None

Java: Looking back at basics

Posted by rolloutjava on January 26, 2008

I am in a process to learn the java programming ‘again’. Looking back at the basics always helps and this is what I will do in this post. It will help me to strengthen my own knowledge and may be to any reader. Pls do post any important tips if you have. :) I will be very thankful to you. I wont state the definitions and all here.. simply some points (which I did not practice for long time) that I am reminding myself.

Inside Inheritance: A subclass inherits all the members from its superclass. Members here are field, methods, and nested classes. Constructors are not members, so they are not inherited by subclasses, however a subclass can invoke the constructor of its superclass.

  • A subclass inherits all the public and protected members of its parent, independent of the package the subclass is in.
  • Sublcass inherits package-private members of the parent, if the superclass lies in the same package as the subclass.
  • a new instance method in the subclass can be created that has the same signature as the one in the superclass (overriding).
  • a new static method in the subclass can be created same as the one in superclass (hiding).
  • An overriding method can also return a subtype of the type returned by the overridden method. This is called a covariant return type.
  • Overridden and hidden method: Version of the hidden method invoked depend from where it is invoked (superclass or subclass).
  • A protected instance method in the superclass can be made public, but not private in the subclass.
  • If a subclass constructor invokes a constructor of its superclass, either explicitly or implicitly, there will be whole chain of constructors called, all the way back to the constructor of ‘Object’(constructor chaining).
  • Methods called from constructors should generally be declared final.

Abstract classes:

  • cannot be instantiated but can be subclassed.
  • abstract method is declared without implementation.
  • subclass of abstract class provides implementations for all of the abstract methods in its parent class. Else, the subclass must be declared abstract.

Abstract classes and interfaces:

  • abstract classes can contain fields that are not static and final, and they can contain implemented methods.
  • Abstract classes are most commonly subclassed by similar classes that have a lot in common (the implemented parts of the abstract class), but also have some differences (the abstract methods).
  • Abstract class that implements an interface does not need to implement all of the methods of that interface.

Generics:

  • Bounded Type Parameters: Useful when we want to restrict the kinds of typed that are allowed to be passed to a type parameter. To declare a bounded type parameter, list the type parameter’s name, followed by the ‘extends’ keyword, followed by its upper bound.
  • Wildcard: an unknown type in generics is represented by the wildcard character “?”.

Ok!… I have just finished reading this from the Sun java tutorial trail.. and there are a lot of things unclear… I will keep updating this section when I clear my doubts.

Posted in java | Tagged: | Leave a Comment »

Java: Do you practice this?

Posted by rolloutjava on January 20, 2008

Initializing instance variables: There are two alternatives to using a constructor to initialize instance variables: initializer blocks and final methods.

Initializer blocks: Initializer blocks for instance variables look just like static initializer blocks, but without the static keyword: { //code here }. the compiler will copy the block into every constructor.

final method: This method cannot be overridden in a subclass. This is useful if subclasses might want to reuse the initialization method.

Enum Type:

  • An enum type is a type whose fields consist of a fixed set of constants.
  • The names of an enum type’s fields are in uppercase letters.
  • The enum class body can include methods and other fields.
  • They have static ‘values’ method that returns an array containing all of the values of the enum in the order they are selected.
  • An enum cannot extend anything as it is implicitly extending java.lang.Enum.

Annotations: Annotations provide data about a program that is not part of the program itself. They do not have any direct effect on the operation of the code they annotate.

  • Used by compiler to detect errors or suppress warnings.
  • Software tools can process annotation information to generate code, XML files, and so forth.
  • Annotation appear first and may include elements with names or unnamed values.
  • To make the information annotation class appear in javadoc-generated documentation, it must be annotated with the @Documented annotation.
  • To make annotation information available at runtime, the annotation type itself must be annotated with @Retention(RetentionPolicy.RUNTIME)
  • Annotations used by the compiler:
    • @Deprecated: this annotation indicates that the marked element is deprecated and should no longer be used. When an element is deprecated, it should be documented using the javadoc @deprecated tag.
    • @Override: Informs the compiler that the element is menat to override an element declared in a superclass
    • @SuppressWarnings: tells the compiler to suppress specific warnings that it would otherwise generate.

Posted in Uncategorized | Leave a Comment »

Java: Controlling access to members of a class

Posted by rolloutjava on January 15, 2008

‘public’: Class is visible to all classes everywhere. If a class has no modifier, it is visible only within its own package.

Member-level access modifiers: For members of a class there are two more modifiers, private and protected. ‘private’ specifies that the member can only be accessed in its own class. ‘protected’ specifies that the member can only be accessed within its own package and by a subclass of its class in another package.

Posted in java | Leave a Comment »

Object Oriented Principles: OOPS

Posted by rolloutjava on January 11, 2008

Data Encapsulation: Software objects store their state in fields (variables) and expose their behavior through methods(functions). Hiding internal state and requiring all interaction to be performed through an object’s method is known as data encapsulation.

Class: A class is a blueprint from which individual objects are created.

Inheritance: Different kinds of objects often have a certain amount in common iwht each other. Yet each also define additional eatures that make them diferent. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.

Interface: Methods form the object’s interface with the outside world. An interface is a group of related methods with empty bodies.

Posted in OOPS | Leave a Comment »

Hello world!

Posted by rolloutjava on October 31, 2007

Well! first post eh? Satisfied, happy, and joyful. At least, I have something of my own where ppl can read what I want to say (of course, if they want to, oh please…. you have to read it dear :( ). I found the Hello World! title fine, so I will continue with the same.

No, don’t think that I am writing this page just for fun or that I want to see my blog stats just growing. I dont see that happening with MY blog… I am just interested in what I learn in Java programming community and that someone somewhere might find it useful enough to use it in their work.

I am just a beginner and then after that I will still call myself a beginner and at the end – beginner.

have fun and enjoy reading and keep learning and share the knowledge as ‘Good knowledge is light’.

Posted in Uncategorized | 1 Comment »

 
Follow

Get every new post delivered to your Inbox.