About 222,000 results
Open links in new tab
  1. Does Java support default parameter values? - Stack Overflow

    In this sample we construct ParameterObject with default values and override them in class instance initialization section { param1 = 10; param2 = "bar";} Share Improve this answer

  2. java - how to set default method argument values ... - Stack …

    You can't declare default values for the parameters like C# (I believe) lets you, but you could simply just create an overload. public int doSomething(int arg1, int arg2) { //some logic here return 0; } //overload supplies default values of 1 and 2 public …

  3. Default values and initialization in Java - Stack Overflow

    Oct 2, 2013 · Default Values. It's not always necessary to assign a value when a field is declared. Fields that are declared but not initialized will be set to a reasonable default by the compiler. Generally speaking, this default will be zero or null, depending on the data type. Relying on such default values, however, is generally considered bad ...

  4. What are the default values for data types in Java? [duplicate]

    3 days ago · Default values for primitives in java: Data Type Default Value (for fields) byte 0 short 0 int 0 long 0L float 0.0f double 0.0d char '\u0000' boolean false

  5. java - How do I set default values for instance variables ... - Stack ...

    Apr 20, 2017 · You have two choices for setting the default value of an instance variable (sometimes called an "instance field"): Using an initializer on the declaration. Using an assignment in a constructor. Say I have a class Example and an instance variable answer whose default should be 42. I can either:

  6. Variable default value in Java - Stack Overflow

    Jan 7, 2021 · From the Java Language Specification, Java SE 8 Edition, 4.12.5 Initial Values of Variables: A local variable (§14.4, §14.14) must be explicitly given a value before it is used, by either initialization (§14.4) or assignment (§15.26), in a way that can be verified using the rules for definite assignment (§16 (Definite Assignment)).

  7. How is the default max Java heap size determined?

    Default values of heap size parameters on 64-bit systems have been scaled up by approximately 30%. This increase is meant to compensate for the larger size of objects on a 64-bit system. With these parameters, if the percent of free space in a generation falls below 40%, the generation will be expanded to maintain 40% free space, up to the ...

  8. java - Default values for record properties - Stack Overflow

    Jan 16, 2024 · If I have a Java record with 2 properties and I want to define default values for the properties which should be used instead of null. I can either override the getters: public record MyRecord(Set<

  9. java - Setting default values to null fields when mapping with …

    Via adding the @Builder.Default on the property you are then able to set default values. @Value @Builder @Jacksonized public class SomeClass { String field1; @Builder.Default String field2 = "default-value"; }

  10. Default initialization in java - Stack Overflow

    Apr 11, 2017 · For type long, the default value is zero, that is, 0L. For type float, the default value is positive zero, that is, 0.0f. For type double, the default value is positive zero, that is, 0.0d. For type char, the default value is the null character, that is, …

Refresh