Arraylist vs LinkedList vs Vector in java

All ArrayList LinkedList, and Vectors implement the List interface. Both (ArrayList and Vectors) use dynamically resizable arrays as their internal data structure. Whereas both ArrayList and Linked List are non synchronized. But they have several differences also, let us discuss ArrayList, LinkedList and Vectors in details with examples and differences. Collection Interface   ArrayList: ArrayList … Read more

Can we make the user thread as daemon thread if thread is started?

No, if we make the user thread as daemon thread if thread is started, it will throw IllegalThreadStateException. Java interview questions on multithreading What is multithreading? Difference between process and thread in java? What is thread in java? What is the difference between preemptive scheduling and time slicing? What is join method in java? What … Read more

Thread Java

Multithreading: Multithreading refers to a type of multitasking based upon threads. Context switching in case of multi-threading is done in-between threads instead of processes. Thread: A thread is used to execute multiple activities or tasks with-in a single process. It refers to a lightweight process. Thread uses process’s memory area i.e. execution environment. Multiple threads … Read more

Process vs Thread java

Multiprocessing: Multiprocessing represents a type of multitasking which is based upon processes. Context switching in Multiprocessing, is done in-between processes. For example: Listening music, downloading file, Typing in notepad etc from internet at the same time. You can clearly identify that all applications like music software, notepad etc are independent. Multiprocessing is handled at OS … Read more

Jagged arrays in java

Jagged arrays are also known as ragged arrays. They are the arrays containing arrays of different length. Consider the below example in which each row consists of different number of elements. First row contains 4 elements, second row contains 2 elements and third row contains 3 elements. Example package com.w3schools;   import java.util.Arrays;   public … Read more

difference between array and arraylist in java?

Array ArrayList Array objects are of fixed length. ArrayList objects are of variable length. Array does not support generics. ArrayList supports generics. Array can store both primitive types as well as reference types. ArrayList can store only reference types. Length of the Array is provided by the length variable. Length of the ArrayList is provided … Read more

Anonymous Array in java

An array without any name is anonymous array in java. They are mainly created for one time use only. Note: Anonymous arrays can be passed as an argument of a method. Syntax: Anonymous Int Array new int[] { 15, 25, 23, 45, 34}; Syntax: Anonymous Char Array new char[] {‘a’, ‘b’, ‘c’, ‘d’); Syntax: Anonymous … Read more

Change array size in java

No, we cannot change array size in java after defining. Note: The only way to change the array size is to create a new array and then populate or copy the values of existing array into new array or we can use ArrayList instead of array. Example: Custom Approach public class Main { public static … Read more

ArrayStoreException in java

ArrayStoreException is a run time exception which is thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects. Class Hierarchy of ArrayStoreException: java.lang.Object ↳ java.lang.Throwable ↳ java.lang.Exception ↳ java.lang.RuntimeException ↳ java.lang.ArrayStoreException Constructors of ArrayStoreException: public ArrayStoreException() It is used to construct an ArrayStoreException with … Read more

Call string class methods using string literals

Yes, we can call string class methods using string literals. Example package com.w3schools;   public class Test { public static void main(String args[]){ System.out.println("w3schools".charAt(3)); System.out.println("w3schools".indexOf(’i’)); } }package com.w3schools; public class Test { public static void main(String args[]){ System.out.println("w3schools".charAt(3)); System.out.println("w3schools".indexOf(‘i’)); } } Output p 5p 5 Java interview questions on String Handling Why string objects are … Read more