CSC105 Individual Greenfoot Java Questions - Panusin/Dedo GitHub Wiki
1.Why Java called the “Platform Independent Programming Language”?
Ans. Because java can run on any machine or different systems which in java code have source code that translate to byte code so this is common for all machine to be read. For the easy comment it means “write once run anywhere”
2.What is the difference between JDK and JRE?
Ans. JRE (Java Runtime Environment) contains class libraries without development tools such as compiler and JDK (Java Development Kit) is a superset of JRE and contains everything in the JRE plus development tools such as the compiler.
3.What are the primitive data types supported by Java? What is “Auto boxing and Unboxing”? Ans. The primitive data types have 8 types are -Boolean -Char -Byte -Short -Int -Long -Float -Double
Auto boxing is the automatic conversion that means we use primitive data types to specify objects to that type. For example, convert an int to an Integer
Int number = 239;
Unboxing is the opposite of Auto boxing by convert the object that already initialize back to its primitive type.
For example Int number = 239; int n = number;
4.What does the “static” keyword as seen in “public static void main(String[] args)” mean?
Ans. So Public static void main(String[] args) is a method that we can call without create an instance class. And this method will also call by Java JVM.
5.Why can’t you access “non-static variables” in the “static” context?
Ans. Because static variables or method is created every times that class is loaded so a non-static variables or methods is always defines only when the class is created.
-
What is a constructor? What does a “default constructor” look like?
Ans. A constructor is an instance method normally declare as the same name of the class and can be used for define the values or objects or make it default in side. This is what Default constructor look like Ex. Public class Panusin{ Public Panusin(){ //default constructor } }
7.What is the difference between String s1 = new String(“CSC105”); and String s2 = “CSC105”;?
Ans. when we created s1 it means we created an instance new String variable but when we created s2 java will look for instance that already defined and if we create String s3 = “CSC105”; like s2 so that mean s2 and s3 they are the same variable but both s2 and s3 not the same variable as s1.
8.What is the difference between the “==” operator and the “equals” method?
Ans.”==” this operator use for compare objects by using the location but “equals” method can be used by compare values in the objects and used for compare only String type.
9.What is the difference between the “String”, “StringBuilder”, and “StringBuffer” classes?
Ans. StringBuilder is the same as StringBuffer but it is faster because it allow only one tread to access at that time. Plus we can edited it any times without create a new object. For StringBuffer it allow any treads to be used and when we created it. Then, when we edited it, StringBuffer will create a new objects in the same name instead.
10.What is the difference between the “final” keyword and the “finally” keyword?
Ans. final keyword is use for the reason to define variables that not can be changed. And the finally keyword is use for what aver the program is error or not the statement with this keyword must be executed. And normally it’s used at the end of try-catch.
11.What are Java’s “enum” classes?
Ans. An enum is a special type that any variable to be a set of it. And anything can be enum types because enum types can represents a fixed set of constants.
-
What are the basic “Interfaces” of the Java Collections Framework (JCF)?
Ans. Interface is a group of related methods with empty bodies and objects that defined connect to the outside world with the methods that already exist.