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...

Console: Java Console Applications

Java Console Applications The console is, of course, the command prompt. On Windows go to [Start][enter 'cmd' into search] to bring up a command prompt. Could be called a shell also or power shell. Its the text-based screen window for entering commands. 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 ...