Java Tutorials, Tips & Tricks
Java is a programming language originally developed by Sun Microsystems and released in 1995 as a core component of Sun Microsystems’ Java. It is platform independent.
XPath is a language for finding information in an XML file. You can say that XPath is (sort of) SQL for XML files. XPath is used to navigate through elements and attributes in an XML document. You can also use XPath to
traverse through an XML file in Java.XPath comes with powerful expressions that can be used to parse an xml document and retrieve ...
While reading through Stackoverflow, I came up to this interesting question:
Java Properties File binding to Java Interface. The idea is simple but quite helpful.Basically we create an interface like:interface LoginConstants extends Constants { @DefaultStringValue("Welcome to my super app") @Key("appDescription") String appDescription();@DefaultStringValue("Ok") @Key("okButtonLabel") String okButtonLabel(); }And whenever we want to use ...
System.out and System.err stream objects are mapped to "standard" output and error stream respectively. By default, Java display standard output/error on display console.Thus, when we print a statement using System.out:System.out.println("Hello World!"); System.err.println("errr.. Hello World!");It prints the messages to default console.What if you want to reassign the "standard" output and error stream? Lets say you want to redirect all those standard out messages in a ...
Apache POI is a powerful Java library to work with different Microsoft Office file formats such as Excel, Power point, Visio, MS Word etc. The name POI was originally an acronym for Poor Obfuscation Implementation, referring humorously to the fact that the file formats seemed to be deliberately obfuscated, but poorly, since they were successfully reverse-engineered.In this tutorial we will use Apache POI library ...
When you use JSTL format tag <fmt:formatDate> and <fmt:formatNumber>, JSTL automatically takes care of locale resolution. Depending on the browser's locale setting JSTL will display the date and numbers.You may want to override this default behavior. For example in case where you want to display date format only in en_US locale irrespective of user locale setting of browser. Or you may want to store user ...
Whenever you write a Java class in Eclipse which implements java.io.Serializable interface, you'll get this warning:The serializable class XXXX does not declare a static final serialVersionUID field of type longWhy do we need serialVersionUID? Whenever we implement java.io.Serializable interface, we explicitly tell JVM that this class can be serialized. Meaning, we might convert object of this ...
Loading CSV file into Database can be cumbersome task if your Database provider does not offer an out of box feature for this. Most of the time you'll spend up in creating valid insert statements and putting up values escaping all special characters. Importing CSV files gets a bit complicated when you start doing things like ...
If you want to work with Comma-separated Files (CSV) in Java, here's a quick API for you.As Java doesn't support parsing of CSV files natively, we have to rely on third party library.
Opencsv is one of the best library available for this purpose. It's open source and is shipped ...
In Java, we play a lot with Dates. Here's one more scenario. You have a string which has date in it. You want to convert it into a valid java.util.Date object. Now in Java you can convert a String to Date using
SimpleDateFormat class. But we will add a little more complexity on ...
Sometimes Eclipse gives weird errors that you have no clue why is coming. For example, recently I got this strange error in eclipse's Problems view.This project needs to migrate WTP metadataTo remove this error, all you have to do is to re-validate the project.Select the project that you want to validate. Right-click the project and then ...