Articles tagged with: Java 5
Java »
Many applications require to check if the file being accessed is really a file or a directory. Also if it is a directory then you would need to traverse through the contents of directory. Here is the code snippet that shows how to do it. In addition to this you may have to handle exceptions. Also ensure the file is closed at the end of everything in finally block.
Java, Tech Notes »
Annotation is not a new feature getting introduced in Java 5, but in this release Java is trying to explore the power of this feature. If we look at the open source product stack adapting to Java 5, then this is the feature what has changed most of the products considerably. It has begun a new era of decorative programming. In this article, it is assumed that you already have knowledge of Java, and can appreciate this article focusing on the concept of annotations, use of annotations etc.
Annotations Prior to …
Java, Tech Notes »
Static keyword is used to allow access to an attribute/ a method or a class without creating instance of it. (Some of you may argue that this is not object oriented way, but we leave that discussion aside for now.) We use static for those elements which do not change from instance to instance of a class. An example would be constant variables in a program. These values are stored using ‘public static final’ keywords. In enum article we have seen one way of managing logically linked constants. Static import …
Java, Tech Notes »
Varargs means variable arguments, something really different from normal Java language syntax. Normally, we define method signature to offer a contract to the callers of that method by restricting number and type of input parameters, return data type and exceptions thrown. Using vararg feature, we can overcome this restriction partially and make the signature dynamic. You may say that the dynamic signature is not new. Following two options you used many times to avoid an impact on clients due to additional/reduced parameters in signatures.
Using array/collection as an input parameter
…
Java, Tech Notes »
Enumerations already existed in other languages like C, C++, SmallTalk etc. Enums are used primarily to handle a collection of logically grouped constants. In Java, for ages we have been handling constants (number constants here) through separate Java files, sometimes by encapsulating those in relevant POJOs, and even using a wrong design style of implementing an interface containing all constants. We used these constants in conditions implemented using ‘if’ statement or switch cases also. First thing you can notice about all these approaches is that this made the code look …
