Flashcard Deck · 23 cards · Public

Stanford CS106A - Programming Methodology (Java Basics)

Master Java programming fundamentals with this comprehensive flashcard deck, covering variables, control structures, methods, arrays, and object-oriented basics essential for CS106A success. Elevate your coding skills and ace your programming journey!

Cards in this deck

(23 cards)

Preview terms and definitions before starting your study session.

#1
Term
What is Java?
Definition
Java is a high-level, object-oriented programming language known for its "write once, run anywhere" capability, achieved through the Java Virtual Machine (JVM). It's widely used for enterprise-level applications, mobile development (Android), and more.
#2
Term
What is the purpose of the main method in a Java program?
Definition
The main method is the entry point for any standalone Java application. When you run a Java program, the JVM looks for and executes the main method first. Its signature is public static void main(String[] args).
#3
Term
Explain the difference between declaring and initializing a variable in Java.
Definition
1. Declaration: Reserves memory for a variable and specifies its data type, e.g., int age;.
2. Initialization: Assigns an initial value to a declared variable, e.g., age = 30;.
Often, declaration and initialization are combined: int age = 30;.
#4
Term
List and briefly describe four primitive data types in Java.
Definition
1. int: Stores whole numbers (integers), e.g., 10, -5.
2. double: Stores floating-point numbers (decimals), e.g., 3.14, -0.5.
3. boolean: Stores truth values, either true or false.
4. char: Stores a single character, enclosed in single quotes, e.g., 'A', '7'.
#5
Term
How does the String data type differ from primitive data types in Java?
Definition
String is an object (a class), not a primitive data type. It represents a sequence of characters. Unlike primitives which store direct values, String variables store references to String objects in memory.
#6
Term
What is the basic syntax for an if statement in Java?
Definition
An if statement executes a block of code only if a specified condition is true.
java3 lines
if (condition) {
    // Code to execute if condition is true
}
#7
Term
Explain the purpose and structure of an if-else if-else statement.
Definition
It allows for multiple conditions to be tested sequentially. The first true condition's block is executed, and subsequent else if and else blocks are skipped.
java7 lines
if (condition1) {
    // Code for condition1
} else if (condition2) {
    // Code for condition2
} else {
    // Code if no conditions above are true
}
#8
Term
When would you typically use a for loop in Java? Provide its basic syntax.
Definition
A for loop is ideal when you know exactly how many times you want to iterate, often used for iterating over arrays or a fixed range of numbers.
java3 lines
for (initialization; condition; increment/decrement) {
    // Code to execute repeatedly
}
Showing 8 of 23 cards in this deck.
Study All Now