What is a class constant?

JLS-8.3.1.1. static Fields says (in part) A static field, sometimes called a class variable, is incarnated when the class is initialized (§12.4). JLS-4.12.4. final Variables says (in part) A constant variable is a final variable of primitive type or type String that is initialized with a constant expression (§15.28) tl;dr Putting that together, a class constant is a static final field.

JaxbRepresentation gives error “doesnt contain ObjectFactory.class or jaxb.index”

In my case I was able to resolve this by adding a file called “jaxb.index” in the same package folder as the JAXB annotated class. In that file list the simple, non-qualified names of the annotated classes. For example, my file /MyProject/src/main/java/com/example/services/types/jaxb.index is simply one line (since I have only one JAXB typed class): which … Read more

Get only part of an Array in Java?

The length of an array in Java is immutable. So, you need to copy the desired part into a new array.Use copyOfRange method from java.util.Arrays class: startIndex is the initial index of the range to be copied, inclusive.endIndex is the final index of the range to be copied, exclusive. (This index may lie outside the array) E.g.:

equivalent to push() or pop() for arrays?

In Java an array has a fixed size (after initialisation), meaning that you can’t add or remove items from an array. The above snippet mean that the array of integers has a length of 10. It’s not possible add an eleventh integer, without re-assign the reference to a new array, like the following: In Java … Read more

Java String to SHA1

UPDATEYou can use Apache Commons Codec (version 1.7+) to do this job for you. DigestUtils.sha1Hex(stringToConvertToSHexRepresentation) Thanks to @Jon Onstott for this suggestion. Old AnswerConvert your Byte Array to Hex String. Real’s How To tells you how. and (copied from Real’s How To) BTW, you may get more compact representation using Base64. Apache Commons Codec API 1.4, has this nice utility … Read more

What is the difference between JSF, Servlet and JSP?

JSP (JavaServer Pages) JSP is a Java view technology running on the server machine which allows you to write template text in client side languages (like HTML, CSS, JavaScript, ect.). JSP supports taglibs, which are backed by pieces of Java code that let you control the page flow or output dynamically. A well-known taglib is JSTL. JSP also supports Expression … Read more

difference between System.out.println() and System.err.println()

In Java System.out.println() will print to the standard out of the system you are using. On the other hand, System.err.println() will print to the standard error. If you are using a simple Java console application, both outputs will be the same (the command line or console) but you can reconfigure the streams so that for example, System.out still prints to the … Read more