Post

OCP 17 Exam - chapter 1 notes

Chapter 1 notes:

  • source file must have at most one public type
  • import that specifies class name takes precedence over import with * if there are two classes with the same name
    • e.g. java.util.Date vs. java.sql.*, which also provides Date class
  • types - boolean size is not specified, depends on JVM
    • byte8 bit-128127
    • short16 bit-32,76832,767
    • int32 bit-2,147,483,6482,147,483,647
    • long64 bit-2^632^63 - 1
    • float32 bitn/a
    • double64 bitn/a
    • char16 bit065,535
  • string text block - if you put ending """ in new line, it will result in blank line
    • \ - joins lines - line break is ignored
    • \s - add extra twi spaces at the end of line
  • underscore in number literals can be used only inside, we cannot start or end number with _ or use near .
    • correct: 1___1_1.1___1_1
  • variable name must start with letter, _, or currency symbol like $, , ¥
  • declaration of multiple variables in the same line is only possible for the same type, except var!
    • e.g. int v1 = 1, v2, v3 = 3;
  • you can declare array in two ways: int[] arrayName or int arrayName[]
  • var var = "var" is allowed because var is not reserved word, just reserved type!
  • curly braces can be used inside class or method and they define new scope
    • when used in class it is called
  • “identifying blocks and variable scope is second nature of the exam” ;)
  • object vs. references - “all references are the same size, but object can have different size”

Fundamentals exam notes from practise attempt:

  • cast: if we assign smaller type size to larger, e.g. int to long or byte to short then we don’t need cast.
    • short to char and vice-versa also needs a cast
  • functional interface must have exactly one abstract method and may have other default or static methods”
  • break w/o a label can occur only in a switch, while, do, or for statement”
  • interfaces allow multiple implementation inheritance through default methods” - Java doesn’t allow to extend from multiple classes
  • trim is method of String, not StringBuilder
This post is licensed under CC BY 4.0 by the author.