can overloaded methods be synchronized?

Yes, overloaded methods can be synchronized in java. Note: But you will get mutual exclusive problem if all methods are synchronized and you are using same object to invoke them. So, instead of using synchronized keyword at method level, try to follow below approach. class LoggerTest { private final Object LOCK = new Object();   … Read more

which one is faster among string stringbuffer and stringbuilder?

StringBuilder is faster one among string, stringbuffer and stringbuilder. Example public class Main { long startTime = 0l; long endTime = 0l; long timeDiff = 0l; // Concatenates to String public void concat1(String website) { startTime = System.nanoTime(); website = website + ".com"; endTime = System.nanoTime(); timeDiff = endTime – startTime; System.out.println("Time taken by String: … Read more

can you declare an interface method static in java?

No, we cannot declare interface methods as static because static methods can not be overridden. Example interface Test1 { static void show(); }   public class Main { void show(){ System.out.println("Implmented method."); }   public static void main(String[] args) { Main object = new Main(); object.show(); } }interface Test1 { static void show(); } public … Read more

Priority of garbage collector thread

Priority of Garbage Collector thread will be low. This is because of reason that the process of GC running is expensive, so rather than interrupt critical tasks it should only be done when the system has time to do. It is worked on the real time concept that is “do the unimportant task in the … Read more

can array size be negative in java?

No, array size cannot be negative. If we specify array size as negative, there will be no compile time error. But there will be run time NegativeArraySizeException. Example class Main { public static void main(String[] args) {   int[] testArray = new int[4];   for (int i = 0; i < testArray.length; ++i) { System.out.println(testArray[i]); … Read more

Is “abc” a primitive value?

No, “abc” is not a primitive value. It is a string object. Example public class Main{ void show(){ System.out.println("abc".getClass().getName()); } public static void main(String args[]){ Main obj=new Main(); obj.show(); } }public class Main{ void show(){ System.out.println("abc".getClass().getName()); } public static void main(String args[]){ Main obj=new Main(); obj.show(); } } Output java.lang.Stringjava.lang.String