COS 202

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards

What is Java?

Java is a popular high-level, object-oriented programming language originally developed by Sun Microsystems (now owned by Oracle). It is a programming language and a platform, known for being robust and secure.

2
New cards

List the key features of Java.

  1. Object-Oriented: Supports OOPS principles like Inheritance, Encapsulation, Polymorphism, Classes.
  2. Platform Independent: Compiled into platform-neutral bytecode.
  3. Easy To Learn: Inherits features from C and C++.
  4. Secure: Provides automatic garbage collection, developers don't interact directly with memory.
  5. Architectural-Neutral: Java bytecode can run on any processor.
  6. Portable: Code written on one OS can run on another without changes.
  7. Robust: Strong compile-time error checks and runtime exception handling.
3
New cards

Name some applications or uses of Java.

Java is used for:

  1. Desktop Applications
  2. Web Applications
  3. Enterprise Applications (e.g., banking)
  4. Mobile (Android apps)
  5. Embedded Systems
  6. Smart Cards
  7. Robotics
  8. Games
4
New cards

What is JVM and its purpose?

JVM (Java Virtual Machine) is an abstract machine that provides a runtime environment for executing Java bytecode. It does not physically exist but is a specification.

5
New cards

What does JRE stand for and what is its function?

JRE (Java Runtime Environment) is a set of software tools that provides the runtime environment for Java applications to execute. It does not include development tools.

6
New cards

What is JDK and what does it include?

JDK (Java Development Kit) includes all the tools, executables, and binaries required to compile, debug, and execute a Java program. It is platform dependent.

7
New cards

Explain the role of the main() method in a Java program.

The main() method represents the starting point of a Java program. The JVM executes it. It is declared as public static void main(String args[]).

8
New cards

What is the purpose of System.out.println()?

System.out.println() is used to print a statement or value to the console. Here, System is a class, out is an object of the PrintStream class, and println() is a method of the PrintStream class.

9
New cards

What are Java keywords?

Java keywords are predefined words with specific meanings that act as keys to code. They cannot be used as variable, object, or class names (e.g., class, if, for, static).

10
New cards

How do you write a single-line comment in Java?

Single-line comments start with two forward slashes (//). Any text after // to the end of the line is ignored by Java.
Example: // This is a comment

11
New cards

How do you write a multi-line comment in Java?

Multi-line comments start with /* and end with */. Any text between these delimiters is ignored by Java.
Example: /* This is a multi-line comment. */

12
New cards

What is a variable in Java?

A variable in Java is a named memory location that acts as a container for storing data values. It is assigned a data type and holds a value during program execution.

13
New cards

List the three types of variables in Java.

  1. Local variable
  2. Instance variable
  3. Static variable
14
New cards

What is a 'local variable'?

A local variable is declared inside the body of a method. It can only be used within that method.

15
New cards

What is an 'instance variable'?

An instance variable is declared inside a class but outside the body of any method. It is not declared as static.

16
New cards

What is a 'static variable'?

A static variable is declared using the static keyword. It cannot be local and is associated with the class, not an instance.

17
New cards

What are Java operators?

Java operators are symbols used to perform various operations on variables and values, such as addition, subtraction, comparison, and logical operations.

18
New cards

List some types of operators in Java.

  1. Unary Operator
  2. Arithmetic Operator
  3. Relational Operator
  4. Ternary Operator
  5. Assignment Operator
  6. Bitwise Operator
  7. Logical Operator
  8. Shift Operator
19
New cards

What are Arithmetic Operators used for? Provide examples.

Arithmetic operators perform common mathematical operations.

  • +: Addition (e.g., x + y)
  • -: Subtraction (e.g., x - y)
  • *: Multiplication (e.g., x * y)
  • /: Division (e.g., x / y)
  • %: Modulus (division remainder, e.g., x % y)
  • ++: Increment (e.g., ++x)
  • --: Decrement (e.g., --x)
20
New cards

What is the purpose of Relational Operators and what do they return?

Relational (or conditional) operators check the relationship between two operands (e.g., less than, greater than, equal to). They return Boolean values (true or false).

21
New cards

Give examples of Java Relational Operators.

  • <: Less Than
  • >: Greater Than
  • <=: Less Than or Equal to
  • >=: Greater Than or Equal to
  • ==: Equal to
  • !=: Not Equal to
22
New cards

What are Logical Operators used for in Java?

Logical operators perform logical operations on boolean values, commonly used in decision-making statements like if conditions and loops to control program flow.

23
New cards

Describe the Java Logical Operators (&&, ||, !).

  • && (Logical AND): Returns true if both operands are non-zero (or true).
  • || (Logical OR): Returns true if at least one operand is non-zero (or true).
  • ! (Logical NOT): Reverses the logical state of its operand (makes true into false, and false into true).
24
New cards

What do data types define in Java?

Data types define the type and value range of the data for variables, constants, method parameters, and return types. They inform the compiler about the type of data to be stored and the required memory.

25
New cards

What are the two main types of data types in Java?

  1. Primitive Data Types
  2. Non-Primitive Data Types
26
New cards

List the eight primitive data types in Java and their general purpose.

Primitive data types are predefined by Java language:

  • byte: Stores small whole numbers (-128 to 127)
  • short: Stores whole numbers (-32,768 to 32,767)
  • int: Stores whole numbers (approx. \pm 2 \text{ billion} )
  • long: Stores large whole numbers (approx. \pm 9 \text{ quintillion} )
  • float: Stores fractional numbers (6-7 decimal digits)
  • double: Stores fractional numbers (15-16 decimal digits)
  • boolean: Stores true or false values
  • char: Stores a single character/letter or ASCII values
27
New cards

What are Non-Primitive Data Types, and why are they also called reference types?

Non-primitive data types are called reference types because they refer to objects. They are typically created by the programmer (except for String) and can call methods to perform operations.

28
New cards

What is a String in Java?

A String in Java is a class that represents sequences of characters, used for storing text. String variables hold collections of characters enclosed in double quotes (e.g., "Hello").

29
New cards

How do you find the length of a String in Java?

You can find the length of a string using the length() method.
Example: String txt = "Hello"; System.out.println(txt.length()); // Outputs 5

30
New cards

Name two common String methods for case conversion.

  1. toUpperCase(): Converts a string to uppercase letters.
  2. toLowerCase(): Converts a string to lowercase letters.
31
New cards

What are Arrays in Java?

Arrays are used to store multiple values of the same type in a single variable, effectively acting as containers for collections of values.

32
New cards

How do you declare and initialize an array of strings in Java?

Declaration: String[] cars;
Initialization: String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};

33
New cards

How do you access an element of an array in Java?

You access an array element by referring to its index number, which starts from 0.
Example: String[] cars = {"Volvo", "BMW"}; System.out.println(cars[0]); // Outputs "Volvo"

34
New cards

What are Classes and Interfaces in Java?

  • Classes: User-defined data types that consist of variables (attributes) and methods (behaviors).
  • Interfaces: Abstract types used to specify a set of methods that a class must implement, defining a contract.
35
New cards

What are control flow statements in Java?

Control flow statements determine the order in which statements in a Java program are executed, allowing for conditional execution and repetition of code blocks.

36
New cards

List the three types of control flow statements in Java.

  1. Condition/Decision Making statements (e.g., if, switch)
  2. Loop statements (e.g., for, while, do-while)
  3. Jump statements (e.g., break, continue)
37
New cards

What is the purpose of an if statement?

An if statement allows you to control the flow of your program by executing a block of code only if a specified condition evaluates to true.

38
New cards

Explain the use of if, else if, and else in Java.

  • if: Executes a block of code if the condition is true.
  • else if: Specifies a new condition to test if the preceding if condition (and any else if conditions) were false.
  • else: Executes a block of code if all preceding if and else if conditions are false.
39
New cards

What is a switch statement used for?

A switch statement selects one of many code blocks (called cases) to be executed based on the value of an expression. It's an alternative to writing many if..else if statements.

40
New cards

How does a switch statement work?

  1. The switch expression is evaluated once.
  2. The result is compared with each case value.
  3. If a match is found, the corresponding code block runs.
  4. (break) stops the execution after a match.
  5. (default) runs if no case matches the expression's value.
41
New cards

What are loop statements in Java used for?

Loop statements allow a statement or group of statements to be executed multiple times, controlling the repetition of code blocks.

42
New cards

List the types of loops available in Java.

  1. while loop
  2. for loop
  3. do...while loop
  4. Enhanced for loop (as of Java 5, for traversing collections/arrays)
43
New cards

When is a for loop typically used?

A for loop is used when the number of times a block of code needs to be executed is known in advance. It combines initialization, condition checking, and increment/decrement into a single line.

44
New cards

What is the syntax of a for loop?

for (initialization; condition; increment/decrement) {
  // block of statements
}
45
New cards

Explain the while loop in Java.

The while loop repeatedly executes a block of code as long as a specified condition remains true. It tests the condition before executing the loop body.

46
New cards

What is the syntax of a while loop?

while (condition) {
  // code block to be executed
}
47
New cards

What is unique about the do-while loop compared to the while loop?

The do-while loop is a variant of the while loop that guarantees the code block will execute at least once, even if the condition is false, because the condition is tested after the initial execution of the loop body.

48
New cards

What is the syntax of a do-while loop?

do {
  // code block to be executed
}
while (condition);
49
New cards

What are sorting and searching operations in the context of arrays?

  • Sorting: Rearranging the elements of a list or array into a specific order (ascending or descending).
  • Searching: Finding a specific element or its index within a list or array.
50
New cards

What inbuilt Java Arrays class methods can be used for sorting and searching?

  • Arrays.sort(nameOfArray): Sorts the array in ascending order.
  • Arrays.binarySearch(nameOfArray, element): Searches for a specified element in a sorted array and