Certainly! Here is the fully updated and unified Java review guide, now with both parts of the lesson included and organized for clarity:
Term | Description |
---|---|
Method | A behavior or function defined in a class. |
Static | Belongs to the class itself. Called using ClassName.methodName() . |
Non-static | Belongs to an individual object. Requires creating an instance to access. |
Cake
and Bakery
ClasseslistFlavorChoices
Cake.listFlavorChoices();
String
(list of flavors).java
System.out.println(Cake.listFlavorChoices());
howManyCalories
Steps:
Create a Cake
object:
java
Cake vanilla = new Cake();
2. Call the method:
java
int calories = vanilla.howManyCalories();
addWriting
String
.java
vanilla.addWriting("Happy Birthday");
mixIngredients
Component | Description |
---|---|
Access Modifier | public , private , etc. (controls visibility) |
Return Type | e.g., int , String , void |
Method Name | Identifier like howManyCalories |
Parameters | Inputs like (String message) |
char
.Concept | Description |
---|---|
Stack | Stores variable references. |
Heap | Stores objects. |
String Pool | Optimized memory for string literals. Same values point to the same object. |
Immutable | Strings cannot be changed once created. Any changes produce a new string. |
String a = "Hello";
String c = new String("Hello");
==
).equals
)a.equals(b); // true if values are the same
a.equalsIgnoreCase(b); // ignores capitalization
Method | Description |
---|---|
length() |
Returns the number of characters. |
substring(start) |
Returns part of the string starting at index start . |
substring(start, end) |
Returns characters from start (inclusive) to end (exclusive). |
equals(otherString) |
Checks for value equality (case-sensitive). |
equalsIgnoreCase(otherString) |
Value equality ignoring case. |
compareTo(otherString) |
Returns difference in Unicode values; 0 if equal. |
String e = "hi";
String f = e;
String g = "howdy";
String h = new String("Hi");
// Comparisons
e == f; // true (same object)
e == h; // false (different objects)
e.equals(h); // false (case-sensitive)
e.equalsIgnoreCase(h); // true
g.length(); // 5
g.substring(2); // "wdy"
g.substring(1, 4); // "owd"
+
Operator in Java+
Operation | Description |
---|---|
Addition | Adds numeric values (int + int, double + double). |
Concatenation | Joins two strings together. |
3 + 5 // 8 (int)
2.0 + 4.0 // 6.0 (double)
4.2 + 3 // 7.2 (int is promoted to double)
"Hello" + " " + "World" // "Hello World"
"Score: " + 100 // "Score: 100"
โ ๏ธ Java will implicitly convert non-strings (e.g., int, double) to strings when used in concatenation.
ClassName.methodName()
for static methods.objectName.methodName()
for non-static methods..equals()
to compare values, not ==
.substring()
, length()
, and compareTo()
for manipulation.+
can mean addition (for numbers) or concatenation (for strings).Let me know if you want practice questions, diagrams, or code samples for any part of this guide!