Search the courses, subjects, tracks, games and features, or jump straight to a page.
5 cards from this section. Quick, good the night before a test.
Choose the most suitable primitive type for each value: (a) the number of students in a class, (b) whether a shop is open, (c) the grade letter on a report card, (d) the average temperature of a week, such as 31.6.
First decide the family (whole number, decimal, single character or true/false), then pick the usual type in that family.
The line float price = 49.99; does not compile. Explain why, then fix it.
What type does Java give to a decimal number written directly in code?
How many primitive data types does Java have?
Count four whole-number types, two decimal types, one character type and one logical type.
Which declaration compiles without an error?
Compare each literal's default type with the type of its variable.
Write a program that stores a student's profile using the most suitable primitive type for each field: roll number, age, section letter, percentage, whether the student passed, a 10-digit mobile number and the year of admission. Print every field, then explain why the mobile number cannot be stored in an int.
Compare the largest int with a typical 10-digit mobile number.
A sensor logs one million readings. Write a program that calculates how many bytes one million values take as byte, short, int, long, float, double and char, using the BYTES constant of each wrapper class (for example Integer.BYTES). Then decide which type you would use for readings that are (a) whole numbers from 0 to 100 and (b) temperatures such as 36.6.
Size in bytes multiplied by the number of values gives the total; then check whether the smaller types can hold the values you need.
6 more questions in this section. Enroll free to practise them all.
Enroll free