- 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 4338 Articles for Java 8
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
1K+ Views
The volatile modifier indicates the JVM that the thread accessing a volatile variable should get data always from the memory. i.e. a thread should not cache the volatile variable.Accessing a volatile variable synchronizes all the cached copied of the variables in the main memory. Volatile can only be applied to instance variables, which are of type object or private. A volatile object reference can be null.Examplepublic class MyRunnable implements Runnable { private volatile boolean active; public void run() { active = true; while (active) { // line 1 ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
277 Views
An array is a data structure/container/object that stores a fixed-size sequential collection of elements of the same type. The size/length of the array is determined at the time of creation.The position of the elements in the array is called as index or subscript. The first element of the array is stored at the index 0 and, the second element is at the index 1 and so on.Creating an arrayIn Java, arrays are treated as referenced types you can create an array using the new keyword similar to objects and populate it using the indices as −int myArray[] = new int[7]; ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
7K+ Views
An array is a data structure/container/object that stores a fixed-size sequential collection of elements of the same type. The size/length of the array is determined at the time of creation.The position of the elements in the array is called as index or subscript. The first element of the array is stored at the index 0 and, the second element is at the index 1 and so on.Each element in an array is accessed using an expression which contains the name of the array followed by the index of the required element in square brackets.For example, if an array of 6 ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
10K+ Views
Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array.Element: Each item stored in an array is called an element.Index: Each location of an element in an array has a numerical index, which is used to identify the element.Storing Objects in an arrayYes, since objects are also considered as datatypes (reference) in Java, you can create an array of the type of a particular class ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
2K+ Views
Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array.Element − Each item stored in an array is called an element.Index: Each location of an element in an array has a numerical index, which is used to identify the element.The size of the array will be determined at the time of creation.Disadvantages of arraysDeleting or inserting − You cannot insert a new element at the ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
1K+ Views
To find continuous sub array whose sum is equal to a given number −Iterate through the array.At each element add the next n elements one by one, when the sum equals to the required value print the sub array.Exampleimport java.util.Arrays; import java.util.Scanner; public class sub_arrays { public static void main(String args[]){ //Reading the array from the user Scanner sc = new Scanner(System.in); System.out.println("Enter the size of the array that is to be created: "); int size = sc.nextInt(); int[] myArray = new int[size]; ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
2K+ Views
To separate zeros from non-zeros in an integer array, and push them to the end, you need to rearrange it array by assigning all the nonzero elements to its positions, sequentially, starting from zero. Then, from last position of the array to its end populate it with zeros.ExampleFollowing Java program pushes all the zeros in an array to its end.import java.util.Arrays; import java.util.Scanner; public class ZerosFromNonZeros { public static void main(String args[]){ //Reading the array from the user Scanner sc = new Scanner(System.in); System.out.println("Enter the size of the array that ... Read More
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
6K+ Views
To find all pairs of elements in Java array whose sum is equal to a given number −Add each element in the array to all the remaining elements (except itself).Verify if the sum is equal to the required number.If true, print their indices.Exampleimport java.util.Arrays; import java.util.Scanner; public class sample { public static void main(String args[]){ //Reading the array from the user Scanner sc = new Scanner(System.in); System.out.println("Enter the size of the array that is to be created: "); int size = sc.nextInt(); int[] myArray ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
859 Views
In Java, serialization is a concept using which we can write the state of an object into a byte stream so that we can transfer it over the network (using technologies like JPA and RMI).To serialize an object −Make sure the class implements the Serializable interface.Create a FileOutputStream object representing the file (abstract path) of the file to which the object is to be stored.Create a ObjectOutputStream object by passing the above created FileOutputStream object.Write the object to the file using the writeObject() method.To de-serialize an objectCreate a FileInputStream object representing the file that contains the serialized object.Read the object ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
837 Views
In Java, serialization is a concept using which we can write the state of an object into a byte stream so that we can transfer it over the network (using technologies like JPA and RMI).To serialize an object −Make sure the class implements the Serializable interface.Create a FileOutputStream object representing the file (abstract path) of the file to which the object is to be stored.Create a ObjectOutputStream object by passing the above created FileOutputStream object.Write the object to the file using the writeObject() method.To de-serialize an objectCreate a FileInputStream object representing the file that contains the serialized object.Read the object ... Read More