LEARN, PRACTICE & EXCEL!
What is an algorithm? Answer: A finite, well-defined step-by-step procedure to solve a problem,
usually written before coding.
List the basic steps for writing an algorithm. Answer: Define the problem (inputs/outputs),
break into subproblems, identify steps for each subproblem, organize steps logically.
Give the algorithm steps to compute the area of a rectangle. Answer: 1) Declare variables, 2)
Get length, 3) Get width, 4) Compute area = length * width, 5) Print output.
What is the basic structure of a Java application class? Answer: public class ClassName { public
static void main(String[] args) { / code / } }
Explain the parts of 'public static void main(String[] args)'. Answer: public: access modifier;
static: belongs to class; void: returns nothing; main: entry method name; String[] args:
command-line args array.
How do you add algorithm steps into code as annotations? Answer: Use comments (// single-
line or / ... / block) to include algorithm steps and guide implementation.
What are the two floating-point types in Java and when to use each? Answer: float (32-bit
single precision) for memory saving in large arrays; double (64-bit double precision) as the
default for decimals and higher precision.
How do you declare multiple variables of the same type in one line? Answer: double length,
width, area;
How do you assign values to variables in Java? Answer: Use the assignment operator '='; e.g.,
length = 10;
How do you compute area from length and width in Java? Answer: area = length * width;
How do you print results to the console? Answer: System.out.println("The area for the
rectangle is " + area);
How do you read user input from the console using Scanner? Answer: Import java.util.Scanner;
create Scanner input = new Scanner(System.in); use input.nextDouble(), input.nextInt(), etc.
How do you import the Scanner class explicitly? Answer: import java.util.Scanner;
Why prefer explicit import over 'import java.util.*;'? Answer: Explicit import clarifies which
classes are used and avoids bringing in unnecessary classes.
APPHIA – Crafted with Care and Precision for Academic Excellence.
1
, What are identifiers in Java? Answer: Names for classes, methods, variables: sequences of
letters, digits, underscore (_), or dollar sign ($); cannot start with a digit; case-sensitive.
Is Java case-sensitive for identifiers? Answer: Yes: area, Area, and AREA are distinct identifiers.
What is a named constant and how do you declare one? Answer: A final variable that cannot
change. Example: final double PI = 3.14159;
What are Java naming conventions for variables, classes, and constants? Answer:
Variables/methods: camelCase. Classes: PascalCase. Constants:
ALL_CAPS_WITH_UNDERSCORES.
List Java's six primitive numeric types. Answer: byte, short, int, long, float, double.
What is the range and size of byte? Answer: 8-bit signed, range -128 to 127.
What is the range and size of short? Answer: 16-bit signed, range -32768 to 32767.
What is the range and size of int? Answer: 32-bit signed, range -2147483648 to 2147483647.
What is the range and size of long? Answer: 64-bit signed, very large range (approx -9.22e18 to
9.22e18).
What are the typical ranges for float and double? Answer: float: approx 1.4e-45 to 3.4e38 (32-
bit). double: approx 4.9e-324 to 1.8e308 (64-bit).
How do you read various primitive numeric types using Scanner? Answer: input.nextByte(),
.nextShort(), .nextInt(), .nextLong(), .nextFloat(), .nextDouble().
What arithmetic operators does Java provide? Answer: +, -, *, /, % (modulus)
What does the modulus operator (%) return? Answer: The remainder after integer division.
How to convert seconds into minutes and remaining seconds? Answer: minutes = seconds / 60;
remainingSeconds = seconds % 60;
How do you compute exponents in Java? Answer: Use Math.pow(base, exponent). Example:
Math.pow(2, 3) returns 8.0.
Name forms of numeric literals in Java. Answer: Decimal (100), octal (0144), hexadecimal
(0x64), binary (0b1100100), floating-point (3.14159).
State Java operator precedence for arithmetic. Answer: 1) Parentheses, 2)
Multiplication/Division/Modulus (left to right), 3) Addition/Subtraction (left to right).
What does augmented assignment mean? Give examples. Answer: Operators combining
arithmetic and assignment: i += 8 (i = i + 8), i = 8 (i = i 8), etc.
APPHIA – Crafted with Care and Precision for Academic Excellence.
2