
Java MCQs on Syntax and Semantics

Quiz
•
Information Technology (IT)
•
University
•
Easy
Sáng Nguyễn
Used 1+ times
FREE Resource
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following correctly describes Syntax in Java?
The meaning of a syntactically correct program.
The structure of statements or elements in a programming language.
The algorithm used to check errors in a program.
The way objects are stored in memory.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is wrong with the following code? int[] arr = [1, 2, 3];
Syntax error
Semantic error
No error
Runtime error
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the semantic error in the following code? String a = new String("hello"); String b = new String("hello"); if (a == b) { System.out.println("Equal"); } else { System.out.println("Not Equal"); }
Syntax error because == cannot be used with String.
Semantic error because == compares references instead of string content.
No error, the program runs correctly.
Runtime error because a and b are not initialized.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
To identify syntax errors in Java, you need to:
Understand the program's algorithm.
Check the code against rules in The Java Language Specification.
Run the program and check the output.
Use knowledge of memory and resource management.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is wrong with the following code? int x = 10 System.out.println(x);
Syntax error due to missing semicolon.
Semantic error because x is not initialized.
Syntax error because System.out.println is invalid.
No error.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the semantic error in the following code? int sum = 0; for (int i = 1; i <= 5; i++) { sum = i; } System.out.println(sum);
Syntax error due to incorrect for loop format.
Semantic error because sum does not accumulate i values.
Runtime error because sum exceeds int limits.
No error.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
In Java, the {x} notation in grammar rules indicates:
Exactly one occurrence of x.
Zero or one occurrence of x.
Zero or more occurrences of x.
A sequence of x elements concatenated together.
Create a free account and access millions of resources
Similar Resources on Wayground
20 questions
Көп өлшемді массивтер туралы тест (Java)

Quiz
•
University
15 questions
Bài 26

Quiz
•
10th Grade - University
25 questions
THIRD ROUND BINGO

Quiz
•
University
25 questions
Google Sheets Midterm Quiz - 21/10/2024

Quiz
•
University
20 questions
HT - 13 Identifica principales aplicaciones

Quiz
•
University
21 questions
Q1_Web Systems

Quiz
•
University
15 questions
Dart Programming Quiz

Quiz
•
University
15 questions
Understanding Loops in C Programming

Quiz
•
1st Grade - University
Popular Resources on Wayground
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
10 questions
Ice Breaker Trivia: Food from Around the World

Quiz
•
3rd - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
20 questions
ELA Advisory Review

Quiz
•
7th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Multiplication and Division Unknowns

Quiz
•
3rd Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Information Technology (IT)
11 questions
NFL Football logos

Quiz
•
KG - Professional Dev...
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
36 questions
Unit 5 Key Terms

Quiz
•
11th Grade - University
38 questions
Unit 6 Key Terms

Quiz
•
11th Grade - University
20 questions
La Hora

Quiz
•
9th Grade - University
7 questions
Cell Transport

Interactive video
•
11th Grade - University
7 questions
What Is Narrative Writing?

Interactive video
•
4th Grade - University