In our application, logging is one of the important mechanism to capture the messages thrown by the applications. One of the most popular logging framework is log4j which provides the logging in your applications. However, you can implement the logging without adding any third party implementations by the JDK’s built in logging APIs. java.util.logging package …
Java
Java Timer Example
In Java, we have java.util.Timer class for scheduling the tasks at the frequent intervals. The steps for creating the simple job using the java.util.Timer class is: Create the task / job by extending the java.util.TimerTask. A task has to extend java.util.TimerTask and implement the run() method Create the Timer instance to manage the tasks. You …
JQuery ID Selector Example
JQuery Id selector selects elements with the given id attribute. It represents the tag with the given ID in the document object model. The id selector is a name preceded by a hash character (#). The id selector matches an element based on contents of the given id attribute which match exactly the value given …
java.sql.SQLException: Can’t call commit when autocommit=true Exception
When you work with JDBC application, by default the auto commit is set to true, after the transaction is completed all the transactions are committed to the database. When it is set as true, you can not explicitly call the commit method. If you call the connection.commit() method, then the below exception will be thrown.
State Design Pattern In Java
This tutorial explains the state design pattern with a simple example program. State design pattern is very similar to the Strategy pattern, the only difference is that state design pattern maintains the state of the context where as strategy pattern passes the context and execute the specific strategy. The state design pattern is very useful …
How To Split And Merge Files Using Java
When transferring files through network or uploading to internet, it is common that file size could be the real factor. In those scenarios, splitting the file will solve your problem. The files will be splitted into small parts of chunks, that will be merged into a single file at the destination. This example shows how …
Load Files From ClassPath Using getResourceStream()
If you are looking to load a file from the classpath of your project, the use the method getResourceAsStream(). The main difference from the File class is that, File class uses the absolute path for finding the files. java.io are dependent on the current working directory of your application. There are not dependent on the …
Downcasting In Java
Upcasting is assigning the sub class reference object to the parent class which is allowed in Java. Downcasting is assigning parent class reference object to the sub class which is not allowed in Java. However, if you do downcasting, there will not be any compiler error. But, there will be runtime exception java.lang.ClassCastException. Then why …