Java Varargs


In this article, we will discuss about passing variable number of arguments to Java methods. Variable arguments feature was introduced in Java 1.5 and it is a very useful feature as we will see in the below examples. Also Read: Java 5 New Features Java 7 Tutorials Java 8 Tutorials Prior to Java 1.5 Lets […]

A Simple Factory For Collections Using Varargs


Suppose you want to create a list object in Java and populate it with some default elements, how would you go about coding it? One will pursue one of the following approaches: (If you have any other approach feel free to share them via the comments and we will update the post accordingly). In the […]

Introduction to Java Agents


In this article we will discuss about Java Agents. Java Agents are software components that provide instrumentation capabilities to an application. In the context of agents, instrumentation provides the capability of re-defining the content of class that is loaded at run-time. We will discuss this in more detail in the further sections. Download Source Code: […]

Java 5.0


Java 5.0 Java Platform, Standard Edition (also known as Java 2 Platform) lets you develop and deploy Java applications on desktops and servers, as well as today’s demanding Embedded and Real-Time environments. Java SE includes classes that support the development of Java Web Services and provides the foundation for Java Platform, Enterprise Edition (Java EE). […]

How to use Enum in Switch?


Enums introduced in Java 5.0 (Read: New features in Java 5.0) allows switching to be done based on the enums values. It is one of the greatest new features introduced from the version 5.0. Prior to Java 1.4, switch only worked with int, short, char, and byte values. However, since enums have a finite set of […]

Adding methods to an Enum


Enums introduced in Java 5.0 are just compiled java classes with some extra behavior. So you can basically do whatever you can in a normal java class inside an enum as well. That includes adding methods , class level variables and constructors to an enum. Adding methods to an enum works just like adding methods […]

Mixing Generics And Non-Generics Code


If we are work on code that uses generics that is fine and what will happen if we want to mix both generic and non generic code. Consider below Animal class also read: New Features in Java 5.0 Generics in Java 5.0 Annotations in Java 5.0 if we create the list like below will it […]

How to use ? extends in Generics?


In generics as we know we can not assign subclass generic type to super class generic type, for example will not compile even though Dog IS-AN Animal. the reason for this is already explained in generics basics section. How can we solve this particular problem????? we can solve this problem by using wildcard in generics, […]

Using ? super in generics – Java 5.0


As we know we can not add any value except null to collection if we use ? extends syntax. What if we want to add value to the collection, then we have to use ? super syntax. The code looks like this. also read: New Features in Java 5.0 Generics in Java 5.0< Annotations in […]

Generic Methods in Java 5.0


In java 1.5 we have a feature called generic methods, with this we can write a method, which can be generic, means it can be called by any parameter and behavior of the method will be according to the parameter passed. Assume that we need to write a method which takes an array and converts […]