Make your own Java webServer


class myserver
public static void main(String str[])

String myIp=null;
int port=786;

//Get Systems current ip address
myIp= Inet4Address.getLocalHost().getHostAddress();
System.out.println(“Server is Running with “+ myIp +”:”+ port);

//Create Server Socket
ServerSocket welcome = new ServerSocket(port);

//Accept incomming connection Socket
Socket sskt = welcome.accept();

PrintWriter out = new PrintWriter(sskt.getOutputStream());

//Create MIME type to describe that, This is HTML Code
out.println(“HTTP/1.1 200 OK”);
out.println(“Content-Type: text/html”);
//Write your HTML Code Here
out.println(“Hello world “);

catch(Exception e)


What  is MIME type?

MIME stands for Multi-purpose Internet Mail Extensions. MIME types form a standard way of classifying file types on the Internet. Internet programs such as Web servers and browsers all have a list of MIME types, so that they can transfer files of the same type in the same way, no matter what operating system they are working in.[2]

A MIME type has two parts: a type and a subtype. They are separated by a slash (/). For example, the MIME type for Microsoft Word files is application and the subtype is msword. Together, the complete MIME type is application/msword.[2]






Share Post