How to check if File Exists in JAVA ?

If you want to check whether certain file is present or not in your disk before proceeding further to do some operations in JAVA, the class provides an API “exists()” using which we can detect if file is present or not in your filesystem. $ vim [java] import; public class FileExists { … Read more

Solved : Address already in use (Bind failed)

If you are working with TCP / UDP sockets in JAVA, there is higher chances your might have seen an exception like below, while trying to create a new socket on specific predefined port number instead of using dynamically allocated port number. Exception in thread “main” Address already in use (Bind failed) at … Read more

Writing TCP server and client socket programs in JAVA

As we have already seen, how to write UDP socket programs in JAVA, now we will write a sample TCP client and server in java. $ vim [java] import*; import*; public class TcpReceiverServer extends Thread { private static int remoteServerPort = 5555; private ServerSocket localServerSocket = null; public TcpReceiverServer() { try { … Read more

Sending and receiving message as part of DatagramPacket using JAVA DatagramSocket ( JAVA DatagramSocket Client and Server Example )

$ vim [java] import; import; import; public class DatagramSenderClient{ private static String remoteServerAddr = ""; private static int remoteServerPort = 5555; public static void main(String[] args) throws Exception { DatagramSocket localSocket = new DatagramSocket(); String message = "This is string sent from Client"; InetAddress remoteServerInetAddr = InetAddress.getByName(remoteServerAddr); DatagramPacket dataGramPacket = … Read more

How to Install Java using apt-get command on Ubuntu ?

Installing JAVA on ubuntu can be done using following easiest command. for ubuntu 16.04, this command installs OpenJDK 8 as we can see details in additional packages installed. $ sudo apt-get install default-jdk The following additional packages will be installed:ca-certificates-java default-jdk-headless default-jre default-jre-headless fonts-dejavu-extra java-common libgif7 libice-dev libpthread-stubs0-dev libsm-dev libx11-6 libx11-dev libx11-doc libxau-devlibxcb1-dev libxdmcp-dev libxt-dev … Read more