- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9317 Articles for Object Oriented Programming
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
1K+ Views
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 −Example Live Demoimport java.util.LinkedList; import java.util.List; import ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
554 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 −Example Live Demoimport 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 ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
33K+ Views
In order to generate random array of integers 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 a random array of integers in Java −Example Live Demoimport java.util.Random; public class Example { public static void main(String[] args) { Random rd = new Random(); // creating Random object int[] arr = new int[5]; for (int i = 0; i
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
7K+ Views
In order to generate random bytes in Java, we use the nextBytes() method. The java.util.Random.nextBytes() method generates random bytes and provides it to the user defined byte array.Declaration − The java.util.Random.nextBytes() method is declared as follows −public void nextBytes(byte[] bytes)where bytes is the byte array.Let us see a program to generate random bytes in Java −Example Live Demoimport java.util.Random; public class Example { public static void main(String[] args) { Random rd = new Random(); byte[] arr = new byte[7]; rd.nextBytes(arr); System.out.println(arr); } }Output[B@15db9742Note − The output might ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
6K+ Views
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 −Example Live Demoimport 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.
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
4K+ Views
In order to get the number of available processors in Java, we use the availableProcessors() method. The java.lang.Runtime.availableProcessors() method returns the number of processors which are available to the Java virtual machine. This number may vary during a particular call of the virtual machine.Declaration − The java.lang.Runtime.availableProcessors() method is declared as follows −public int availableProcessors()Let us see a program to get the number of available processors in Java −Example Live Demopublic class Example { public static void main(String[] args) { // print statement at the start of the program System.out.println("Start..."); System.out.print("Number ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
23K+ Views
The getProperty(String key) method in Java is used to returns the system property denoted by the specified key passed as its argument.It is a method of the java.lang.System Class.Declaration − The java.lang.System.getProperty(String key) is declared as follows −public static String getProperty(String key)where key is the name of the System property.Some values of the key are as follows −file.separatorjava.specification.versionjava.vm.versionjava.class.pathjava.vendorjava.class.versionos.archjava.compilerline.separatorjava.versionjava.vendor.urlos.nameLet us see a program showing the use of getProperty() method in Java −Example Live Demopublic class Example { public static void main(String[] args) { System.out.println("System property: " + System.getProperty("user.dir")); System.out.println("Operating System: " + System.getProperty("os.name")); ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
325 Views
In order to display the amount of free memory in the Java Virtual Machine, we use the freeMemory() method. It is a method of the java.lang.Runtime Class. It returns the amount of free memory in the Java Virtual Machine. If we call the gc method, there is a possibility of increase of free memory.Declaration − The java.lang.Runtime.freeMemory() method is declared as follows −public long freeMemory()Let us see a program to display the amount of free memory in the Java Virtual Machine −Example Live Demopublic class Example { public static void main(String[] args) { // print statement at ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
215 Views
In order to display the maximum amount of memory in Java, we use the maxMemory() method. It is a method of the java.lang.Runtime Class. It returns the maximum amount of memory that the Java Virtual Machine will try to use.Declaration − The java.lang.Runtime.maxMemory() method is declared as follows −public long maxMemory()Let us see a program to display the maximum amount of memory in Java −Example Live Demopublic class Example { public static void main(String[] args) { // print statement at the start of the program System.out.println("Start..."); // displays the maximum memory ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
510 Views
In order to determine the existence a preference node in Java, we use the nodeExists() method. The nodeExists() method returns a boolean value. It returns true when the specified preference node exists in the same tree as this node.Declaration − The java.util.prefs.Preferences.remove() method is declared as follows −public abstract boolean nodeExists(String pathname)throws BackingStoreExceptionwhere pathname is the path name of the node whose existence needs to be determined.Let us see a program to determine if a preference node exists in Java −Example Live Demoimport java.util.prefs.Preferences; public class Example { public static void main(String[] args) throws Exception { boolean ... Read More