Java Articles

Page 168 of 450

Java Program to Implement Associative Array

Ashin Vincent
Ashin Vincent
Updated on 27-Feb-2025 329 Views

What is an associative array? An associative array stores data in key-value pairs where we can retrieve values using unique keys. There is a significant difference between standard arrays and associative arrays. Normal arrays use numbers for indexing (like arr[0], arr[1], arr[2]). Whereas in an associative array, we use meaningful names such as "name" or "city” to identify each value. Example Let's consider a list of student grades where names act as keys − Key (Student Name): Value (Marks) Raju: 85 Krishna: 90 Yash: 78 This lets us find the grades of students by using their names instead of ...

Read More

Java Program to Print Odd Elements at Odd Index

Ashin Vincent
Ashin Vincent
Updated on 27-Feb-2025 294 Views

In this article, we will learn how to find and print the odd numbers that are present at odd index positions in an array. First we will understand the problem with the help of an example, and then we will learn three approaches to implement it in Java. Example Consider the array = [2, 1, 4, 4, 5, 7]. The odd numbers at odd indices are 1 and 7. Explanation The indexing of an array starts from 0. Here the element 1, which is an odd number, is present at index 1, which is an odd index. In the same ...

Read More

Java Program to Generate Random Hexadecimal Value

Ashin Vincent
Ashin Vincent
Updated on 27-Feb-2025 317 Views

In this article, we will learn how to generate random hexadecimal number values in Java. Random hexadecimal values are used in many applications, like unique identifiers, cryptographic keys, session tokens, or colour codes. We will discuss three different ways to generate random hexadecimal values in Java − Using Random – A simple, fast method to make random hexadecimal values. Using SecureRandom – Best for secure random hexadecimal numbers. Using BigInteger – Helps produce large random hexadecimal numbers. 1. Using Random In this approach, we use the Random class to produce random numbers from 0 to 15. After ...

Read More

James Gosling:The Father of Java

Ashin Vincent
Ashin Vincent
Updated on 27-Feb-2025 855 Views

James Arthur Gosling, also known as the Father of Java, is one of the greatest minds in computer science and programming history. He created the Java programming language in 1994, which became a revolutionary invention that transformed the software development industry. Java lets developers run a single code on any device, which makes it a platform-independent language. Other than java, Gosling has worked on several technical areas such as Artificial intelligence, software engineering and cloud computing. Early life and education James Gosling was born on May 19, 1955, in Calgary, Alberta, Canada. He developed an interest in computers at an ...

Read More

Java Program to Increment All Elements of an Array by One

Ashin Vincent
Ashin Vincent
Updated on 27-Feb-2025 249 Views

Arrays are one of the most fundamental data structures in programming, and they are used to store elements of the same data type in contiguous memory locations. If you are not familiar with the array concept, do check out this article on Arrays. In this article, we will learn how to increment every element of an array by one and print the incremented array. For example, If the input array is [3, 7, 10] The output should be [4, 8, 11] We can solve this problem using different approaches − Using for-loop Using java streams Using arrays.setAll() ...

Read More

How to find hyperfactorial in Java?

Ashin Vincent
Ashin Vincent
Updated on 27-Feb-2025 241 Views

What is hyperfactorial? The hyperfactorial of a number is the product of numbers from 1 to the given number where each number is raised to the power of itself. For example, the hyperfactorial of 4 will be − = 1^1 * 2^2 * 3^3 * 4^4 = 1*4*27*256 = 27648 So we can say that the formula for finding hyperfactorial is − H(n)=1^1 * 2^2 *3^3 * 4^4 * 5^5 * . . . . . . . . . * n^n In this article, we will learn different approaches to find the hyperfactorial of a number, ...

Read More

How to pad a String in Java?

Ashin Vincent
Ashin Vincent
Updated on 27-Feb-2025 562 Views

What is string padding? String padding means adding extra spaces or characters to the string to reach a specified length. This extra character or space can be added before the string, after the string, or on both sides of the string. This is useful for formatting output or aligning text in documents in order to improve the overall appearance of the content. For example, while displaying a table, padding helps to align the content properly so that every column in the lineup is correct. Approaches to pad a string in Java There are multiple approaches to pad a string in ...

Read More

Java program to find Harmonic series

Shiva Keerthi
Shiva Keerthi
Updated on 26-Feb-2025 1K+ Views

The reciprocals of an arithmetic series without considering 0 is known as Harmonic series. If $a_{1}, a_{2}, a_{3}$… is arithmetic series then $\frac{1}{a1}$, $\frac{1}{a2}$, $\frac{1}{a3}$, … is the harmonic series. In this article, we will discuss how to implement a Java program to find the harmonic series. Harmonic Series For 1st term n = 1 and for every term n is incremented by 1 and at last the nth term the value is ‘n’. Harmonic series : $1+\frac{1}{2}+\frac{1}{3}$.......+$\frac{1}{n}$ Where, 1/n is the nth term of harmonic series. Problem Statement Write a Java program to find the ...

Read More

Java Concurrency – join() method

Alshifa Hasnain
Alshifa Hasnain
Updated on 25-Feb-2025 678 Views

In this article, we will learn about concurrency in Java. It allows multiple threads to execute simultaneously, sharing system resources efficiently. One of the methods provided in the Thread class for managing thread execution is the join() method. What is the join() Method? the join () function is used to join the beginning of the execution of a thread to the end of the execution of another thread. This way, it is ensured that the first thread won’t run until the second thread has stopped executing. This function waits for a specific number of milliseconds for the thread to terminate. ...

Read More

Java program to divide a number into smaller random ints

Alshifa Hasnain
Alshifa Hasnain
Updated on 24-Feb-2025 685 Views

In this article, we will learn to divide a number into smaller random ints in Java. Dividing a number into smaller random integers is a useful technique in various applications such as resource allocation, gaming, and randomization processes Divide a Number into Random Parts The approach relies on generating unique random dividers within the given number and then computing the differences between consecutive dividers to form the final parts.  Following are the steps to divide a number into smaller random ints in Java Create a HashSet to ...

Read More
Showing 1671–1680 of 4,498 articles
« Prev 1 166 167 168 169 170 450 Next »
Advertisements