gs gs128 Java Autoboxing - Java Coding Best Practices - Quiz No.1
gs gs128 Java Quiz
This quiz belongs to book/course code gs gs128 Java of gs organization. We have 136 quizzes available related to the book/course Java. This quiz has a total of 10 multiple choice questions (MCQs) to prepare and belongs to topic Java Autoboxing. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
Question 1: What should the return type of method where there is no return value?
Null
Empty collection
Singleton collection
Empty String
Question 2: What data structure should be used when number of elements is fixed?
Array
Array list
Vector
Set
Question 4: Which of the following is good coding practice to determine oddity?
i)
i)
public boolen abc(int num) { return num % 2 == 1; }
ii)
public boolean xyz(int num) { return (num & 1)!= 0; }
i
ii
(i) causes compilation error
(ii) causes compilation error
Question 5: Which one of the following causes memory leak?
Release database connection when querying is complete
Use Finally block as much as possible
Release instances stored in static tables
Not using Finally block often
Question 6: Which of the following is a best practice to measure time taken by a process for execution?
System.currentTimeMillis()
System.nanoTime()
System.getCurrentTime()
System.getProcessingTime()
Question 7: What one of the following is best practice to handle Null Pointer exception?
i) int noOfStudents = line.listStudents().count;
ii) int noOfStudents = getCountOfStudents(line);
i) int noOfStudents = line.listStudents().count;
ii) int noOfStudents = getCountOfStudents(line);
public int getCountOfStudents(List line) { if(line != null) { if(line.listOfStudents() != null) { return line.listOfStudents().size(); } } throw new NullPointerException("List is empty"); }
Option (i)
Option (ii)
Compilation Error
Option (ii) gives incorrect result
Question 8: Which of the below is true about java class structure?
The class name should start with lowercase
The class should have thousands of lines of code
The class should only contain those attribute and functionality which it should; hence keeping it short
The class attributes and methods should be public
Question 9: Which of the below is false about java coding?
variable names should be short
variable names should be such that they avoid ambiguity
test case method names should be created as english sentences without spaces
class constants should be used when we want to share data between class methods
Question 10: Which is better in terms of performance for iterating an array?
for(int i=0; i<100; i++)
for(int i=99; i>=0; i–)
for(int i=100; i<0; i++)
for(int i=99; i>0; i++)