0% found this document useful (0 votes)
29 views1 page

Java Synchronized Code Will Only Be Executed by One Thread at A Time. in Summary, Java

Synchronization in Java ensures that only one thread can access shared resources at a time using the synchronized keyword. ArrayLists are not synchronized and faster than Vectors while Vectors are synchronized and slower. Throws declares exceptions a method may throw while throw actually throws an exception. Checked exceptions require exception handling code while unchecked exceptions do not. Static variables and methods can be used without an instance of the class and only require the class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Java Synchronized Code Will Only Be Executed by One Thread at A Time. in Summary, Java

Synchronization in Java ensures that only one thread can access shared resources at a time using the synchronized keyword. ArrayLists are not synchronized and faster than Vectors while Vectors are synchronized and slower. Throws declares exceptions a method may throw while throw actually throws an exception. Checked exceptions require exception handling code while unchecked exceptions do not. Static variables and methods can be used without an instance of the class and only require the class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

Synchronization in Java
Since java is a multithreaded language , multiple threads run concurrently to complete a program. So
synchronization is required in order to avoid any error in accessing of the shared resources. Java
synchronized code will only be executed by one thread at a time.  In Summary, Java
synchronized Keyword provides this functionality of locking and unlocking the objects

2. Difference between arraylist and vector


Arraylist is not synchronized and it is fast.
Since Array is an index based data-structure searching or getting element from Array with index is pretty

fast. Array provides O(1) performance for get(index) method but remove is costly in ArrayList as you need to

rearrange all elements. On the Other hand LinkedList doesn't provide Random or index based access and

you need to iterate over linked list to retrieve any element which is of order O(n).

3. Difference between Throws and Throw


Throws is the declaration of exception thrown by the method and Throw is actually throwing the exception.

4. What is difference between checked and unchecked Exception in Java.


checked Exception requires mandatory exception handling code while unchecked doesn't.

5. What is Static
Static variable and Methods can be used without having any instance of the Class. Only the
Class is required to invoke a static Method or static variable.

You might also like