PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

InetAddress class

← All stacks

Theory

187/270

InetAddress class

java.net covers sockets, URLs, addresses. Socket = endpoint for TCP communication.

URL/URLConnection fetch remote resources.

Always handle IOException.

Write one tiny example for InetAddress class. Compile, print one result, and say the output out loud before you type.

Use InetAddress class only when the problem needs it. Don’t force it into every program. Know one beginner trap.

Let's take this on the board with one tiny Main class — no extra files. InetAddress class — prints local machine host name and IP — basic networking API. Start from main, go line by line, and stop at each print. That output is the proof for InetAddress class.

Exam tip

Client socket needs host + port.

Example

import java.net.InetAddress;
public class Main {
  public static void main(String[] args) throws Exception {
    InetAddress local = InetAddress.getLocalHost();
    System.out.println(local.getHostName());
    System.out.println(local.getHostAddress());
  }
}

InetAddress class — prints local machine host name and IP — basic networking API.

Short notes

  • DefInetAddress class is a Java idea you should explain with one small example.
  • RuleKnow the keyword / API used for InetAddress class. Type a tiny Main and print one result.
  • RememberFor InetAddress class, say the output before you code.
  • TrapInetAddress class — only memorising the heading. No example, no trap.
  • Socket = endpoint
  • URL for resources

Questions

1

What is InetAddress class?

2

Why do we use InetAddress class in Java?

3

Write one small example of InetAddress class.

4

What mistake do beginners make with InetAddress class?

5

Where is InetAddress class used in a real program?

Previous← HttpURLConnectionNextReflection API →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.