Friday, 31 October 2025

Difference between a Public IP address and a Private IP address ?

A public IP address is a unique identifier assigned by an Internet Service Provider (ISP) to a device, such as router or server, allowing it to communicate over the internet. These public IP addresses are globally unique and publicly accessible, enabling data exchange between your network and the external systems via TCP/IP protocol.

Because public IP address is exposed to the internet, they can be used to trace a device's approximate geographic location.

A private IP address, also known as local IP address, is assigned by a router to devices within a home, office or public WIFI network. Unlike a public IP address is exposed to internet, private IPs function only within the local network. Since they don't need to globally unique, the same private IP ranges can be used across different network without conflict.

However, each device on the network receive a different private IP address, allowing the router to manage the data transfers effectively. This enables the internal LAN connections between network devices and ensures that external traffic arriving via the public IP address is forwarded to the correct individual network device.

private IP address ranges:

  • 10.0.0.0 - 10.255.255.255 this range allows for 16 million IP addresses and is often used in large enterprise networks or large organizations that have thousands of devices in their local network.
  • 172.16.0.0 - 172.31.255.255, known as 172.16/12 block, this range allows one million IP addresses  and it is used in medium-sized networks such as schools, universities, and businesses.
  • 192.168.0.0 - 192.168.255.255 this range supports about 65000 IP addresses is primarily used in home and small office networks.

What is a DNS server ? What is the use of a DNS server ?

DNS server translates the human-readable domain names (www.google.com) into machine-readable IP addresses (142.250.70.196) which is required for navigating the internet. We can consider its like a Internet Phone Book.

How it works ?

  • When you type a URL in the browser, your device sends the query to DNS server.
  • The DNS server, known as recursive resolver, it checks in its cache if it has IP address for given domain name. Otherwise, it will searches for it by communicating with other DNS servers, including root name servers and authoritative name servers.
  • Once it finds the IP address, it will be sent back to your device, then your browser connect to that website.
We can see the DNS server in windows using ipconfig command ipconfig /all

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . :

   Description . . . . . . . . . . . : Intel(R) Wi-Fi 6 AX201 160MHz

   Physical Address. . . . . . . . . : XXXXXXXXXXXXXXXX

   DHCP Enabled. . . . . . . . . . . : Yes

   Autoconfiguration Enabled . . . . : Yes

   IPv6 Address. . . . . . . . . . . : XXXXXXXXXXXXXXXX

   Temporary IPv6 Address. . . . . . : XXXXXXXXXXXXXXXX

   Link-local IPv6 Address . . . . . : XXXXXXXXXXXXXXXX

   IPv4 Address. . . . . . . . . . . : 192.168.1.10(Preferred)

   Subnet Mask . . . . . . . . . . . : 255.255.255.0

   Lease Obtained. . . . . . . . . . : Friday, October 31, 2025 9:36:25 AM

   Lease Expires . . . . . . . . . . : Saturday, November 1, 2025 1:21:33 PM

   Default Gateway . . . . . . . . . : fe80::1%13

                                       192.168.1.1

   DHCP Server . . . . . . . . . . . : 192.168.1.1

   DHCPv6 IAID . . . . . . . . . . . : XXXXXXXXXXXXXXXX

   DHCPv6 Client DUID. . . . . . . . : XXXXXXXXXXXXXXXX

   DNS Servers . . . . . . . . . . . : XXXXXXXXXXXXXXXX

                                       XXXXXXXXXXXXXXXX

                                       192.168.1.1

   Primary WINS Server . . . . . . . : 192.168.1.1

   NetBIOS over Tcpip. . . . . . . . : Disabled

Note: Here, the 192.168.1.1 is my router IP address, which is also acting as my DNS server, DHCP server. We can also use the google public DNS server 8.8.8.8 (alternative: 8.8.4.4)

How to trace all the routers from my computer to a website like www.google.com ?

tracert command is a windows based diagnostic tool that traces the each "hop" or router(s) to a destination along the way that route packets take.

How to use tracert command ?

  1. Open cmd prompt
  2. Type the command tracert followed by a destination
    • tracert www.google.com
  3. Press enter
  4. Review the results
Note:
  • tracert works for windows. use traceroute for Linux and MacOs.
  • Windows utility tracert uses Internet Control Message Packets (ICMP) packets to find the route.
  • By default, it will trace up to 30 hops. This can be changed using -h parameter.
    • tracert -h 40 www.google.com
  • Use -d parameter with tracert utility to speed up the trace, which prevents the command from IP addresses to hostnames.
  • Use -w parameter to specify the wait time for a reply in milliseconds.

C:\Users\Dinesh.Dontha>tracert www.google.com

Tracing route to www.google.com [2404:6800:4007:837::2004]

over a maximum of 30 hops:

  1    11 ms     1 ms     1 ms  2401:4900:1c27:f15b:8ea3:99ff:fefc:7fd0

  2     *        *        *     Request timed out.

  3     5 ms     5 ms     5 ms  2404:a800:3a00:2::209

  4     *        *        *     Request timed out.

  5    16 ms    15 ms    15 ms  2404:6800:8202:280::1

  6    21 ms    16 ms    16 ms  2404:6800:8202:280::1

  7    16 ms    16 ms    16 ms  2001:4860:0:1::5658

  8    15 ms    15 ms    15 ms  2001:4860:0:1::4878

  9    39 ms    16 ms    16 ms  2001:4860:0:1::880d

 10    16 ms    16 ms    16 ms  2001:4860:0:1::163f

 11    16 ms    15 ms    16 ms  lcmaaa-as-in-x04.1e100.net [2404:6800:4007:837::2004]

Trace complete.

Thursday, 30 October 2025

Explain some of the Creational Design Patterns ?

  • Creational Design Patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation.
    • Singleton design pattern is a creational design pattern that lets you ensure that a class has only one instance, while providing a global access point to this instance.
    • Builder design pattern is a creational pattern that separates the construction of a complex object from its representation, allowing the same construction process to create different representations. It is particularly useful when an object has a large number of optional parameters or when its construction involves a complex, step-by-step process.
    • Prototype design pattern is a creational pattern that creates new objects by copying an existing object, known as a prototype. This is beneficial for complex or costly object creation, as it's more efficient to clone a pre-configured prototype than to build a new object from scratch. To implement it, you create a Prototype interface with a clone() method that concrete classes implement to copy themselves.
    • Factory design pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify their exact classes. Rather than by calling a constructor, this is accomplished by invoking a factory method to create an object. Factory methods can be specified in an interface and implemented by subclasses or implemented in a base class and optionally overridden by subclasses.

Tuesday, 28 October 2025

How to change the last commit message in Git ?

Use --amend option with git commit

git commit --amend -m "Added application properties"

Sometimes, the above git commit --amend command execution opens up a editing tool like notepad++ with the previous commit message, so that we can alter the commit message. Once after saving this message and closing this editing tool, this changes the log previous message.

Use git log --oneline to check all the commits and commit messages.

Tuesday, 14 October 2025

How to use BiFunction functional interface in java 8 ?

BiFunction is a Functional interface with only one abstract method apply(T t, U u), which takes two arguments and return a result of type R. It is a generic interface defined as BiFunction<T, U, R>

BiFunction interfaces are typically implemented as lambda expressions.

import java.util.function.BiFunction;
import java.util.function.Function;

public class BiFunctionExample {
public static void main(String[] args) {
BiFunction<String, String, String> biFunction = (s1, s2) -> s1 + s2;
System.out.println(checkStr(biFunction));
Function<String, String> function = r -> "Result : " + r;
System.out.println(biFunction.andThen(function).apply("b", "c"));
}

private static Boolean checkStr(BiFunction<String, String, String> biFunction) {
if ("ab".equals(biFunction.apply("a", "b"))) {
return true;
}
return false;
}
}

Result:

true

Result : bc

Monday, 13 October 2025

How to use Duration class in java.time ?

Duration class in java.time package was introduced in Java 8 new Date and Time API.

It represents a time-based amount of time such as `34.5seconds`, `2 hours`. It deals with quantity of time with seconds and nanoseconds precision as well. In addition, DAYS unit can be used and it is treated like 24 hours amount of time, without considering any daylight saving effects. For date based amounts of time one can use java.time.Period class.

Duration class is immutable class and thread-safe. Duration class has static factory methods ofDays(), ofHours(), ofMinutes(), ofSeconds(), ofMillis(), and ofNanos() like for Duration instance creation.
import java.time.Duration;
import java.time.LocalDateTime;

public class DurationExample {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime then = LocalDateTime.of(2025, 10, 13, 22, 52, 0);
System.out.println("Current date time: " + now);
//30 minutes amount of time
Duration duration = Duration.between(now, then);
System.out.println("Duration between now and then " + duration);

//add 10 hours and 2 minutes for the duration
Duration changedDuration = duration.plusHours(10).plusMinutes(2);
System.out.println("changed duration : " + changedDuration);

Duration lessDuration = Duration.ofSeconds(30);
//convert duration to nanoseconds and millis
System.out.println("less duration in nanos : " + lessDuration.toNanos());
System.out.println("less duration in millis : " + lessDuration.toMillis());
}
}

Result:

Current date time: 2025-10-13T21:55:26.190489700
Duration between now and then PT56M33.8095103S
changed duration : PT10H58M33.8095103S

Sunday, 12 October 2025

How to use Clock class in java.time package ?

Clock class is an abstract class defined in java.time package. Use of Clock class is optional compared to date time classes defined in java.time package. 

Clock class has some static method to get UTC time, to print Time Zone information. 

import java.time.Clock;
import java.time.ZoneId;

public class ClockExample {
public static void main(String[] args) {
Clock clock = Clock.systemUTC();
//utc time
System.out.println(clock.instant());

System.out.println("------------------------------");

Clock clock2 = Clock.systemDefaultZone();
System.out.println(clock2);
// always instant() shows the UTC time
System.out.println(clock2.instant());
// current time zone.
System.out.println(clock2.getZone());

//results when executed in "Asia/Calcutta" timezone.
Clock clock3 = Clock.system(ZoneId.of("America/Los_Angeles"));
System.out.println(clock3);
//still the UTC time
System.out.println(clock3.instant());
System.out.println(clock3.getZone());

}
}
Result:
2025-10-12T07:15:55.975588400Z
------------------------------
SystemClock[Asia/Calcutta]
2025-10-12T07:15:56.023460400Z
Asia/Calcutta
SystemClock[America/Los_Angeles]
2025-10-12T07:15:56.023460400Z
America/Los_Angeles
References: Clock class usage - optional

How to use UUID class of java.util package ?

 We can generate a UUID (Unique ID) in java using UUID class of java.util package.

import java.util.UUID;
public class UniqueIdGenerator {
public static void main(String[] args) {
String value = UUID.randomUUID().toString().replace("-", "");
System.out.println("uuid = " + value);
}
}
uuid = 5029262172c74f6cab932f30cb23bb07

Tuesday, 7 October 2025

What is AtomicBoolean? How to use it?

AtomicBoolean class is part of Package java.util.concurrent.atomic.
  • Use primitive boolean or Boolean wrapper class when dealing with single-threaded contexts or when thread-safety is handled by synchronization mechanisms.
  • Use AtomicBoolean class specifically when you need to perform thread-safe, atomic operations on a boolean value in a concurrent environment, especially flags that needs to be updated reliably by multiple threads.
Note: There are many such classes in package java.util.concurrent.atomic.