CORE API / CATATAN</>↗Core API08 Jul 2007
In this example you’ll see how to create a client-server socket communication. The example below consist of two main classes, the ServerSocketExample and the ClientSocketExample. The server application listen to port 7777 at the localhost. When we send a message from the client application the server receive the message and send a reply to the […]
CORE API / CATATAN</>↗Core API06 Jul 2007
This example demonstrates how to use the java.io.ObjectOutputStream and java.io.ObjectInputStream classes to write and read a serialized object. We will create a Book that implements java.io.Serializable interface. The Book class has a constructor that accept all the book detail information. To write an object to a stream we call the writeObject() method of the ObjectOutputStream […]
CORE API / CATATAN</>↗Core API05 Jul 2007
java.io.DataOutputStream and java.io.DataInputStream give us the power to write and read primitive data type to a media such as file. Both of these classes have the corresponding methods to write primitive data type and to read it back. Using this class make it easier to read int, float, double data and others without needing to […]
CORE API / CATATAN</>↗Core API03 Jul 2007
This is an example of using RandomAccessFile class to read and write data to a file. Using RandomAccessFile enable us to read or write to a specific location in the file at the file pointer. Imagine the file as a large array of data that have their own index. In the code below you’ll see […]
SERVLET / CATATAN</>↗Servlet02 Jul 2007
package org.kodejava.servlet; import java.io.IOException; import java.io.PrintWriter; import java.util.Enumeration; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet(urlPatterns = "/request-headers") public class ServletRequestHeader extends HttpServlet implements Servlet...
SERVLET / CATATAN</>↗Servlet01 Jul 2007
In the code example below we will extract information regarding the HTTP (Hypertext Transport Protocol) from the request object (HttpServletRequest). We will extract the protocol used (http / https), server name and its assigned port number. We will also read our application context path, servlet path, path info and the query string. If we combine […]