Java-Primitive Types

Cards (22)

  • What types have been covered so far in the course?
    Primitive types
  • What are the primitive types in Java?
    Numeric (integer, floating-point, char, Boolean)
  • What are non-primitive types also known as?
    Composite types
  • What are the non-primitive types in Java?
    • Strings
    • Arrays
    • Objects
  • What are the properties of primitive types?
    They are built into the language, cannot be decomposed, and are not classes.
  • How do variables of primitive types store values?
    They hold the actual value, not a reference.
  • What are the properties of non-primitive types?
    They are not always built into the language, can be decomposed, and are classes.
  • How do variables of non-primitive types store values?
    They hold a reference to the value, not the actual value.
  • What is an array in Java?
    A collection of elements of the same type.
  • How is a String in Java defined?
    A String is made up of a sequence of characters.
  • How is the state represented in objects?
    State is represented as fields.
  • What is the difference in how primitive and non-primitive types store values?
    Primitive types store actual values, while non-primitive types store references to values.
  • How do you compare primitive types in Java?
    Using "==" and "!=" to compare values.
  • How do you compare non-primitive types in Java?
    Using "==" and "!=" compares memory locations, while values are compared using type-specific methods.
  • What will be printed if a=a =5.5 5.5 and b=b =5.5 5.5 are compared with "=="?

    Equal with ==
  • What will be printed if two String objects are compared with "=="?

    Equal with ==
  • What will be printed if two arrays are compared with "=="?

    Equal with ==
  • What happens to the parameter value when it is changed inside a method?
    Changing the value of a parameter inside the method doesn’t change its value externally.
  • Can you change the memory location of a non-primitive type parameter inside a method?
    No, you can’t change the memory location, but you can change the contents of that location.
  • What will happen to the array 'numbers' after calling doSomething(numbers)doSomething(numbers)?

    The array 'numbers' will remain unchanged.
  • What will happen to the array 'numbers' after calling doSomethingElse(numbers)doSomethingElse(numbers)?

    The second element of 'numbers' will be changed to 5.
  • What are the key differences between primitive and non-primitive types in Java?
    • Primitive types:
    • Store actual values
    • Built into the language
    • Cannot be decomposed
    • Not a class
    • Non-primitive types:
    • Store references to values
    • Not always built into the language
    • Can be decomposed
    • Are classes