What is the difference between synchronized block and synchronized method ? ,Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher
What is the difference between synchronized block and synchronized method ?

Both the synchronized method and block are used to acquires the lock for an object. When you mark a method synchronized, then you are forcing every thread which calls that method to lock the monitor. If you expect a synchronized() {} block in the calling code, it is possible that some code which calls your method might neglect to
use synchronized() and end up with a threading problem in your program. synchronized code always use objects as locks to prevent other threads from entering the synchronized block. For instance methods, they are synchronized on the \'this\' reference, and for static methods they are synchronized on the instance of the Class object method belongs to. Best practice is to minimize the code inside synchronized blocks because they prevent concurrent threads from executing - losing any advantage of multi-threaded applications. Synchronized blocks help let those portions of a method that do not access shared resources to be run simultaneously while still keeping those parts that need to be shared thread-safe.

More interview questions and answers
What are different normalization forms?
What is normalization?
What are transient variables in java?
How Observer and Observable are used?
What is Stored Procedure
What is Trigger?
What is View?
What is Index?
What is List interface ?
What is SQL?
What is the difference between yield() and sleep()?
Can we call finalize() method ?
What is the initial state of a thread when it is created and started?
Can we declare an anonymous class as both extending a class and implementing an interface?
What are the components of physical database structure of Oracle database?
What are the components of logical database structure of Oracle database?
What is the differences between boolean & operator and && operator?
What is a tablespace?
What is SYSTEM tablespace and when is it created?
Explain the relationship among database, tablespace and data file.
What is an abstract method ?
What is schema?
What are Schema Objects?
what is a the difference between System.err and System.out
Can objects of the same schema reside in different table spaces?
Can a tablespace hold objects from different schemes?
What is Oracle table?
What is an Oracle view?
What is the difference between synchronized block and synchronized method ?
Do a view contain data?
How can you force garbage collection in java?
How can you call a constructor from another constructor ?
How can you call the constructor of super class ?
What must be the order of catch blocks when catching more than one exception?
How can we call a method or variable of the super class from child class ?
If you are overriding equals() method of a class, what other methods you might need to override ?
What is externalizable ?
Does garbage collection guarantee that a program will not run out of memory?
What is a native method?
What is the difference between a continue statement and a break statement?
What must a class do to implement an interface?
What is the difference between notifyand notifyAll method ?
What does wait method do ?
What are the different states of a thread ?
What is the difference between static and non static inner class ?
What is the difference between readers and streams?
Why we cannot override static methods?
When does a compiler supplies a default constructor for a class?
What will happen if an exception is not caught ?
What are the different ways in which a thread can enter into waiting state?
What is a ResourceBundle class?
What is numeric promotion?
What is the difference between the prefix and postfix forms of the ++ operator?
What is the difference between a switch statement and an if statement?
What is hashCode?
What is the difference between RandomAccessFile and File?
What is the difference among JVM Spec, JVM Implementation, JVM Runtime ?
What is the difference between Hashtable and HashMap ?
Why java is said to be pass-by-value ?
What do you mean by immutable ? How to create an immutable object ?
What is a weak reference ?
What is object cloning?
What is object pooling?
What is the disadvantage of garbage collection?
What are tag interfaces?
What are the restrictions placed on static method ?
What is JIT?
What is the Locale class?
What is the difference between URL and URLConnection?
What are the two important TCP Socket classes?
Strings are immutable. But String s=\"Hello\"; String s1=s+\"World\" returns HelloWorld how ?
What is classpath?
What is path?
What is java collections?
Can we compile a java program without main?
What is static initializer block? What is its use?
How does a try statement determine which catch clause should be used to handle an exception?
If a class doesn\'t have any constructors, what will happen?
What will happen if a thread cannot acquire a lock on an object?
What will happen if you are invoking a thread's interrupt method while the thread is waiting or sleeping?
What is coupling?
How will you define an interface?
How will you define an abstract class?
What is a JVM heap?
What is daemon thread?
What is a green thread?
What is volatile variable?
What is diamond problem?
How many JVM's we can run in a system?
Why ArrayList is faster than Vector?
What is the security mechnaism used in java?
What is phantom memory?
What is reflection?
What are the differences between JIT and HotSpot?
How would you implement a thread pool?
What is the difference between throw and throws clause?
What is the difference between Comparable and Comparator ?
What is the difference between List, Set and Map?
What is the difference between Exception and Error ?
What is meant by Open Source ?