Instantiating a socket can be done in various ways.
by 2 line declaration & instantiation:
First we need to define a variable which will hold a Socket class object:
then we can create a Socket class object:
socket = new Socket();
We can also make a one line definition & instantiation:
Socket socket = new Socket();
both ways will create an unconnected socket.
We can use other parameterized constructors to instantiate connected or unconnected socket class object:
For details see class doc specs: