fbpx
Responsive Ad Area
Home » Blog » Java » Console

Console

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 java.io.*; 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(); } } //psu...

Servers: Java Daemons and Servers

Java Daemons and Servers A server is a daemon but a daemon is not necessarily a server? I think so. I think all a daemon is, is a process that runs in the background, meaning no user interface. You start it up, it hides, runs and does its thing. A server does the same thing but accepts connections from clients which request it to do things for them. The server then does as requested if it can and responds to the client with details, data or files. A server’s user interface is the client itself though actually, they can have admin user interfaces that are web or GUI based. They usually do not have user interfaces but are simply configured, started and stopped. If a java daemon(server) is started then in a process list you will see the Java VM instead of the actual Java class name. If ...

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