CSC111 (KSU) Core Java Programming Concepts · GitHub
CSC111 (KSU) Core Java Programming Concepts · GitHub
naserowaimer / CSC111(KSU)-
CoreJavaProgrammingConcepts.m
d
Created 7 hours ago
Embed Clone
<script src="https://gist.github.com/nas
Code Revisions 1
CSC111(KSU)-CoreJavaProgrammingConc Raw
epts.md
1. INTRODUCTION TO JAVA
Floating-point: float ,
double [13]
Increment/Decrement
Operators: ++ , -- [14]
Strings [15]:
String: Sequence of
characters, enclosed in double
quotes [15]
Empty String: Contains no
characters, length is 0 [15]
String Indices: Start at 0 [16]
String Methods [17]:
length() : Returns length
of string [17]
charAt(index) : Extracts
character at given index
[17]
indexOf(char) : Finds
first occurrence of
character [17]
indexOf(char, pos) :
Finds character starting at
given position [17]
indexOf(String) : Finds
first occurrence of
substring [18]
indexOf(String, pos) :
Finds substring starting at
given position [18]
substring(beginIndex) :
Extracts substring from
given index to end [19]
substring(beginIndex,
endIndex) : Extracts
substring between given
indices [19]
toLowerCase() : Converts
to lowercase [19]
toUpperCase() : Converts
to uppercase [19]
equals(String) : Checks
if strings are equal [19]
equalsIgnoreCase(String
) : Checks equality
ignoring case [19]
Escape Characters: Special
characters within strings [20]
Examples: \" , \n , \\
[20]
Unicode Character Set:
Encodes characters from
various languages [20]
Input and Output [21]:
Screen Output [21]:
System.out.println(data
) : Prints data and a
newline [21]
System.out.print(data)
: Prints data without a
newline [22]
Concatenation Operator
( + ): Combines strings and
data [21]
Keyboard Input [22]:
Use the Scanner class
[23]
Import
java.util.Scanner [23]
3. CONTROL FLOW
Branching [30]:
if (boolean_expression) {
// Code to execute if tr
} else {
// Code to execute if fa
}
Boolean Expression:
Evaluates to true or false
[31]
Comparing Strings: Use
equals() or
equalsIgnoreCase() [31]
CRITICAL NOTE: Do
not use == to
compare string objects
[32]
Nested if-else: if-else
statements inside each
other [33]
CRITICAL NOTE: Pay
attention to matching
else blocks [34]
Each else
matches the
closest
unmatched if
[34]
Use braces to
clarify nesting
[34]
Multibranch if-else: Chain
of if-else if statements
[35]
Syntax [35]:
if (condition1) {
// Code 1
} else if (condition2) {
// Code 2
} else if (condition3) {
// Code 3
} ... else {
// Default code
}
switch (expression) {
case value1:
// Code 1
break;
case value2:
// Code 2
break;
...
default:
// Default code
}
Controlling Expression:
Value to be matched [36]
Case Label: Constant
value to compare with [36]
break Statement: Exits the
switch block [37]
CRITICAL NOTE:
Omitting break leads
to fall-through [37]
default Case: Executed if
no match found [37]
Conditional Operator ( ?: ):
Shorthand for simple if-else
[30]
Syntax: condition ?
value_if_true :
value_if_false [30]
Loops [38]:
while (boolean_expression) {
// Loop body
}
do {
// Loop body
} while (boolean_expression)
Initialization: Executes
once at the beginning [41]
Condition: Checked before
each iteration [41]
Update: Executed after
each iteration [41]
for Statement Variations
[42]:
Multiple initializations
or updates using
commas [42]
Empty body using a
semicolon [42]
Omitting parts of the
control statements
[42]
CRITICAL NOTE: Be
careful to avoid infinite
loops [43]
Nested Loops: Loops inside
other loops [44]
break Statement in Loops:
Exits the loop immediately [45]
CRITICAL NOTE: Use
sparingly, can make code
harder to understand [45]
continue Statement in Loops:
Skips to the next iteration [45]
CRITICAL NOTE: Not
recommended, can
complicate logic [45]