Responsive Ad Area
Home » Blog » Java » Console » Console Applications

Console Applications

Serializing Java Objects to XML and Deserializing XML back to Java Objects

Like object serialization this is very easy and straight forward. Below is two examples of psuedo code for writing and then reading. This code merely shows the steps. We didn't have to use the buffered streams. With small files you do not have to but with larger files it will speed up reading and writing. XMLEncoder Class //psuedo code does not run import java.beans.*; import*; public class SerializeToXML { public static void main(String args[]){ // an object, composition of objects or collection of objects AnObject anObject = new AnObject(); XMLEncoder encoder=null; try{ encoder=new XMLEncoder(new BufferedOutputStream(new FileOutputStream("objects.xml"))); }catch(FileNotFoundException fnfe){ fnfe.printStackTrace(); } encoder.writeObject(anObject); encoder.close(); } } //psuedo co...

Java Console Applications

Java Console Applications I gave a very small introduction to Java console application execution in the Java Desktop applications article. Java console applications are started in the same manner. I talked about path and classpath which are both very important. If the path and classpath are not set properly then your console application will fail to execute. I explain how to set the classpath on windows in the Desktop Applications article. There is much help on the internet for telling you how to set the system path to add java bin folder. If you do not add the JDK bin folder to the path then when you type 'java' at the command line or any other java tools you will get a not found error. (DOS OR Windows Shell example) [code] set path=%path%;c:\dev\java\jdk8\bin; set classpath=%classpath%;....

Skip to toolbar