Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Nancy Den
Page 5 of 18
Generate Random Integer Numbers in Java
In order to generate Random Integer Numbers in Java, we use the nextInt() method of the java.util.Random class. This 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 generate random integer numbers in Java −Exampleimport java.util.Random; public class Example { public static void main(String[] args) { Random rd = new Random(); // creating Random object System.out.println(rd.nextInt()); } }Output27100093Note - The output might vary on Online Compilers.
Read MoreConvert a Queue to a List in Java
In order to convert a Queue to a List in Java, we can create an LinkedList and pass the Queue as an argument in the parameterized constructor of an ArrayList. This can be done as follows −Queue q = new LinkedList(); List l = new ArrayList(q);The quickest way is used to LinkedList in the first place which can be used both as a List and a Queue. This can be done as follows −Queue q = new LinkedList(); List l = (List) q;Let us see a program to convert a queue to a list −Exampleimport java.util.LinkedList; import java.util.List; import java.util.Queue; ...
Read MoreGet ceiling value of a number using Math.ceil in Java
In order to get the ceiling value of a number in Java, we use the java.lang.Math.ceil() method. The Math.ceil() method returns the smallest (closest to negative infinity) double value which is greater than or equal to the parameter and has a value which is equal to a mathematical integer on the number line. If the parameter is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument. If the argument value is less than zero but greater than -1.0, then the value returned is negative zero.Declaration − The java.lang.Math.ceil() method is ...
Read MoreGet Canonical Name for a class in Java
The canonical name of a class can be obtained using the java.lang.Class.getCanonicalName() method. This method returns the canonical name of the underlying class and returns null if there is no canonical name for the underlying class.A program that demonstrates the getCanonicalName() method to obtain the canonical name is given as follows −Examplepackage Test; import java.lang.*; public class Demo { public static void main(String[] args) { Demo obj = new Demo(); Class c = obj.getClass(); System.out.println("The canonical name of the underlying Class is: " + c.getCanonicalName()); } }OutputThe canonical name ...
Read MoreCheck whether String is an interface or class in Java
The method java.lang.Class.isInterface() is used to find if String is an interface or class in Java. This method returns true if String is an interface, otherwise it returns false.A program that demonstrates this is given as follows −Examplepackage Test; import java.lang.*; public class Demo { public static void main(String[] args) { Class c = String.class; boolean interfaceFlag = c.isInterface(); System.out.println("This is an Interface? " + interfaceFlag); } }OutputThis is an Interface? falseNow let us understand the above program.The isInterface() method is used to find if String is an interface ...
Read MoreLoad class with forName() method in Java
The class object associated with the class with the given string name can be returned with the method java.lang.Class.forName(String name, boolean initialize, ClassLoader loader), using the class loader that is used to load the class.The parameters in the forName() method are name, initialize and loader. If the value of the parameter loader is null, then the class is loaded using the bootstrap class loader. Also, if the initialize parameter is true, then only the class is initialized if it has not been initialized earlier.A program that loads the class using the forName() method is given as follows −Exampleimport java.lang.*; public ...
Read MoreDisplay the declared methods of java.lang.Math
The methods of the java.lang.Math class can be listed using the java.lang.Class.getDeclaredMethods() method. This method returns an array that contains all the Method objects with public, private, protected and default access. However, the inherited methods are not included. Also, the getDeclaredMethods() method returns a zero length array if the class or interface has no methods or if a primitive type, array class or void is represented in the Class object.A program that demonstrates this is given as follows −Exampleimport java.lang.reflect.Method; public class Demo { public static void main(final String[] args) { final Method[] methods = Math.class.getDeclaredMethods(); ...
Read MoreIncrease the font size of a paragraph with Bootstrap
Use the .lead class in Bootstrap to increase the font size of a paragraph.You can try to run the following code to implement lead class −Example Bootstrap Example Football FIFA The 2018 FIFA World Cup is the 21st FIFA World Cup. FIFA, 2018 is going on in Russia.
Read MoreDefine the style for the body of the modal with Bootstrap
Use the .modal class to define the style for the body of the modal.You can try to run the following code to implement the .modal class −Example Bootstrap Example Website Information Info × Warning If JavaScript isn't enabled in your web browser, then you may not be able to see this information correcty. Close
Read MoreSet Bootstrap Panel with Heading
Follow the below steps to set Bootstrap panel with heading −Use .panel-heading class to add a heading container to your panel.Use any - with a .panel-title class to add a pre-styled heading.You can try to run the following code for panel with headings in Bootstrap −Example Bootstrap Example Tutorials Learn for free Quiz Attempt these quizzes
Read More