The Internet Protocol suite contains all sort of protocols that enables communication between devices over the Internet. TCP is a connection-oriented protocol, which means it maintains the established connection between two devices till the end of a communication. This is the reason it is used while web surfing, sending emails and transferring files. In this article, we will develop a simple client-server side calculator using TCP in Java. The client will request the operation and the server will send the result to client device after calculating it. Java Networking Let's briefly understand a few basic concepts about Java networking that ... Read More
There are two types of Collections in Java. One is ordered and the other one is unordered collection. The ordered collections store their elements in the order in which they are inserted i.e. it maintains the insertion order of elements. Whereas, the unordered collections such as Map and Set do not maintain any order. In this article, we will create an unordered collection and try to shuffle its elements using the inbuilt method Collections.shuffle(). The Collections.shuffle() Method The Collections.shuffle() method is provided by java.util package. It takes a list as an argument and then rearranges the elements randomly. Therefore, before ... Read More
In Java, downcasting is the process of converting an object of parent class to object of child class. We need to perform the conversion explicitly. It is quite similar to what we do in primitive typecasting. In this article, we will learn about downcasting and what are the rules that we must follow to downcast an object in Java. There is one more concept for modifying objects named Upcasting. In this process, the object of sub class gets converted to super class object. It can be done implicitly. Both the concepts, upcasting and downcasting together called object casting. Object Downcasting ... Read More
Vectors implement the List interface and are used to create dynamic arrays. The array whose size is not fixed and can grow as per our needs is called as a dynamic array. The vectors are very similar to ArrayList in terms of use and features. In this article, we will learn how we can create a vector and search for a particular element by its index in Java. Let's discuss Vector first. Java Vector Vector is similar to ArrayList in many ways but there exist some differences too. The Vector class is synchronized and several legacy methods are contained in ... Read More
In Java, the static methods are defined using static keywords but to declare instance variables we don't use static keywords. Generally, we can't access the instance variable by a static method. In this article, we will create an instance variable and then we will check the accessibility of that instance variable by a static method. Let's understand static method and instance variable first. Java Instance Variable In the context of programming language, variables are the name of containers that contain data of any type. We can say it is a storage unit. A variable can be initialized at the time ... Read More
A distinct sublist is a continuous portion of a list in which all the elements are different from each other. The goal is to find the maximum length of such a sublist within a given list of elements. In Python, a list is an ordered and mutable data structure in which sequence of elements are enclosed in square brackets []. The elements in a list can be of any datatype such as integer, float, string etc., and each element in a list has a unique index position which starts from 0. Using set() function The set() is a built-in function ... Read More
A Consecutive sequence is a series of numbers where each number follows the previous one without any missing the order like 1, 2, 3, 4. It is a set of numbers where each number appears in increasing order by 1, even if not adjacent. We can find the Consecutive sequences in data structures of Python such as lists, strings, tuple, etc. Using set() function set() is the built-in function in Python which is used to create a Set data structure. This function is used to eliminate the duplicates from the given input. We can use set() function to find the ... Read More
In Python, a string is immutable data structure in which sequence of characters are enclosed in double("") or single quotes(''). In some cases, we need to find the length of the longest subsequence of characters that can be rearranged to form a palindrome. This type of subsequence is referred to as a palindromic anagram subsequence. To solve this, we need to count how many characters appear an even number of times and at most one character can appear an odd number of times. An anagram is a word or phrase formed by rearranging the letters of another word or phrase ... Read More
In Python, a list is a ordered and mutable data structure where elements are enclosed in square braces []. In some scenarios, we may need to count how many elements to the right of each element in the list are smaller than it. Using Binary Search with bisect_left() Function The bisect_left() Function of the bisect method is used locate the insertion point for an element in a sorted list to maintain the list's sorted order. The insertion point returned by bisect_left() is the index where the element can be inserted without violating the sort order by placing it before any ... Read More
In Python, datastructures such as string, list etc., may contain duplicates of a value. In few scenarios, we may need to find which element appears only once while all others elements appear multiple times. Let's go through different methods to find which element occurs exactly once in Python. Using Bitwise XOR The XOR is abbrivated as Exclusive OR is a bitwise operator which returns 1 if the corresponding bits of two operands are different otherwise, it returns 0 if they are same. In Python, we can use the ^ between two operands to perform Exclusive OR operation. Example Following is ... Read More