Docsity

CST 8116 Final Exam Cheatsheet 2026 | Java Variables, Methods & Data Types | Complete Stud, Exams of Nursing

Toggle sidebar
bg1
Variables:
Java editing, compiling and executing:
While loop(pretest loop) Anatomy:
Switch Statement:
Comparison Operators:
If statement anatomy:
For loop(alternative loop) Anatomy:
Some array examples:
Java Primitive Data Types:
-Boolean
-char (16 bits)
-byte (8-bits of memory, numerical range is from -128 to 127)
-short (16-bits of memory, numerical range is from -32,768 to 32,767)
-int (32-bits of memory, numerical range is from -2^31 to 2^31 -1)
-Long (64-bits of memory numerical range is from -2^63 to 2^63 -1)
-Float (4 bytes)
-double (8 bytes)
Non-Primitive Data Types:
-String, Array, Class, Interface
Types of Variables:
Instance variables:
Declared inside the class but outside of the method, block or
constructor. If not initialized, the default value is 0. Variables are
created when an instance of the class is created and destroyed when it
is destroyed.
Instance Variables:
pf3

Partial preview of the text

Download CST 8116 Final Exam Cheatsheet 2026 | Java Variables, Methods & Data Types | Complete Stud and more Exams Nursing in PDF only on Docsity!

Variables:

Java editing, compiling and executing:

While loop(pretest loop) Anatomy:

Switch Statement:

Comparison Operators:

If statement anatomy:

For loop(alternative loop) Anatomy:

Some array examples:

Java Primitive Data Types:

  • Boolean
  • char (16 bits)
  • byte (8-bits of memory, numerical range is from - 128 to 127)
  • short (16-bits of memory, numerical range is from - 32,768 to 32,767)
  • int (32-bits of memory, numerical range is from - 2 ^ 31 to 2 ^ 31 - 1)
  • Long (64-bits of memory numerical range is from - 2 ^63 to 2^ 63 - 1)
  • Float (4 bytes)
  • double (8 bytes)

Non-Primitive Data Types:

  • String, Array, Class, Interface

Types of Variables:

Instance variables: Declared inside the class but outside of the method, block or constructor. If not initialized, the default value is 0. Variables are created when an instance of the class is created and destroyed when it is destroyed.

Instance Variables:

Local Variables: Declared and initialized inside the body of the method, block, or constructor. It has access only within the method in which it is declared and is destroyed later from the block or when the function call is returned. Static Variable: Declared using a “static” keyword. It cannot be local. Variables are created to create a single copy in the memory shared among all objects at a class level.

Constructors:

Initializes an object on creation, they have the same name as the class, they do not have a return type, and it cannot be static, final or abstract.

Arrays:

An array is a group of like-type variables referred by a common name, having continuous memory. Primitive value objects are stored in an array. It provides code optimization since we can sort data efficiently and also access it randomly. The only flaw is that we can have a fixed-size element in an array.

Strings:

  • String type is used to declare string variables.
  • An array of strings can also be declared.
  • Java strings are immutable; we cannot change them.
  • Whenever a string variable is created, a new instance is created.

STRINGS ARE IMMUTABLE!

Method Coupling: Used to discuss how much one or more methods

are connected. Tight Coupling: One or more methods are interdependent on each other. Loose Coupling: one or more methods are not interdependent.

Variable Scopes:

Class-level scope: Each variable declared inside of a class's

brackets ( {} ) with private access modifier but outside of any method, has class scope. As a result, these variables can be used everywhere in the class, but not outside of it:

Local/Method/Loop Scope: Variables declared inside of the

method or loop will only be valid inside of the same method or loop.

Block-Level Scope: A variable declared inside of an if, else, or

switch is limited to the block it was declared within, a block in this context is code inside the { and }

Memory Maps:

Classes are represented using a rectangle with SQUARE edges. Objects are represented using ROUNDED edged rectangles Variables are represented by a small square box, enter ref into box for references and null if empty.

Stack: Method call stack is used to store information about the active

methods in a program and is important for keeping track of the execution of the program and allowing methods to call and return from each other

Heap: The Heap is where objects are allocated and stored during the

lifetime of a program, it is where memory is allocated for new objects and deallocated when they are no longer needed. The heap is typically much larger than the stack, and it is where garbage collection takes place.

Flowcharts:

Oval: Indicate start and end points Parallelograms: Designate input or output operations Rectangle: Depicts a process such as a math calculation or a variable assignment Diamond: True/false statement being tested in a decision symbol

Random Slideshow info:

Algorithms: An algorithm is a solution to a problem, as a sequence of steps initiated with one starting point, and finishing at one exit point. Computer programs are algorithms. Variable: A name (identifier) used by a programmer to refer to a part of the computer's memory to store and retrieve data. [Modifiers] [Data Type] [Identifier][Assignment Operator][Initial Value];

What is a class?: A class is a blueprint for an object

What is an object?: An object is an allocation of memory that

contains properties and behaviors.

Instantiating Class Scanner:

private Scanner keyboard = new Scanner(System.in);

Keyword “Return”:

Tells Java to exit a method immediately and must be the last statement in the method for non-void methods.

Method Overloading:

Method overloading occurs when two methods have the same name, but different signatures. (Same for Constructors)

Magic Numbers:

Magic numbers are literal values within computer code that have additional meaning outside of their value.

Loop Control Variable:

A loop control variable is a variable that is part of the boolean expression controlling the loop.

Implementation Hiding: Hiding or encapsulating the details of

how a method works.

Method Cohesion: How the internal statements serve to

accomplish the method's purpose.

Git Commands:

‘Git init’ Initialize a new local git repository ‘Git add’ Add files to the staging area ‘Git commit’ Create a new commit with the files that are in staging

To encapsulate a variable it must be set to private