Week 2 - Java foundations - Classes, Objects, Flow Control, Arrays Flashcards
What is the purpose of the package declaration in a Java file?
The package declaration declares the package in which the class will reside. Packages are a way of organizing classes, interfaces, and enums in a hierarchical manner.
What is the naming convention for Java packages?
Packages follow a naming convention of lowercase characters separated by periods in the reverse way you would specify a web domain - thus, com.revature.mypackage instead of mypackage.revature.com.
What is a fully qualified class name in Java?
A fully qualified class name is the package declaration followed by the class name, in order to uniquely identify the class.
Let’s say we have a Java class named “Employee” that is located in the “com.company.hr” package. The fully qualified class name for this class would be “com.company.hr.Employee”.
What is the purpose of an import statement in Java?
An import statement is used to pull in other classes so that the programmer can just use the class name without the package.
What is the default package imported in Java?
By default, everything in the java.lang package is imported in Java, which gives us the System class.
What is a class declaration in Java?
A class declaration in Java declares a class with a specific name, and it is defined by wrapping it with curly braces.
What is the name of the method that serves as the entry point for Java applications?
The main method serves as the entry point for Java applications
What is the purpose of the main method in Java?
The main method is a special method that specifies the entry point of the application. It is invoked by the JVM when the code is executed.
What type of data does the main method return in Java?
The main method does not return any data in Java. The void keyword is used to denote this.
What is the purpose of the array of String objects passed to the main method in Java?
The array of Strings defined in the main method parameters are passed from the command line when the java command is run. They are used to pass input to the program at runtime.
What are the different scopes of a variable in Java?
The different scopes of a variable in Java are: instance, class, method, and block.
What is instance scope in Java?
Instance scope means that the variable is attached to individual objects created from the class. When an instance-scoped variable is modified, it has no effect on other, distinct objects of the same class.
What is class scope in Java?
Class scope means that the variable resides on the class definition itself. When objects update a class-scoped variable, the change is reflected across all instances of the class. Class scope is declared with the static keyword.
What is the method scope in Java?
Method scope is the scope of a variable declared within a method block, whether static or instance. Method-scoped variables are only available within the method they are declared and do not exist after the method finishes execution.
What is block scope in Java?
Block scoped variables only exist within the specific control flow block, of which there are several in Java: for, while, and do-while loops, if/else-if/else blocks, switch cases, or even just regular blocks of code declared via curly braces ({}).
What is the difference between a class and an object in Java?
A class is a template used to instantiate objects. An object is an instance of a class in memory.
What is a reference variable in Java?
A reference variable is a variable that stores the reference to an object in memory. It is used to interact with objects through their reference, which is the memory address used by the JVM to find a particular
Which is not a rule for which you can create a custom class in Java?
Syntax rules
What is TDD?
Test-driven development, or TDD, is a software development process that involves writing unit tests before implementing application code.
What is the TDD process?
The TDD process involves designing the interface/function, writing tests that use that function, refactoring method signatures, implementing functions, and running tests to verify functionality.
What is unit testing?
Unit testing is the testing of individual software components in isolation from the rest of the system, accomplished by writing tests that execute the code we want to inspect.
Why is TDD useful in software development?
Following the TDD process ensures that a valid unit test exists for any class or method written, and gives developers confidence in refactoring code without breaking existing functionality. When issues arise, the pinpointing of problems is easier with TDD.
What is the most common unit testing framework in Java?
JUnit is the most common unit testing framework in Java.
When following the Test Driven Development process (TDD), when should the tests be written?
Before any code is written
What is the testing of individual software components in isolation from the rest of the system?
Unit testing
A unit test should be run…?
Until the test passes