- 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
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
496 Views
In order to export preferences to an XML file in Java, we need to use the exportSubtree() method. This method emits an XML document showing all of the preferences contained in this node and all of its descendants. This XML document provides an offline backup of the subtree rooted at the node.Declaration − The java.util.prefs.Preferences.exportSubtree method is declared as follows −public abstract void exportSubtree(OutputStream os) throws IOException, BackingStoreExceptionLet us see a program to export preferences to an XML file in Java −import java.io.FileOutputStream; import java.util.prefs.Preferences; public class Example { public static void main(String args[]) throws Exception { Preferences ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
158 Views
Elements can be filled in a short array using the java.util.Arrays.fill() method. This method assigns the required short value to the short array in Java. The two parameters required are the array name and the value that is to be stored in the array elements.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { short[] shortArray = new short[5]; short shortValue = 1; Arrays.fill(shortArray, shortValue); System.out.println("The short array content is: " + Arrays.toString(shortArray)); ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
332 Views
In order to remove a preference from a preference node in Java, we use the remove() method. The remove method() removes all the values associated with the specified key in the preference node.Declaration − The java.util.prefs.Preferences.remove() method is declared as follows −public abstract void remove (String key)where key is the key whose preference is to be removedThe remove methods throws the following exceptions −NullPointerExceptionThis exception occurs when the key is nullIllegalStateExceptionThis exception is thrown when the ancestor node is removed by the removeNode() method.Let us see a program to remove the preference from a preference node −Example Live Demoimport java.util.prefs.Preferences; public ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
570 Views
An array of field objects is returned by the method java.lang.Class.getFields(). These field objects include the accessible public fields of the class that is represented by the class object.Also, the getFields() method returns a zero length array if the class or interface has no public fields that are accessible or if a primitive type, array class or void is represented in the Class object.A program that demonstrates this is given as follows −Example Live Demoimport java.lang.reflect.*; public class Demo { public static void main(String[] argv) throws Exception { Class c = java.lang.Thread.class; Field[] fields ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
3K+ Views
To replace all words with another String using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.Declaration − The java.lang.String.replaceAll() method is declared as follows −public String replaceAll(String regex, String replaced) Let us see a program to replace all words with another string with Java Regular Expressions −Example Live Demopublic class Example { public static void main( String args[] ) { String str = new String("Good Harry Good"); System.out.println( "Initial String : "+ str); ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
7K+ Views
To replace one string with another string using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.Declaration − The java.lang.String.replaceAll() method is declared as follows −public String replaceAll(String regex, String replaced) Let us see a program to replace one string with another string using Java Regular Expressions −Example Live Demopublic class Example { public static void main( String args[] ) { String str = new String("Good Harry Good"); System.out.println( "Initial String : "+ str); ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
2K+ Views
To replace *' with '^' using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.Declaration − The java.lang.String.replaceAll() method is declared as follows −public String replaceAll(String regex, String replaced) Let us see a program to replace '*' with '^' using Java Regular Expressions −Example Live Demopublic class Example { public static void main( String args[] ) { String str = new String("H*e*l*l*o"); System.out.println( "Initial String : "+ str); // replacing '*' ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
292 Views
In order to match the phone using regular expression, we use the matches method in Java. The java.lang.String.matches() method returns a boolean value which depends on the matching of the String with the regular expression.Declaration − The java.lang.String.matches() method is declared as follows −public boolean matches(String regex)Let us see a program to validate a phone number with regular expressions −Example Live Demopublic class Example { public static void main( String[] args ) { System.out.println(phone("+91 1023456789")); } // validate zip public static boolean phone( String z ) { return z.matches("\+[0-9]*\s+\d{10}" ); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
179 Views
Binary search on a long array can be implemented by using the method java.util.Arrays.binarySearch(). This method returns the index of the required long element if it is available in the array, otherwise it returns (-(insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] args) { long long_arr[] = { 250L, 500L, 175L, 90L, 415L }; Arrays.sort(long_arr); System.out.print("The sorted array ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
395 Views
To format message with currency fillers in Java, we use the MessageFormat class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration −The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder in {} curly braces ... Read More