Java Basics Study List Flashcards
What is source control?
Source control, also known as version control or revision control, is a system that manages and tracks changes to files and directories over time. It allows multiple developers to collaborate on a project by providing a centralized repository where changes can be recorded, tracked, and managed.
What is a Git repository?
a storage location where Git tracks and manages the history and versions of files for a project. It contains all the files, directories, and commit history associated with the project.
What does git add –all do?
used to stage all changes in the working directory for the next commit. It adds all modified, deleted, and new files to the staging area.
What does git commit -m “my comment” do?
used to create a new commit in the Git repository with a descriptive comment. It permanently saves the changes staged in the staging area and creates a new point in the project’s history.
What does git push do?
used to upload local commits to a remote repository. It sends the committed changes from the local branch to the corresponding branch on the remote repository, making them available to others.
What does git pull do?
used to fetch and merge changes from a remote repository into the current local branch. It updates the local branch with the latest changes from the remote repository.
Why would you create a branch in Git?
Allows developers to work on different features or bug fixes in isolation from the main branch. It enables parallel development and experimentation without affecting the main branch. Once the changes in the branch are complete and tested, they can be merged back into the main branch.
What does the git clone command do?
used to create a copy of a remote Git repository on a local machine. It initializes a new Git repository with the same commit history and files as the remote repository. Cloning allows developers to work with the project locally and make changes that can be synchronized with the remote repository.
What are the three steps in the life cycle of a java program?
Edit
Compile
Execute.
What is the difference between a compiler and an interpreter?
a compiler translates the entire program into machine code before execution, while an interpreter translates and executes the program line by line.
What is the syntax of the main method?
public static void main(String[] args) {
// Code goes here
}
Describe the benefits of using an IDE during programming.
features such as code completion, syntax highlighting, debugging tools, project management, version control integration, and automatic compilation, which enhance productivity and make the development process more efficient.
What is a syntax error?
Syntax errors occur when the code violates the language syntax rules and prevent the program from compiling.
List the differences between data and information.
Data refers to raw facts or values, while information is processed data that has meaning and relevance.
How do you write single-line and multi-line comments?
// This is a single line comment
/*
* This is a multi line comment
*/
What is wrong with the following code?
public class Hello {
String new = “My New House”;
String short = “I am short”;
String private = “I am a private person”;
int catch = 0;
double this = 1.0;
}
The variable names “new,” “short,” “private,” and “catch” are invalid because they are reserved keywords in Java.
The variable name “this” is also invalid because it is a reference to the current instance of the class.
Variable names should be meaningful and descriptive, not arbitrary.
Assign each value to a data type:
5
128
34,780
Bob
86.02
true
x
5: int
128: int
34,780: int
Bob: String
86.02: double
true: boolean
x: depends on the intended usage (e.g., int, double, String, etc.)
How would you keep the decimal value when doing the following operation?
int a = 10;
int b = 4;
float c = 0;
c = a / b;
int a = 10;
int b = 4;
float c = 0;
c = (float) a / b;
What data type is returned when reading from the console? What approach would you use to convert console data to another usable data type?
The data type returned when reading from the console is usually a String. To convert the console data to another usable data type, you can use type conversion methods such as Integer.parseInt() for integers, Double.parseDouble() for doubles, and so on.
What is a runtime error?
Runtime errors occur during program execution when an unexpected condition arises, such as division by zero or accessing an invalid memory location.
What is a logic error?
Logic errors occur when the program executes without any errors or exceptions, but produces incorrect or unexpected results due to flawed logic or algorithm.
Describe how you would debug/step through your code using your IDE?
set breakpoints at specific lines or methods in your code, run the program in debug mode, and then step through the code line by line to analyze the state and behavior of variables and objects at runtime.
What is the output of this method?
public static void main(String[] args) {
int a = 12;
int b = 13;
String C = “Java”;
System.out.println(a + b + C); System.out.println(C + b + a); }
25Java
Java130
Analyze the following code and determine the output.
public static void main(String[] args) {
int a = 12;
int b = 13;
String C = “Java”;
if (a<=b) { System.out.println(a + " is less than " + b); } if (a<=b) { System.out.println(a + " is less than " + b); } else { System.out.println("This is false."); } if (C.equals("JAVA")) { System.out.println("This is true"); } else { System.out.println("This is all uppercase!"); if (C.equals("Java")) { System.out.println("This one is equal"); } } }
12 is less than 13
12 is less than 13
This is all uppercase!
This one is equal
Compare and contrast if statements with switch statements.
If statements allow conditional execution based on boolean expressions, while switch statements allow multi-branch selection based on the value of a variable or expression.
If statements can handle complex conditions and multiple comparisons, while switch statements are limited to equality comparisons.
If statements can use any boolean expression as a condition, while switch statements require a constant or an enum type for the controlling expression.
Write code to generate a random number between 1 and 6.
import java.util.Random;
public class RandomNumberExample {
public static void main(String[] args) {
Random random = new Random();
int randomNumber = random.nextInt(6) + 1;
System.out.println(randomNumber);
}
}