Found 9150 Articles for Object Oriented Programming

Filter Pattern in Java

Deepti S
Updated on 11-Jul-2023 10:33:38

689 Views

The Filter Design Pattern, also known as the Criteria Design Pattern, is a structural design pattern used by developers to filter objects based on different criteria. It enables decoupled filtering and logical operations by chaining multiple criteria into a single criterion. It provides two techniques for creating filters: filtering for the entire collection or filtering for a particular collection member. To apply criteria to a class, you can follow these steps: Create a class that requires filtering. Develop the criteria's interface. Implement concrete classes that meet the interface's requirements. Filter out certain objects by using a variety of criteria ... Read More

Java Program for Left Rotation and Right Rotation of a String

Prabhdeep Singh
Updated on 11-Jul-2023 08:55:14

3K+ Views

Rotation means we have to shift each character either in a forward direction or backward direction. Forward direction means right rotation (Or anticlockwise) and backward direction means left rotation (Or clockwise). In this problem, we have given a string of characters of size n and integer d. Here d is less than n. Our task is to print the left rotated string or right rotated string by d integer. Only the permutation of the current string changes, not the length or frequency of the characters in the given string. Input 1 str = “apple”, d = 2 Output 1 Left ... Read More

Difference between DataClass vs NamedTuple vs Object in Python

Rohan Singh
Updated on 06-Jul-2023 17:43:43

2K+ Views

Dataclass, NamedTuple, and Object are used to create structured datatypes in Python. Though all three are used to create structured data they differ in their properties and implementation method. In this article, we will understand the difference between DataClass, NamedTuple, and Object in Python. Feature Object NamedTuple Dataclass Creation Objects are created by defining a class and its attributes and methods manually. Named tuples are created using the named tuple function from the collections module. The field names and values are specified manually. Data classes are created using the @dataclass decorator. The class attributes ... Read More

Java Program to Find a Good Feedback Edge Set in a Graph

Rushi Javiya
Updated on 04-Jul-2023 16:00:27

260 Views

A feedback edge set in a graph refers to a set of edges that, when removed from the graph, eliminates all cycles or feedback loops. In other words, it is a subset of edges that, when deleted, transforms the original graph into a directed acyclic graph (DAG). A good feedback edge set is a feedback edge set that has the minimum possible number of edges. In this tutorial, we will learn to find a Good Feedback Edge Set in a Graph. Problem Statement Write a Java program that identifies and removes feedback edges in a graph to construct a Good ... Read More

Java Program to Extract Digits from A Given Integer

Rushi Javiya
Updated on 31-May-2024 14:02:14

19K+ Views

In Java programming, there are scenarios where we need to extract individual digits from an integer for further manipulation or analysis. This tutorial will guide you through the process of extracting digits from a given integer using Java. Syntax while (num > 0) { int digit = num % 10; System.out.println(digit); num = num / 10; } The above is the syntax to extract digits from an integer in Java. We keep extracting the last digit by taking the remainder of the number with 10. We divide the number by 10 until it ... Read More

Java Program to Implement Zhu-Takaoka String Matching Algorithm

Rushi Javiya
Updated on 04-Jul-2023 15:53:46

227 Views

The Zhu-Takaoka algorithm is one of the best algorithms for pattern matching. It is developed using the combination of the Boyer-Moore and KMP string-matching algorithms. The Zhu-Takaoka algorithm utilizes the good character shift and bad character shift techniques to solve the problem. Problem statement − We have given two strings. We need to implement the Zhu-Takaoka algorithm for pattern matching. Sample Examples Input str = "PQRDPQRSSE"; patt = "PQRS"; Output 5 Explanation The ‘PQRS’ pattern exists at position 5. So, it prints 5. Input str = "PQRDPQRSSE"; patt = "PRQS"; Output -1 Explanation ... Read More

Java Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range

Rushi Javiya
Updated on 04-Jul-2023 15:51:49

274 Views

The naïve approach to finding the prime numbers in the given range is to check whether each number is prime. Also, we need to make iterations equal to the given number to check whether the number is prime. So, the naïve approach is very time-consuming, and we need to optimize it to make it time efficient. In this tutorial, we will learn wheel factorization and Sieve of Eratosthenes algorithms given by Sieve to find the prime numbers in the given range efficiently. Problem statement − We have given left and right integer values. We need to implement the Wheel factorization ... Read More

Java Program to Find All Palindromic Sub-Strings of a String

Shriansh Kumar
Updated on 16-Aug-2024 07:52:17

1K+ Views

In this problem, we are given a String and our task is to find all palindromic sub-strings of the specified length. There are two ways to solve the problem. The first way is to compare the characters of sub-string from start to last, and another way is to reverse the sub-string and compare it with the original sub-string to check whether it is palindrome. String in Java is a class which represents a sequence of characters. It is immutable which means once it is created a String object cannot be changed. And, sub-string is a small portion or part of ... Read More

Java program to find 2 elements in the array such that difference between them is largest

Rushi Javiya
Updated on 30-Aug-2024 11:41:20

564 Views

In this problem, we will find two array elements such that the difference between them is maximum using Java. We can make a pair of each element and find the difference between the elements of each pair. After that, we can take a pair whose element has a maximum difference. Another approach is to sort the array and take the largest and smallest elements from the array. Problem statement  We have given an array containing the integer values. We need to find two array elements to maximize the difference between them. Input 1 array[] = { 50, 10, 30, ... Read More

Difference Between Class Method, Static Method, and Instance Method

Pradeep Kumar
Updated on 03-Jul-2023 16:03:42

3K+ Views

A well-liked programming paradigm called object-oriented programming (OOP) emphasizes the use of objects to represent and manipulate data. The ability to construct methods that can interact with these objects is one of the main characteristics of OOP. Class methods, static methods, and instance methods are the three different categories of methods in Python. Methods that belong to a class rather than an instance of that class include class methods and static methods. Class methods receive a reference to the class or instance as their first argument, but static methods do not. This is the primary distinction between them. ... Read More

Advertisements