
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 33676 Articles for Programming

4K+ Views
The byte array in Java can be filled by using the method java.util.Arrays.fill(). This method assigns the required byte value to the byte array in Java. The two parameters required for java.util.Arrays.fill() 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[] a) { byte arr[] = new byte[] {5, 1, 9, 2, 6}; System.out.print("Byte array elements are: "); for (int num : arr) { ... Read More

624 Views
To compute the elapsed time of an operation in milliseconds in Java, we use the System.currentTimeMillis() method. The java.lang.System.currentTimeMillis() returns the current time in milliseconds.Declaration −The java.lang.System.currentTimeMillis() is declared as follows −public static long currentTimeMillis()The method returns time difference in milliseconds between the current time and midnight, January 1, 1970 (UTC or epoch time).Let us see a program to compute the elapsed time of an operation in milliseconds in Java −Example Live Demopublic class Example { public static void main(String[] args) throws Exception { // finding the time before the operation is executed long ... Read More

176 Views
Two byte arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order. A program that compares two byte arrays using the Arrays.equals() method is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { boolean flag = Arrays.equals(new byte[] { 1, 7, 5 }, new byte[] { 1, 7, 5 }); System.out.println("The two byte arrays are ... Read More

350 Views
A multi-dimensional array can be easily printed using java.util.Arrays.deepToString() in Java. This method converts the multi-dimensional array to string and prints the array contents enclosed in square brackets. What Are Multi-Dimensional Arrays? Multi-dimensional arrays allow you to store data in a matrix-like structure, providing a way to represent tables, grids, or more complex hierarchical data. The most common type is a two-dimensional array, but Java supports arrays with more than two dimensions. int[][] array = new int[rows][columns]; Using Naive Approach The Arrays.deepToString(arr) method from the Arrays class ... Read More

400 Views
An array can be sorted in case-sensitive order using the java.util.Arrays.sort() method. Only a single argument required in this case for this method i.e. the array to be sorted. A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String args[]) { String[] arr = new String[] { "apple", "mango", "Banana", "Melon", "orange" }; System.out.print("The unsorted array is: "); System.out.println(Arrays.toString(arr)); Arrays.sort(arr); System.out.print("The sorted array in case-sensitive order is: "); System.out.println(Arrays.toString(arr)); } ... Read More

339 Views
A byte array can be sorted using the java.util.Arrays.sort() method with a single argument required i.e. the array to be sorted. A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] args) { byte[] arr = new byte[] { 4, 1, 9, 7, 5}; System.out.print("The original byte array is: "); for (byte i: arr) { System.out.print(i + " "); } Arrays.sort(arr); System.out.print("The sorted byte array is: "); ... Read More

8K+ Views
The list of all declared fields can be obtained using the java.lang.Class.getDeclaredFields() method as it returns an array of field objects. 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 −Example Live Demoimport java.lang.reflect.*; public class Demo { public static void main(String[] argv) throws Exception { Class ... Read More

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 −Example Live Demopackage Test; import java.lang.reflect.*; public class Demo { int i; char c; public Demo(int i, char c) { this.i = i; ... Read More

1K+ Views
The method java.lang.Class.getDeclaredConstructor() can be used to obtain the constructor object for the private constructor of the class. The parameter for this method is a Class object array that contains the formal parameter types of the constructor.A program that demonstrates this is given as follows −Example Live Demopackage Test; import java.lang.reflect.*; public class Demo { String str; Double d; public Demo(String str, Double d) { this.str = str; this.d = d; } public static void main(String[] args) { try { Demo obj = ... Read More

2K+ Views
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 −Example Live Demoimport java.lang.*; ... Read More