Inheritance in Java

Inheritance is an important pillar of OOP(Object Oriented Programming). It is the mechanism in java by which one class is allow to inherit the features(fields and methods) of another class. Important terminology: Super Class: The class whose features are inherited is known as super class(or a base class or a paren class). Sub Class: The… Read More »

Java.lang.Boolean Class in Java

Java provides a wrapper class Boolean in java.lang package. The Boolean class wraps a value of the primitive type boolean in an object. An object of type Boolean contains a single field, whose type is boolean. In addition, this class provides useful methods like to convert a boolean to a String and a String to… Read More »

Maximum product of two non-intersecting paths in a tree

Given an undirected connected tree with N nodes (and N-1 edges), we need to find two paths in this tree such that they are non-intersecting and the product of their length is maximum. Examples: In first tree two paths which are non-intersecting and have highest product are, 1-2 and 3-4, so answer is 1*1 =… Read More »

Superperfect Number

Given an integer n. Check whether the number n is superperfect number or not. A superperfect number is a positive integer which satisfies σ2(n) = σ(σ(n)) = 2n, where σ is divisor summatory function. Input: n = 16 Output: yes Explanation: 16 is a superperfect number as σ(16) = 1 + 2 + 4 +… Read More »

Working with UDP DatagramSockets in Java

DatagramSockets are Java’s mechanism for network communication via UDP instead of TCP. Java provides DatagramSocket to communicate over UDP instead of TCP. It is also built on top of IP. DatagramSockets can be used to both send and receive packets over the Internet. One of the examples where UDP is preferred over TCP is the… Read More »

Sort an array of large numbers

Given an array of numbers where every number is represented as string. The numbers may be very large (may not fit in long long int), the task is to sort these numbers. Examples: Input : arr[] = {“5”, “1237637463746732323”, “12” }; Output : arr[] = {“5”, “12”, “1237637463746732323”}; Input : arr[] = {“50”, “12”, “12”,… Read More »