- 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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
155 Views
The java.lang.reflect.Array.newInstance(Class componentType, int length) method forms a new array with the component type and length as specified in the argumentsDeclaration − The java.lang.reflect.Array.newInstance(Class componentType, int length) method is declared as follows -public static Object newInstance(Class componentType, int length) throws IllegalArgumentException, NegativeArraySizeExceptionLet us see a program to create an integer array with Array.newInstance with Java Reflection -Example Live Demoimport java.lang.reflect.Array; public class Example { public static void main(String[] args) { int[] arr = (int[]) Array.newInstance(int.class, 3); // creates a new array Array.set(arr, 0, 5); Array.set(arr, 1, 9); Array.set(arr, ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
105 Views
The java.lang.reflect.Array.newInstance(Class componentType, int length) method forms a new array with the component type and length as specified in the argumentsDeclaration − The java.lang.reflect.Array.newInstance(Class componentType, int length) method is declared as follows −public static Object newInstance(Class componentType, int length) throws IllegalArgumentException, NegativeArraySizeExceptionLet us see a program to create array with Array.newInstance with Java Reflection −Example Live Demoimport java.lang.reflect.Array; public class Example { public static void main(String[] args) { String[] arr = (String[]) Array.newInstance(String.class, 3); // creates a new array Array.set(arr, 0, "A"); Array.set(arr, 1, "B"); Array.set(arr, 2, "C"); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
5K+ Views
In order to determine if an object is an Object is an array in Java, we use the isArray() and getClass() methods.The isArray() method checks whether the passed argument is an array. It returns a boolean value, either true or falseSyntax - The isArray() method has the following syntax -Array.isArray(obj)The getClass() method method returns the runtime class of an object. The getClass() method is a part of the java.lang.Object class.Declaration − The java.lang.Object.getClass() method is declared as follows −public final Class getClass()The getClass() method acts as the intermediate method which returns an runtime class of the object, which enables the terminal ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
298 Views
One of the methods of the Timer class is void scheduleAtFixedRate(TimerTask task, long delay, long period). This method schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.In fixed-rate execution, each execution is scheduled with respect to the scheduled run time of the initial execution. Fixed-rate execution is apt for repetitive activities that are respond to absolute time. Likewise, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain in sync.Declaration − The java.util.Time.scheduleAtFixedRate(TimerTask task, long delay, long period) method is declared as follows −public void scheduleAtFixedRate(TimerTask task, long delay, long period)Here, task is ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
1K+ Views
In order to get Array Dimensions in Java, we use the getClass(), isArray() and getComponentType() methods with decision making in combination with iterative statements.The getClass() method method returns the runtime class of an object. The getClass() method is a part of the java.lang.Object class.Declaration − The java.lang.Object.getClass() method is declared as follows −public final Class getClass()The isArray() method checks whether the passed argument is an array. It returns a boolean value, either true or falseSyntax - The isArray() method has the following syntaxArray.isArray(obj)The getComponentType() method returns the Class denoting the component type of an array. If the class is not an ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
469 Views
In order to get the array upperbound of a multidimensional array, we use the length() method. For a 2D array, the length() method returns the number of rows. We can access the number of columns using the array_name[0].length method.Let us see a program to get the array upperbound in Java Multidimensional arraysExample Live Demopublic class Example { public static void main(String args[]) { String[][] str = new String[5][10]; System.out.println("1st dimension : " + str.length); // displays the number of rows System.out.println("2nd dimension : " + str[0].length); // displays the number of columns } }Output1st dimension : 5 2nd dimension : 10
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
139 Views
In order to create and demonstrate an immutable collection in Java, we use the unmodifiableCollection() method. This method returns an unmodifiable and immutable view of the collection.Declaration − The java.util.Collections.unmodifiableCollection() method is declared as follows -public static Collection unmodifiableCollection(Collection
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
360 Views
In order to sort items of an ArrayList with Collections.reverseOrder() in Java, we need to use the Collections.reverseOrder() method which returns a comparator which gives the reverse of the natural ordering on a collection of objects that implement the Comparable interface.Declaration − The java.util.Collections.reverseOrder() method is declared as follows -public static Comparator reverseOrder()Let us see a program to sort an ArrayList with Collections.reverseOrder() in Java -Example Live Demoimport java.util.*; public class Example { public static void main (String[] args) { ArrayList list = new ArrayList(); list.add(10); list.add(50); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
305 Views
To rotate elements of a collection in Java, we use the Collections.rotate() method. The rotate method rotates the elements specified in the list by a specified distance. When this method is invoked, the element at index x will be the element previously at index (x - distance) mod list.size(), for all values of i between 0 and list.size()-1, inclusive.Declaration − The java.util.Collections.rotate() is declared as follows -public static void rotate(List list, int distance)Let us see a program to rotate elements of a collection in Java -Example Live Demoimport java.util.*; public class Example { public static void main(String[] args) { ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
234 Views
Elements can be filled in a long array using the java.util.Arrays.fill() method. This method assigns the required long value to the long 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 { long[] longArray = new long[5]; long longValue = 125; Arrays.fill(longArray, longValue); System.out.println("The long array content is: " + Arrays.toString(longArray)); ... Read More