Change the ID of an Immutable String in Python

Yaswanth Varma
Updated on 16-Apr-2025 17:26:18

1K+ Views

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

Execute a String Containing Python Code in Python

Yaswanth Varma
Updated on 16-Apr-2025 17:06:56

19K+ Views

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

Send Data Over Remote Method in Java

Maruthi Krishna
Updated on 16-Apr-2025 17:02:51

739 Views

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

Key Steps in Read/Write from/to a URL Connection in Java

Maruthi Krishna
Updated on 16-Apr-2025 16:29:17

423 Views

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

Largest String Formed by Choosing Words from a Given Sentence

Ravi Ranjan
Updated on 16-Apr-2025 15:58:58

319 Views

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

Difference Between Constructors and Methods in Java

Mahesh Parahar
Updated on 16-Apr-2025 15:54:49

21K+ Views

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

Find Largest, Smallest, Second Largest and Second Smallest in an Array

Ashin Vincent
Updated on 16-Apr-2025 15:53:47

4K+ Views

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

Find Average of a List in Java

Ashin Vincent
Updated on 16-Apr-2025 15:53:07

1K+ Views

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

Difference Between Scanner and BufferedReader Class in Java

Ashin Vincent
Updated on 16-Apr-2025 15:51:50

13K+ Views

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

Differences Between Abstract Class and Concrete Class in Java

Ashin Vincent
Updated on 16-Apr-2025 15:48:22

12K+ Views

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

Advertisements