Fundamentals Flashcards
What is a function?
A function is a block of code that performs a task.
What is the function main?
It is the entry point of our program.
What is a class?
Using a basic perspective, it is a container for one or more related functions, but using a more advance logic it is a blueprint that enable us to create objects.
What does classes are useful for?
They help us organize our code.
What is a method?
It is a function that is part of a class.
What is an access modifier?
It is a special keyword that determines if other classes and methods of the program can access these classes and methods.
Give me some examples of access modifiers.
Private and public.
What does PascalNamingConvention means?
It means that the first letter of every word should be uppercase.
What does camelNamingConvention means?
It means that the first letter of every word should be uppercase except the first word.
What type of naming convention we use for classes?
PascalNamingConvention
What type of naming convention we use for methods?
camelNamingConvention
What is a package used for?
It is used to group related classes.
What do we use to comment our code?
Two slashes //
What type of quotes should we use with textual data?
We should use double quotes.
What is a String?
A sequence of characters.
What are variables used for?
They are used to temporarily store data on the computer’s memory.
What is an identifier?
Is the name or label we give to our variables.
What other name we give to the equal sign?
Assignment operator.
What do we mean to initialize a variable?
To give the variable an initial value.
How many types we have in Java?
Two types: primitive types and non-primitive types also called reference types.
What do we store in primitive types?
Simple values.
What do we store in reference types?
Complex objects.
How many primitive types we have?
We have eight: byte, short, int, long, float, double, char, boolean.
Which primitives store whole numbers?
Byte, short, int and long.
Which primitives store decimal numbers?
Float and double.
What does the char primitive type represents?
Represents one character like ‘A’ or ‘B’.
Mention a best practice when declaring variables.
Always use meaningful descriptive names.
What can you do in Java whenever you deal with a large number?
You can use an underscore to separate every three digits: 100_000.
What should we do to resolve errors shown in the code editor when using long and float types of variables?
We simply add an L at the end of the long number before closing with a semicolon, and an F at the end of a float number before closing with a semicolon.
List the number of bytes for each primitive type.
Byte = 1, short = 2, int = 4, long = 8, float = 4, double = 8, char = 2, boolean = 1.
What type of quotes should we use with a single character?
We should use single quotes.
What does the words coded in the color orange inside our code editor means?
They mean they are reserved words in Java.
What do we need to do in order to use a class from a different package?
We need to import that package.
What does the new operator do?
It allocates memory for the newly created variable.
What are the differences between primitive and reference types?
There are two differences, the first one is that reference types allocate memory whereas primitives don’t. The second difference is that primitives don’t have members (also methods).
What is an object?
An object is an instance (single ocurrence) of a class.
How can we access objects or classes?
We can access using the dot operator.
What does code snippets allow us to do?
They allow us to quickly generate code.
Give me an example of a code snippet.
Typing the word sout in the code editor will automatically produce the following: System.out.println( )
What are parameters?
They are the holes that we define in our methods.
What are arguments?
They are the actual values that we pass to the method.
What do we use escape sequence for?
We use it to type special characters without breaking our code.
How do we use escape sequences?
We type a backward slash: \
What is an array?
A list of items.
What do we add to create arrays?
We add square brackets [ ] in front of the variable:
int [ ] numbers = number [5];
What should we pay attention when creating arrays?
Our variable name should be in plural, since we are creating a list with multiple items.
What are exceptions in Java?
Exceptions are the way Java reports errors.
Mention one characteristic of arrays in Java.
They have a fixed size, so they have a fixed length, meaning that we cannot add or remove additional items to them.
When declaring a two-dimensional array, what does the first pair of brackets mean?
It means the number of rows.
When declaring a two-dimensional array, what does the second bracket means?
It means the number of columns.
How do we create a constant?
We type the reserved word final before the variable type:
final float PI = 3.1416F;
By convention, what do we do with the name of a constant?
We use all capital letters.
What is an expression?
It is a piece of code that produces a value.
Do we need to type the new operator when using abstract classes?
No
Give an example of an abstract class.
NumberFormat
What does factory method means?
It means calling a method of an abstract class, creating an instance and returning it.