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 providesDate
class
- e.g.
- types -
boolean
size is not specified, depends on JVMbyte 8 bit -128 127 short 16 bit -32,768 32,767 int 32 bit -2,147,483,648 2,147,483,647 long 64 bit -2^63 2^63 - 1 float 32 bit n/a double 64 bit n/a char 16 bit 0 65,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
- correct:
- 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;
- e.g.
- you can declare array in two ways:
int[] arrayName
orint arrayName[]
var var = "var"
is allowed becausevar
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
tolong
orbyte
toshort
then we don’t need cast.short
tochar
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 ofString
, notStringBuilder
This post is licensed under CC BY 4.0 by the author.