Krantik Chavan

Krantik Chavan

176 Articles Published

Articles by Krantik Chavan

Page 7 of 18

Roll a six-sided die 6000 times in Java

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 695 Views

In order to roll a six sided die 6000 times in Java, we need to the nextInt() statement with decision making statements.The nextInt() method returns the next random integer value from this random number generator sequence.Declaration − The java.util.Random.nextInt() method is declared as follows −public int nextInt()Let us see a program to roll a six sided die 6000 times −Exampleimport java.util.Random; public class Example {    public static void main(String args[]) {       Random rd = new Random(); // random number generator       int freq[] = new int[6]; // creating an array to compute frequency of ...

Read More

List the Interfaces That a Class Implements in Java

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 744 Views

The interfaces that are implemented by a class that is represented by an object can be determined using the java.lang.Class.getInterfaces() method. This method returns an array of all the interfaces that are implemented by the class.A program that demonstrates this is given as follows −Examplepackage Test; import java.lang.*; import java.util.*; public class Demo {    public static void main(String[] args) {       listInterfaces(String.class);    }    public static void listInterfaces(Class c) {       System.out.println("The Class is: " + c.getName());       Class[] interfaces = c.getInterfaces();       System.out.println("The Interfaces are: " + Arrays.asList(interfaces));   ...

Read More

Get the class name for various objects in Java

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 445 Views

The getName() method is used to get the names of the entities such as interface, class, array class, void etc. that are represented by the class objects. These names are returned in the form of a string. The getPackage() method gets the package for the given class.A program that gets the class name for various objects is given as follows −Examplepackage Test; import java.io.IOException; import java.util.HashMap; public class Demo {    public static void main(String args[]) throws IOException {       Object obj = "string";       System.out.println("The class name is: " + obj.getClass().getName());       obj ...

Read More

Get all declared fields from a class in Java

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 4K+ Views

An array of field objects is returned by the method java.lang.Class.getDeclaredFields(). These field objects include the objects with the public, private, protected and default access but not the inherited fields.Also, the getDeclaredFields() method returns a zero length array if the class or interface has no declared fields or if a primitive type, array class or void is represented in the Class object.A program that demonstrates this is given as follows −Examplepackage Test; import java.lang.reflect.*; public class Demo {    int i;    char c;    public Demo(int i, char c) {       this.i = i;       ...

Read More

Add a gray background color to the active link in a default Bootstrap navbar

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 695 Views

To add gray background color to the active link, use the .active class in Bootstrap.You can try to run the following code to implement .active class −Example           Bootstrap Example                                                                      Website                                        Home                Tutorials                Quiz                                            Demo          This is demo text.          

Read More

Bootstrap table-condensed class

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 1K+ Views

Using the .table-condensed class, row padding is cut in half to condense the table. as seen in the following example. This is useful if you want any denser information.You can try to run the following code to implement table-condensed class in Bootstrap −Example           Bootstrap Table                                                Footballer Rank                                      Footballer                Rank                Country                                                            Messi                1                Argentina                                        Neymar                2                Brazil                                        Ronaldo                3                Portugal                                

Read More

Fade in tab with Bootstrap

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 4K+ Views

Use the .in class in Bootstrap to fade in the tab.You can try to run the following code to fade in tab −Example           Bootstrap Example                                          Tutorials Website          The following is our learning content:                       Home             About             Product                                                Home                This is demo text!                                        About                This is demo text!                                        Product                This is demo text!                                

Read More

What is static import in Java?

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 867 Views

As import statement allows to use a class without its package qualification, static import allows to access the static members of a class without class qualifications. For Example, to access the static methods you need to call the using class name − Math.sqrt(169); But, using static import you can access the static methods directly. Example import static java.lang.Math.*; public class Sample{ public static void main(String args[]){ System.out.println(sqrt(169)); } } Output 13.0

Read More

Java program to sort string stream with reversed comparator

Krantik Chavan
Krantik Chavan
Updated on 23-Nov-2024 821 Views

In this article, we will learn how to sort a stream of strings using a reversed comparator in Java. Java 8 introduced the Stream API, which allows powerful operations like sorting using custom comparators. Java Comparator A Comparator is a functional interface in Java that defines custom sorting logic. It compares two objects and returns a result based on the comparison. Java Stream A Stream is a sequence of elements that can be processed in parallel or sequentially, supporting methods like sorting, filtering, and mapping. Sorting string stream with a reversed comparator The following are the steps for sorting a ...

Read More

Java program to disable the first item on a JComboBox

Krantik Chavan
Krantik Chavan
Updated on 14-Nov-2024 1K+ Views

In this article, we will learn to disable the first item on a JComboBox using Java. This setup is useful for applications where you want to show a placeholder as the first item and prevent it from being chosen, so users must select a valid option. We will be using JComboBox. JComboBox class The JComboBox class in Java is a useful component that combines a dropdown list with a button or a text field. This lets users pick an option from the list or type their input if editing is allowed. It’s great for creating forms where users can choose ...

Read More
Showing 61–70 of 176 articles
« Prev 1 5 6 7 8 9 18 Next »
Advertisements