CS118 cramming cheat sheet

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

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:43 PM on 4/24/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

12 Terms

1
New cards

What happens when we have an else/else if without curly braces?

  • Dangling else problem

  • else will default to the last if that came before it

    • Code may not execute if else was meant for the first if in the block, and several if’s came after it

2
New cards

What is the issue of going from longint and how can it be overcome?

  • long is more precise than int

  • Could lead to a lossy conversion where data is lost and might be less precise

  • Requires a change in return type or an explicit cast

3
New cards

Where can’t switch statements be used?

  • Where there are no discrete values present (e.g. case is an inequality or a range)

4
New cards

What is the process of dealing with a Q2/3-type programming problem?

  • Understand the prompt — identify nouns and verbs, and what concept they relate to

  • Split the task into several steps, input → output → calculation

  • Simplify using variables and arrows

  • Think about how they can be implemented in Java

5
New cards

How should we deal with fields implementing data structures in classes?

  • Declare the field in the class

  • Do not pass it in as a parameter in the constructor, but initialise it within the constructor block

class ClassName { 
 	List<E> list
	int p1;
	int p2;
	
	public ClassName(int p1, int p2) {
		this.p1 = p1;
		this.p2 = p2;
		this.list = new ArrayList<>();
	}
	// ...
}

6
New cards

How should abstract classes and methods be implemented?

  • Declare the method as abstract but do not implement it

  • Inside concrete class, implement the method using @Override notation (without calling it abstract)

7
New cards

How should checked and unchecked exception classes be handled?

  • Unchecked → exception is a subclass of RuntimeException

  • Checked → exception is a subclass of Exception

8
New cards

How should exception-throwing methods be declared?

public [ReturnType] method throws [ExceptionName](…) { … }

throws MUST be there if the method is throwing the exception

9
New cards

What is the format of a generic class?

  • Uses <T> to show that it is a generic class

class ClassName<T> { … }

10
New cards

What would the generic class look like if the generic type can only be subclasses of another type?

Using List<?> as an example:

class ClassName<T extends List<?>> { … }

11
New cards

How are interfaces implemented?

  • Interface only stores the method signature (no body)

  • @Override notation when we implement the methods defined in the interface

  • Included in the class:

public class [ClassName] implements [InterfaceName] { … }

12
New cards

When is @Override notation used?

  • Either when we implement a method from an interface, or we are overriding a method from a superclass

Explore top notes

note
note
6.5: The Great Depression
Updated 1221d ago
0.0(0)
note
Chapter 5: Elasticity
Updated 1138d ago
0.0(0)
note
BUSINESS SECTION 3
Updated 287d ago
0.0(0)
note
Allotropes of Carbon
Updated 1192d ago
0.0(0)
note
FBLA Help Desk
Updated 965d ago
0.0(0)
note
PHRASAL VERBS
Updated 1034d ago
0.0(0)
note
note
note
6.5: The Great Depression
Updated 1221d ago
0.0(0)
note
Chapter 5: Elasticity
Updated 1138d ago
0.0(0)
note
BUSINESS SECTION 3
Updated 287d ago
0.0(0)
note
Allotropes of Carbon
Updated 1192d ago
0.0(0)
note
FBLA Help Desk
Updated 965d ago
0.0(0)
note
PHRASAL VERBS
Updated 1034d ago
0.0(0)
note

Explore top flashcards

flashcards
Healthcare terminology final
172
Updated 84d ago
0.0(0)
flashcards
Unit 5: Rocks and Minerals
78
Updated 995d ago
0.0(0)
flashcards
Japanese Vocab
129
Updated 1150d ago
0.0(0)
flashcards
western civ test 1
100
Updated 537d ago
0.0(0)
flashcards
Memory
42
Updated 854d ago
0.0(0)
flashcards
flashcards
DCAP Ch 10-11 (Exam 5)
108
Updated 201d ago
0.0(0)
flashcards
Healthcare terminology final
172
Updated 84d ago
0.0(0)
flashcards
Unit 5: Rocks and Minerals
78
Updated 995d ago
0.0(0)
flashcards
Japanese Vocab
129
Updated 1150d ago
0.0(0)
flashcards
western civ test 1
100
Updated 537d ago
0.0(0)
flashcards
Memory
42
Updated 854d ago
0.0(0)
flashcards
flashcards
DCAP Ch 10-11 (Exam 5)
108
Updated 201d ago
0.0(0)