Java SE 8 Oracle Certified Associate Java Programmer I
What is an interface?
An interface only has a method signature and is a contract that provides how the class should look/behave like.
What is a Method in a class?
The behavior of objects.
What does an interface look like? How does a class implement an interface using (Car and Mustang)?
(1.) interface Car { void run(); void getFuel(); } (2.) public class fordMustang implements Car { int fuel; public void run(){ System.out.println("vroooom"); } int getFuel (){ return this.fuel; } }
Theoretically, a "Class" is:
A Design used to specify attributes and the behavior of an object.
What does a class constructor do?
A class constructor is creates and initializes the objects of a class!
What is a class in Java?
A class is a Blue Print (design) for Java objects. Allows for the creations of variables and functions (Fields and Methods) (States and Behaviors)
What is a field in Java?
A field is a state of an object (Similar to a variable)
What is a method in Java?
A method is the behavior of an object. (Similar to a function).
What is a protected access modifier?
A protected modifier cannot be applied to classes or interfaces. It is visible to the package and any other subclass that extend it.
What is a public access modifier in Java?
A public modifier is visible to the world.
What is a private modifier in Java?
A rivate modifier is only visible to the class
What is a static method in Java?
A static method doesn't need an object to call itself outside of its class. Non-static variables cannot be implemented inside of a static method.
How does abstraction work?
Abstraction is performed by using classes and interfaces. Where a parent class does not know what the implementation is for a child class.
What are the non mandatory (Optional) components of a class.
Access modifiers: Public Private Non access modifiers (Optional Specifiers): Final Keyword: "extends" that child classes must have to reference parent class Keyword: "implements" that class must have to reference interfaced class
What is an object in Java?
An Object is an element that has a state (variables/fields) and has behaviors (methods /functions).
How can an abstract class be used?
An abstract class can be used by creating an inheriting subclass that CAN be instantiated.
What is an abstract class?
An abstract class is a class that cannot be instantiated but can be extended.
What is an abstract method? What has to happen when an abstract method is extended?
An abstract method is a method that only has a method signature. When an abstract method is extended from a super-class, the method MUST be implemented.
What is the difference between an abstract class and an interface?
An interface only has a method signature and is a contract. All classes that implement this interface must implement all methods inside of the interface in order to use it. An abstract class is an actual class it is more expensive because it requires a look in order to use them. The class may have method implementations inside its body.
What is an Object in a class?
An object is an element (or instance) of a class AND it share the behaviors of the class (which are it's methods).
What is encapsulation?
Combining data and code into a single object. It is a technique used to hide information (Data Hiding).
What are the 3 things an Abstract class can do?
Define standard methods which can be used by the inheriting subclass. Define abstract methods which the inheriting subclass MUST implement. Can provide a common interface which allows the sub-class to be interchanged with all other sub-classes.
(True or False): A source code file can define more than one public class or interface.
False, only one public class is allowed per source code file!
Methods are similar to what type of JavaScript language?
Functions
What is method overloading?
If a class have multiple methods by SAME NAME but DIFFERENT PARAMETERS, it is known as Method Overloading. It increases the readability of the program. (Static Polymorphism)
What is inheritance?
Inheritance is when one object acquires all the properties and behavior of another object of another class. It represents IS-A relationship. It is used for Code Re-usability and Method Overriding.
Each Object has its own copy of what?
Instance Variables Instance Attributes
What is abstraction?
Is the process of hiding implementation details from the user .
What is polymorphism?
It is a way for an object to take on many forms.
What is method overriding and what is it used for?
It is when a subclass provides a specific implementation of a method that is ALREADY provided by its parent class. It is used for run-time POLYMORPHISM and to provide the specific implementation of the method in question. (Dynamic Polymorphism)
What is a static variable in Java?
Known as class variables. Only one copy of the static variable exists regardless of the number of objects (Instanced Classes).
What are the components of a Java class file?
Levels of components: 1. Package statement 2. import statements 3. Project Comments (Optional Element) 4. Declaration of the class --------Inside the class declarations-------- 5. Instantiating variables 6. Project comments 7. Methods used to program
Can a package appear more then once in a declares class?
No
Does a package statement have to be present for the compiler to compile the program?
No
Would the following code run? Class javaPractice { // Some code here }
No the C in class is capitalize, and therefore the code will prompt an error message (the c in the class keyword must be in lowercase).
What to look out for when creating a file in java:
The File name and Class name have to be in common when creating a file for java projects!
What is case sensitive in Java?
The compiler picks up on on lower case and uppercase letters. Case sensitivity can affect the way a program is ran.
What are the mandatory components of a class
The keyword of a class = "Class" The name of the class = "IsNameOfClass" The body of the class = "{...}"
(True or False): The classes and interfaces can be defined in any order of occurrence in a java source file
True
A package statement must
be the first statement in a class.
What does an interface do?
An interface specifies a contract for the classes to Implement.
A package statement is used to:
Define which package a class is in
What is UML and what does is mean?
Unified Modeling Language - A diagram that represents the static view of an application