In Python, strings are immutable, which means once the string is created, it cannot be changed. Because of this immutability, any operation that tries to modify the string results in creating a new string object with a different identity. Every object in Python has a unique identity, which can be accessed by using the built-in id() function. In this article, we are going to learn about changing the id of an immutable string in Python. We cannot directly change the ID of the immutable string, but by reassigning or modifying it, we can create a new string and ... Read More
In Python, it is possible to execute the dynamically generated code or code stored as a string using the Python built-in functions like eval() and exec(). Both eval() and exec() functions should be used carefully, especially with untrusted input, as they execute any code, including the harmful instructions causing the security risk. In this article we will we go through several example of how to execute string containing the python code. Using Python eval() Function The Python eval() function is used to evaluate the string as a python expression and return ... Read More
RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing/running in one system (JVM) to access/invoke an object running on another JVM. RMI is used to build distributed applications; it provides remote communication between Java programs. It is provided in the package java.rmi. To create an RMI Java application, you need to follow the steps given below - Step 1: Define the Remote Interface A remote interface provides the description of all the methods of a particular remote object. The client communicates with this remote interface. Therefore, you need to create an interface that extends ... Read More
The URL class in the java.net package represents a web address or URL (Uniform Resource Locator), which points to a web resource such as a file, page, or directory in the World Wide Web (internet). The URL class provides various constructors, one of which accepts a String parameter (representing a URL) and constructs an object of the URL class. Reading From a URL You can read content from a URL using the openStream() method. This method opens a connection to the web address specified by the current URL object and gives you an InputStream object. The Java InputStream is an ... Read More
To find the largest string formed by choosing words from a given sentence, a user should know about the lexicographically largest string. A lexicographically largest string is a string, when sorted alphabetically, it would appear at the last if we form all possible strings from the selected words. For example: {lion, zebra, apple} will be lexicographically sorted as {apple, lion, zebra}. In this article, we have been given a string and a pattern. Based on this pattern, we have to find the lexicographically largest string matching the given pattern by choosing words from the sentence using C. Here is an ... Read More
Constructors are special methods used to initialize objects, whereas methods are used to execute certain statements. Constructors and methods are both blocks of code inside a class, but they have different purposes. In this article we will learn about the main differences between a constructor and a method. What is a Constructor in Java? A constructor is a special method in Java that is automatically called when an object is instantiated. Constructors have the same name as the class and do not have a return type. Its main purpose is to set initial values to the newly created object. ... Read More
In this problem we are given an array of numbers, and we have to find the largest, smallest, second largest, and second smallest elements in an array in Java. Let’s understand the problem better with the help of an example: Input int arr[] = {55, 10, 8, 90, 43, 87, 95, 25, 50, 12}; Output Smallest element = 8 2nd Smallest element = 10 Largest element = 95 2nd Largest element = 90 To solve this problem, use the following approaches: Using Arrays.sort() Using nested for-loops Optimized one-pass approach Using Arrays.sort() In this ... Read More
Given a list of numbers, our task is to calculate the average of this list. The average of a list can be found by adding all the elements in the list and dividing the sum by the total number of elements. In this article we will learn different methods to implement this in Java. There are multiple ways in Java to find the average of a list. In this article we will explore two different approaches: Using Java Streams Using for loop Find Average of a List Using Java Streams This approach shows how to find ... Read More
Scanner and BufferedReader classes are used to read input from an external system. Scanner is normally used when we know input is of type string or of primitive types, and BufferedReader is used to read text from character streams while buffering the characters for efficient reading of characters. What is Scanner Class? The Scanner class is included in the java.util package. It is mostly used when the data type of the input is already known. We commonly use it with data ty+pes like strings, integers, floats, and booleans. It has built-in methods like nextInt(), nextDouble(), and nextLine() that help ... Read More
Abstract class and concrete class are fundamental concepts of object oriented programming in Java. In this article, we will learn the differences between an abstract class and concrete class. What is an Abstract Class? An abstract class is a class that cannot be used to create objects. It can only be accessed using its subclasses. It can contain abstract methods, which are methods without a body. It acts as a blueprint for its subclasses. It can also contain concrete or regular methods. Example This example shows how to implement an abstract class in java: ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP