COMP SCI MIDTERM
Here are definitions of the terms as they relate to Java:
Chapter 1:
Hardware, Program, and Software
Hardware: The physical components of a computer, such as the CPU, memory, and storage.
Program: A set of instructions that a computer follows to perform a task.
Software: The collection of programs that control hardware and execute tasks.
Programming Language, JAVA Programming Language
Programming Language: A formal set of instructions that a computer can execute.
JAVA Programming Language: A high-level, object-oriented language that is platform-independent due to the Java Virtual Machine (JVM).
Identifiers, Legal Identifiers
Identifiers: Names used for variables, methods, classes, etc.
Legal Identifiers: Must start with a letter, underscore, or dollar sign and cannot be a Java keyword.
White Space
Spaces, tabs, and newlines that improve readability but do not affect execution.
Program Development
The process of designing, writing, testing, and maintaining a program.
Language Levels
Levels of programming abstraction: Machine language, Assembly, High-level language (e.g., Java).
Compilation
Converting Java source code into bytecode using the Java compiler.
Java Translation
The process where Java source code is compiled into bytecode and then interpreted by the JVM.
Development Environments
Tools used for Java programming (e.g., Eclipse, IntelliJ, NetBeans).
Syntax and Semantics
Syntax: The rules governing the structure of valid Java code.
Semantics: The meaning of Java statements.
Three Types of Errors
Syntax Errors: Violations of Java's rules (e.g., missing semicolons).
Runtime Errors: Errors occurring during execution (e.g., division by zero).
Logical Errors: Incorrect logic leading to undesired output.
Problem Solving
The process of designing a solution and implementing it in code.
Development Activities
Steps in creating a program: analysis, design, coding, testing, debugging.
Object-Oriented Programming (OOP)
A programming paradigm based on objects and classes.
Objects
Instances of a class containing attributes (fields) and behaviors (methods).
Classes
Blueprints for creating objects.
Classes and Objects
Classes define object properties; objects are instances of classes.
Chapter 2:
Character Strings
Sequences of characters handled by the
String
class.
Two Ways to Create String Objects
Using string literals:
String s = "Hello";
Using
new
:String s = new String("Hello");
Println/print Method
System.out.print()
: Prints without a newline.System.out.println()
: Prints with a newline.
String Concatenation
Combining strings using
+
:"Hello" + " World"
results in"Hello World"
.
Escape Sequences
Special characters (
\n
,\t
,\\
, etc.).
Variables
Named storage locations in memory.
Assignment
Assigning values using
=
.
Constants
Immutable values declared with
final
.
Primitive Data Types
byte
,short
,int
,long
,float
,double
,char
,boolean
.
Numeric Types
Integer (
int
,long
) and floating-point (float
,double
).
Characters
Represented using
char
, e.g.,char c = 'A';
.
Booleans
true
orfalse
values.
Expressions
Combinations of variables, operators, and values.
Division and Remainder
/
for division,%
for remainder.
Assignment Revisited
Assigning values with operators (
+=
,-=
, etc.).
Increment and Decrement Operators
++
and--
increase or decrease a variable by 1.
Assignment Operators
=
,+=
,-=
,*=
,/=
,%=
.
Data Conversions
Assignment Conversion: Implicit conversion in assignments.
Promotion: Widening conversion (e.g.,
int
todouble
).Casting: Explicit conversion using
(type)
.
Scanner Class
Used for input reading (
Scanner sc = new Scanner(System.in);
).
Reading Input
Methods like
nextInt()
,nextDouble()
,nextLine()
.
Input Tokens
Individual units of input parsed by
Scanner
.
Chapter 3:
Creating Objects
ClassName obj = new ClassName();
Creating Strings (Two Ways)
Using literals.
Using
new
.
Invoking Methods
Calling methods on objects:
obj.method();
.
Object References
Variables storing memory addresses of objects.
Assignment Revisited
Assigning references, not copying objects.
Aliases
Multiple references to the same object.
String Class and Methods
Methods like
length()
,substring()
,toUpperCase()
.
Java API/Packages
Predefined Java libraries.
Import Declarations
import java.util.Scanner;
.
The java.lang
Package
Implicitly imported (contains
Math
,String
, etc.).
Random Class
Generates random numbers (
Random rand = new Random();
).
Wrapper Classes
Convert primitives to objects (
Integer
,Double
, etc.).
Autoboxing
Automatic conversion between primitives and wrapper objects.
Chapter 7:
Definition of Array
A collection of elements of the same type.
Declaring Arrays
int[] arr;
.
Using Arrays
Access elements with indices.
Bounds Checking
Java prevents accessing indices out of range.
Alternate Array Syntax
int arr[];
.
Initializer Lists
int[] arr = {1, 2, 3};
.
Two-Dimensional Arrays
int[][] matrix = new int[3][3];
.
Pros and Cons of Arrays
Pros: Fast access, easy iteration.
Cons: Fixed size, memory overhead.
Chapter 8:
Concepts of Inheritance
A subclass inherits attributes and methods from a superclass.
Examples of Parent/Child Classes
Words:
Noun
extendsWord
.Book:
Ebook
extendsBook
.Hospital Employee:
Doctor
extendsEmployee
.
The protected
Modifier
Allows subclass access but prevents outside access.
The super
Reference
Calls superclass constructor/methods.
Overloading vs. Overriding
Overloading: Same method name, different parameters.
Overriding: Redefining superclass methods in a subclass.
Class Hierarchies
Organized structure of classes.
The Object
Class
The root of all Java classes.
Abstract Classes
Cannot be instantiated; contains abstract methods.
Visibility Revisited
public
,private
,protected
.
Designing for Inheritance
Using
super
andprotected
members.
Chapter 9:
Binding
The association of a method call with its definition.
What is Polymorphism?
The ability of a method to take different forms.
References and Inheritance
A superclass reference can hold a subclass object.
Polymorphism via Inheritance
Subclasses can override superclass methods and be referenced polymorphically.
Let me know if you need further clarification on any term!