These ten questions update floating-point guidance and distinguish arguments, parameters, variable-arity calls, and object construction.
Answer: It is a legacy modifier that no longer changes floating-point evaluation. Since Java 17, floating-point expressions are always evaluated with strict semantics. Older advice to add strictfp to avoid extended-exponent intermediate results does not describe a choice available in Java SE 25.
Strict evaluation does not make binary floating-point arithmetic exact decimal arithmetic: values such as 0.1 still generally require rounding. It also does not promise that every numerical algorithm or library function has identical results regardless of evaluation order. Use appropriate algorithms and types, such as BigDecimal for specified decimal arithmetic, rather than adding an obsolete modifier.
Answer: It remains accepted on eligible class, interface, and implemented method declarations. It cannot modify a variable or constructor and cannot be combined with abstract or native on a method. In Java SE 25 it is unnecessary and javac warns about its use.
Legal syntax and useful modern practice are different questions. When reading old source, recognize the modifier's historical role. For new Java 25 source, omit it; removing it does not weaken the language's current floating-point evaluation rules.
Answer: A variable-arity parameter lets callers supply zero or more compatible arguments, which the method receives as an array. The declaration uses an ellipsis, such as int... numbers. A caller may also supply an existing int array instead of individual values.
Varargs is call-site convenience, not a new collection type. The method can inspect the array's length and elements. Passing an existing array means the method can observe or mutate that array unless its own contract prevents mutation. Generic varargs can introduce heap-pollution warnings and require additional care.
Answer: They are arguments. In getSalary(name, age), the two argument expressions are evaluated and their values are passed to the method's parameters. Java evaluates argument expressions from left to right.
Java passes values, including reference values, by value. Reassigning a reference parameter does not change the caller's variable, although modifying the shared referenced object can be visible to the caller. Avoid surprising side effects in argument expressions, which can make evaluation order difficult to follow.
Answer: They are formal parameters. In int add(int left, int right), left and right are parameter variables; calls supply their initial values through arguments. Parameter types determine which arguments are accepted, subject to method-invocation conversions.
A method signature includes its name, type parameters where applicable, and formal parameter types. Parameter names and the return type do not independently distinguish overloads. Consequently, two methods cannot be overloaded merely by changing a parameter's name or changing only the return type.
Answer: It must be last, and a method or constructor can have at most one variable-arity parameter. Ordinary fixed parameters may precede it. The ellipsis belongs between the component type and the parameter name.
public class VarargsSum {
static int sum(int... numbers) {
int total = 0;
for (int number : numbers) total += number;
return total;
}
public static void main(String[] args) {
System.out.println(sum());
System.out.println(sum(2, 3, 4));
System.out.println(sum(new int[] {5, 6}));
}
}
The output is 0, 9, and 11 on separate lines. The empty call supplies an empty array, not null. Passing a null array explicitly would make this implementation throw NullPointerException. Integer addition can overflow for sufficiently large inputs.
Answer: Ordinary class-instance creation with new invokes a constructor and the required constructor chain. This initializes one new object; calling a superclass constructor does not create a separate superclass object.
The broader statement about every object is inaccurate. Arrays are objects but do not use class constructors in that way, and mechanisms such as cloning and serialization have different construction rules. Java SE 25 also allows restricted constructor-prologue statements before an explicit this or super invocation; the old blanket rule that such an invocation must always be the first statement is outdated.
Answer: For an ordinary class that declares no constructors, the compiler implicitly declares a default constructor. In the usual top-level or static nested class case, it has no parameters and invokes the superclass's no-argument constructor. That invocation must be legal and accessible.
Declaring any constructor suppresses this ordinary default, even if the declared constructor takes arguments. A no-argument constructor you write yourself is not a compiler-provided default constructor. Records, enums, anonymous classes, and inner-class enclosing-instance requirements have specialized rules.
Answer: No, not even void. A declaration named after the class with a return type is an ordinary method rather than a constructor. The new expression produces the reference to the newly created object; the constructor itself does not declare an object return value.
A constructor can use a bare return statement to complete normally when allowed by control flow, but cannot return an expression. Its role is initialization, and failure can be signaled by an exception. Do not confuse constructor syntax with factory methods, which do have return types.
Answer: Ordinary class constructors can be public, protected, private, or package-access. Package access uses no keyword. Constructors can also have parameters, including a final varargs parameter, and can be overloaded.
Constructor access controls who can request that construction path. Private constructors support class-controlled factories; protected constructors can support subclassing. Specialized declarations add restrictions: enum constructors cannot be public or protected, and a record's canonical constructor has rules tied to the record's accessibility.
References: Methods and constructors, Floating-point expressions, and Flexible constructor bodies.