Posts

Showing posts with the label java

Java 1.7 new Language Features and Enhancements

After long time I came back to my blog page and decided to continue filling the space in my blog. In this blog I'm going to write about the new bunch of features coming with all new JAVA 1.7 or JDK 1.7. Once I gone through those features I really realize some of those enhancements are the things that we are waiting until Sun include those features for us. The following enhancements have been added to the Java language: Binary Literals Underscores in Numeric Literals Strings in switch Statements Type Inference for Generic Instance Creation Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods The try-with-resources Statement Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking Binary Literals     In Java SE 1.7 it includes the binary number system with the integral types (byte, short, int, long). To specify  number as a binary value it has to add 0b or ...

Spring Util Map Annotation with Enum key

I wanted create java.util.Map in spring context xml file which injects the Map to one of my service class, but i was struggling with this because my Map's key is an enum value , Finally I was able fix that issue as following, in Spring we can specify the key-type and value-type specifically with generics values. That part was the interesting and new part i found time. All it goes as follows. <map      key-type="EnumType">         <entry key="ENUM_VALUE"  value-ref="leastLoadedAssignmentMechanism" /> </map>

Watermarking Images in a Java Servlet

Image
In our previous tutorial , we showed how to create dynamic images images in a servlet. In this tutorial, we are going to take it a step further by dynamically adding a text watermark to an image as it is requested. Setting up the Servlet In the web.xml, you will need to configure a filter that will be used to call the servlet. By creating a filter, this will simplify the url used to access the servlet and image. To an end user, the filter will look like part of the directory structure for the image. The servlet will be invoked when the url contains the pattern /watermark/*. In our example, we will place the images in a directory called photos in the web application directory. To view the image without the watermark, you would use the url http://webserver/webapp/photos/car.jpg. To invoke the servlet, you would use the url http://webserver/webapp/watermark/photos/car.jpg. view plain copy to clipboard print ? servlet > servlet-name > com.codebeach.servlet.Wa...