Home > Java Programming > Quizzes > Java Basics Practice Test: Java Coding Best Practices
Java Basics Practice Test: Java Coding Best Practices
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 0% Most missed: “Which of the below is true about java class structure?”
Here are some of the best practices for Java coding: Create a proper project structure.: This will help you keep your code organized and easy to find. Use proper naming conventions.: This will make your code more readable and easier to understand. Avoid creating unnecessary objects.: This can help improve the performance of your code. Create proper source file structure.: This will help you keep your code organized and easy to maintain. Comment on the code properly.: This will help you and others understand what the code is doing. Avoid too many parameters in any method.: This can make... Show more
Java Basics Practice Test: Java Coding Best Practices
Time left 00:00
10 Questions

1. Which of the following is good coding practice to determine oddity?

i)
public boolen abc(int num)
{
return num % 2 == 1;
}
ii)
public boolean xyz(int num)
{
return (num & 1)!= 0;
}
2. What one of the following is best practice to handle Null Pointer exception?

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");
}
3. Which one of the following causes memory leak?
4. Which of the below is false about java coding?
5. Which of the following is a best practice to measure time taken by a process for execution?
6. Which is better in terms of performance for iterating an array?
7. Which one of the following causes memory leak?
8. Which is better in terms of performance for iterating an array?
9. What one of the following is best practice to handle Null Pointer exception?

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");
}
10. What causes the program to exit abruptly and hence its usage should be minimalistic?