Bayan Ghanem
Bayan Ghanem

Reputation: 1

what does null means for Serversocket in java

I am a beginner in java socket programming, and i have this line what does null means in this case?

         serverSocket = new ServerSocket(port);
                if (serverSocket != null){
.
.
.
.}

is it mean that socket existed or is connected??

Upvotes: 0

Views: 226

Answers (1)

peterh
peterh

Reputation: 19235

The code snippet you list makes no sense. A constructor in Java either returns a non-null result or throws an exception. In other words: The if statement checking for non-null on the serverSocket variable is not needed. If you use a reasonable IDE like NetBeans (I believe the same is true for Eclipse and Intellij IDEA as well), it will flag this an unnecessary check for null.

Upvotes: 1

Related Questions