Java Language Concepts Flashcards
What is the purpose of the main method of a class?
The main method is like the entry point into the application.
It is the first method to be executed in an application
You can call other methods from the main method to execute them.
What is a ‘method signature’?
A method signature consists of the method name and a parameter list.
methodName(int x, int y)
What is a method?
a method is a block of code that performs certain actions when it is called.
You can pass data, known as parameters, into a method.
Methods are also known as functions.
The major benefit of methods is the ability to reuse code.
What are the rules for writing a construct?
1) Constructors of a class must have the same name as the class name in which it resides.
2) A constructor in Java cannot be abstract, final, static or synchronized.
3) Access modifiers can be used in a constructor declaration to control its access.
How are constructors different from methods in Java?
Constructors must have the same name as the class.
Constructors do not have a ‘return type’ or return any value.
Constructors are called only once at the time of object creation, methods can only be called any number of times.
What are the (3) different types of constructors?
Default Constructor.
No Arg Constructor.
Parameterized Constructor.
What is a default constructor?
A default constructor inserted by Java compiler during compilation, with no parameters (arguments) or code in the body.
What is a No-Arg constructor?
A No-Arg constructor is explicitly coded with no parameters (arguments) but the body can contain code.
What is a parameterized constructor?
A parameterized constructor is explicitly coded with parameters (arguments). There is no limit on the number of parameters.
What are constructors?
Constructors are blocks of code within a class that initialize newly created objects.
Can be used to assign values to the class variables at the time of object creation.
What is a return type and how does it work?
You declare a method’s ‘return type’ in its method declaration. Within the body of the method, you use the ‘return’ statement to return the value.
The data type of the return value must match the method’s declared return type.
Any modified declared ‘void’ doesn’t return a value and it does not need to contain a reutrn statement.
What are operators?
Operators are used to perform operations on variables and values.
The value is called an operand, while the operation (to be performed by the two operators) is defined by an operator.
What are the 4 categories of operators?
Arithmetic operators: used to perform common mathematical operations.
Assignment operators: used to assign values to variables.
Comparison operators: used to compare two values.
Logical operators: Determine the logic between variables or values.
What are Reference Data Types?
When declaring a variable as a string, the variable name is the reference, the values in quotes is the object that Java then stores in a ‘constant pool’.
Any other string variables with the same values in quotes will refer to the same object in the ‘constant pool’.
What is the purpose of “this” keyword in a method?
When placed in front of a variable within a method, “this” keyword refers to the globally declared member/class variable.
Used for distinguishing between a local variable and global variable of the same name.