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

can we declare local inner class as private?

No, local inner class cannot be declared as private or protected or public because local inner class is not associated with Object. Example of local inner class public class Main{ private String website="826.a00.myftpupload.com"; void show(){ class LocalInnerClass{ void display(){ System.out.println(website); } } LocalInnerClass localInnerClass = new LocalInnerClass(); localInnerClass.display(); } public static void main(String args[]){ Main … Read more

are true and false keywords in java?

No, true and false are not keywords in java. They are literals in java. As literals are reserved words in java so we cannot use them as identifiers in our program. Example public class Main { public static void main(String args[]){ int true = 10; String false = "jai"; } }public class Main { public … Read more