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 java.io.File class provides an API “exists()” using which we can detect if file is present or not in your filesystem. $ vim FileExists.java [java] import java.io.File; public class FileExists { … Read more

Solved : java.net.BindException: 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” java.net.BindException: Address already in use (Bind failed) at java.net.PlainDatagramSocketImpl.bind0(Native … 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 TcpReceiverServer.java [java] import java.net.*; import java.io.*; 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 DatagramSenderClient.java [java] import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; public class DatagramSenderClient{ private static String remoteServerAddr = "192.168.1.102"; private static int remoteServerPort = 5555; public static void main(String[] args) throws Exception { DatagramSocket localSocket = new DatagramSocket(); String message = "This is string sent from DatagramSenderClient.java 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