Individual Greenfoot Java Questions - nongtiny/Individual-Project GitHub Wiki

  1. Why is Java called the “Platform Independent Programming Language”?

Answer : Because java has JVM that can read the .class file or byte code. Java need to compile so when it compiled the .class file will be generated by javac(java compiler) and the JVM can read those code that are compiled. When you install java it will automatically install JVM and every os(operating system) have its own JVM. So java language is platform independent.


  1. What is the difference between JDK and JRE?

Answer : JDK use to code a java language to create program or compile.(For development) JRE use to run a java program such as on browser or computer.(For running a java programs)


  1. What are the primitive data types supported by Java? What is “Autoboxing and Unboxing”?

Answer : Primitive data types supported by Java are byte,int,short,long,double,float,char,boolean.

     *Autoboxing is java converting primitive values into an object of the corresponding wrapper class ,such as int to Interger.
     *Unboxing is java converting an object of a wrapper type  to its corresponding primitive. It is an opposite of Autoboxing.
     Autoboxing and Unboxing work by Java compiler.

  1. What does the “static” keyword as seen in “public static void main(String[] args)” mean?

Answer : Static keyword in “public static void main(String[] args)" can be access only static variables which is outside the class by JVM. JVM provide a static variables from main().


  1. Why can’t you access “non-static variables” in the “static” context?

Answer : Because a static can access all member in the class but non-static variables can't ,so you have to change the non-static variables to static variables to make it work.


  1. What is a constructor? What does a “default constructor” look like?

Answer : Constructor is use to initialize the value for class fields. It's like a method and can be overloaded but the parameter must be different when you want a unique constructor.

     Default constructor look like this 

     public ClassName(){

     } 

     But we not necessary to write its because Java will automatically declare when you specify new keyword without passing parameters.

  1. What is the difference between String s1 = new String(“CSC105”); and String s2 = “CSC105”;?

Answer : s1 is a new string object and is created in the heap when its value re-declared by using new it will create another string object. s2 is store a value constant pool when its value re-declared by using = sign it will be the same object and same value.


  1. What is the difference between the “==” operator and the “equals” method?

Answer : == compare a reference, like a memory location of an object if it same it's true else false. .equals() compare the value of the objects if it same it's true else false.


  1. What is the difference between the “String”, “StringBuilder”, and “StringBuffer” classes?

Answer : String cannot be changed. It is an absolute class. StringBulider and StringBuffer is mutable class can be changed. That's all I know.


  1. What is the difference between the “final” keyword and the “finally” keyword?

Answer : final is a keyword. It is a constant value cannot be changed and cannot be overridden. finally is a block. Use to place a code that important whether exception is handle or not.


  1. What are Java’s “enum” classes?

Answer : It's a class that are constant variables by enum type that can enables variable to be set of predefined constants.


  1. What are the basic “Interfaces” of the Java Collections Framework (JCF)?

Answer : There are * java.util.Set * java.util.SortedSet * java.util.NavigableSet * java.util.Queue * java.util.concurrent.BlockingQueue * java.util.concurrent.TransferQueue * java.util.Deque * java.util.concurrent.BlockingDeque