Found 9150 Articles for Object Oriented Programming

Java Program to Separate the Individual Characters from a String

Rudradev Das
Updated on 12-Apr-2023 17:40:29

5K+ Views

In the field of computer science, the string is a collection of a continuous character data sets. Here in this particular problem we will use some spaces to execute the logic. The individual characters present here in the string can be accessed through its index to perform the code. Here is a general flow to build a logic code to separate the individual characters from a string in a Java environment. Define a string with characters. Print the individual characters present from a given string. Set an initial to zero. Print the string by using the function string.charAt(i). Iterate ... Read More

Java Program to Illustrate String Interpolation

Shriansh Kumar
Updated on 31-Jul-2024 19:53:44

1K+ Views

String interpolation is a concatenation technique used to display output text dynamically or effectively by replacing the placeholder characters with variables (or strings in the subsequent examples). It restructures the code and prevents the need to repeatedly use variables to produce the output. It makes it efficient to write lengthy variable names or text just by replacing the placeholder with the variable names allocated to strings. String Interpolation in Java There are several ways in Java to perform String Interpolation with the help of the concatenation operator and library function or class. Here, we will discuss four different methods ... Read More

Java Program to Illustrate Use of Binary Literals

Sakshi Ghosh
Updated on 28-Jan-2025 18:23:53

545 Views

In this article, we will learn to illustrate the use of binary literals in Java. This feature is particularly useful when working with low-level data manipulation, such as in embedded systems or when dealing with bitwise operations. What is Binary Literal? A binary literal is a number that is denoted using binary digits that are 0s and 1s. The values written in data types – byte, int, long, and short can be easily expressed in a binary number system. The prefix 0b or 0B is added to the integer to declare a binary literal. For example − ... Read More

Java Program to Illustrate the usage of Octal Integer

Sakshi Ghosh
Updated on 12-Apr-2023 12:30:06

246 Views

Octal Integer is a number system having a base of 8 and digits from 0 to 7. Int data type is taken into account to store an octal number. The usage of the Octal number system is to be discussed here − Converting decimal to Octal Converting octal to decimal. Conversion from a Decimal number system to an Octal Number system Basics of Conversion To convert any decimal number into its equivalent octal number: Keep dividing the decimal number by the base of the octal number system which is 8 till the quotient 0 is received. Remember ... Read More

Java program to solve set cover problem

Rudradev Das
Updated on 11-Nov-2024 19:16:40

647 Views

The set covering is a well-known NP-hard problem in the combinational optimization technique. We call the set cover problem NP-Hard because there is no polynomial real-time solution available for this particular problem. An algorithm called greedy heuristic is a well-known process for the set cover problem. Here is an example − Let U be the universe of elements, {S1, S2, .....Sm} be collection of subsets of the set, U and Cost(S1), C(S2), ......Cost(Sm) be costs of subsets. 1)Let I is the set of elements included so far. Initialize the process I = {} 2) Do following ... Read More

Java Program to Shuffle Vector Elements

Rudradev Das
Updated on 12-Apr-2023 17:06:51

223 Views

Shuffle() is collection class method in Java, works in a random manner based on the permutation logic on a specific group of list elements. Tree are two distinct types of method in a shuffle class(), depending on the particular parameters. Java Collections shuffle(list) Method. Java Collections shuffle(list, random) Method. In this method, we can arrange the characters randomly to generate some random values. Then we will apply the suffle method on it. To perform the vector shuffle, we can use Fisher-Yates shuffle algorithm. In this method, we can learn a linear scan on a vector and swap each ... Read More

Java Program to Show Time By Rolling Through Hours and Months

Rudradev Das
Updated on 12-Apr-2023 17:04:57

163 Views

The credibility of an efficient coding language depends upon how well it can manage the date and time. In a Java Virtual Environment we get some inbuilt facilities like date, time and calendar to handle the problem related to date and time. java. until date class - In Java, there are many contains those are very important for the program. Date class deals with the operation about the date and time. They are those type of classes which comes with the feature of cloneable, Serializable and comparable interfaces. Extract the current date and time - There are two types ... Read More

Java Program to show the Nesting of Methods

Rudradev Das
Updated on 13-Apr-2023 11:58:33

6K+ Views

Nesting of methods is a hybrid function calling method in Java, which can call another method in the same class. There are two types of nested classes are available in a Java environment. Non-static nested class (also known as , the inner class) Static nested class A non-static nested class (or, inner class) is a defined class within a particular class. It also contains some outer classes with some access authorities. In this method, we can use "." operator to create the instance of the inner class by using an outer class. On the other hand; a static ... Read More

Java Program to Segregate 0s on Left Side & 1s on Right Side of the Array

Rudradev Das
Updated on 06-Aug-2024 22:37:14

2K+ Views

Segregation is a process in the field of software engineering where a code is forced to depend on those methods that are not in use. The segregation interface is known as ISP. It splits the interfaces that are vast in nature. In a Java environment, there are lots of advantages to implementing the segregation principle. It increases the readability of the particular code. It also helps to maintain that particular code conveniently. Problem Statement There is an array of 7s and 16s aimlessly. We must segregate the 7s on the left side and the 16s on the right. The basic ... Read More

Java Program to Search User Defined Object From a List By using Binary Search Comparator

Rudradev Das
Updated on 11-Apr-2023 15:49:36

335 Views

Java comparator interface used to sort Java objects. A comparator class in Java compares the different objects (Obj 01, Obj 02) by invoking the "java. util. comparator". In this method the objects can be compared on the basis of the return value. It can be positive, equal or negative in comparison. The process provides user multiple sorting sequences. There are lots of method by which we can perform the comparison between two methods. public int compare class (obj 1, obj 2) - Perform comparison between two objects. public Boolean equals (obj) - Compare current object with specified object. ... Read More

Advertisements