A: Definitions and Short Answers i. List the eight primitive data types in Java.
ID: 3589377 • Letter: A
Question
A: Definitions and Short Answers i. List the eight primitive data types in Java. ii. List the non-access modifiers we have seen in class. Describe what each are used for iii. Briefly describe the entire process of writing a Java program to running in it from the command line. (Be sure to explain what javac and java are and what they do.) iv. In a Java program, why does main need to be public? v. In a Java program, the main method is static. What would be the consequences if vi. Suppose you have a final array of numbers as an attribute. Explain why you can or vii. Give a concise definition of a method signature. What is the method signature of the Java did not require this? (i.e., how would you run a program?) cannot change the numbers in the array. main method of any program in Java? viii. What is the difference between a primitive data type and a reference data type in Java? ix. Briefly describe the difference between a class attribute and an instance attribute x. Briefly describe the difference between a class method and an instance method. xi. In the statement System.out.println ("hello, world!");, explain what System, out and println each are xii. Briefly describe the difference between the stack and the heap in our memory model xiii. Briefly describe the four sections of the memory model discussed in class: stack, heap, data segment, code segment xiv. What is "this" in Java? xv. Briefly describe the two uses of this in a constructor. xvi. Briefly describe what an activation record is and what it is used for. xvii. Java provides eight primitive wrapper classes. Explain what they are xviii. Strings are immutable in Java. What does this mean? xix. Can a Java class have no constructors? (Explain yes or no.) xx, Given String s = new String ( "cat"); and String t = "cat", draw the box & arrow diagram for these two variablesExplanation / Answer
Hi,
I could complete 10 out of 20 questions. Remaining questions can be posted in new question.
Ans i) Eight primitive data types-
byte
short
int
long
float
double
char
String
Ans ii) Below are the non-access modifiers-
The static modifier for creating class methods and variables.
The final modifier for finalizing the implementations of classes, methods, and variables.
The abstract modifier for creating abstract classes and methods.
The synchronized and volatile modifiers, which are used for threads
Ans iii) In order to write a Java program, we need to create a class first. In the next step we need to decalare the class data members and member functions.
At last, the class must have a main method which acts as a driver of the class and instantiates the class objects and often used for calling member functions of class.
To compile the java program, we need to save the program on the name of "class" name.java.
Lets assume we have a class named as Test then-
Compilation --> javac Test.java
Execution --> java Test
Ans iv) As Java program runs on top of Java virtual machine. Hence, JVM call the main method in order to run the method which is outside the scope of the project therefore the access specifier has to be public to permit a call from anywhere outside the application.
Ans v) Static methods can be called even though the class which contains those methods does not have any object. When the JVM makes a call to the main method there is no object that exists for the class being called therefore it has to have static method to allow invocation from class.
Ans vi) final is a scope modifier in java which tells the compiler that the value of the variable which is declared as final cannot be changed throughout the program.
Ans vii) Any function signatures includes the name of the function and the number of parameters that are passed in the function. The signature of "main" includes the string array args which is used to store the user parameters during the run time of thr program.
Ans viii) Primitive datatypes are pre-defined or built in data types that java offers to the programmersto define the data types for thr variables. Reference types are mostly designed to group primitive types together. So you can have group of int as list, group of char as string, class of the primitives etc.
Ans ix) Instance variables:
These variables belong to the instance of a class, thus an object. And every instance of that class (object) has it's own copy of that variable.
Class variables:
These are also known as static member variables and there's only one copy of that variable that is shared with all instances of that class
Ans x)
Instance method:
Instance methods require an instance of the class to exist before they can be called, so an instance of a class needs to be created by using the new keyword.
Class method:
Class methods are methods which are declared as static. The method can be called without creating an instance of the class.