Strongly, statically typed language
Strongly, statically typed language
Strongly, statically typed language
Platform agnostic
boolean hasClassStarted = true;boolean isClassOver = false;
boolean hasClassStarted = true;boolean isClassOver = false;
int numStudents = rand.nextInt(30);
boolean hasClassStarted = true;boolean isClassOver = false;
int numStudents = rand.nextInt(30);
float gradePointAverage = 3.2f;
boolean hasClassStarted = true;boolean isClassOver = false;
int numStudents = rand.nextInt(30);
float gradePointAverage = 3.2f;
double examScore = 97.362;
boolean hasClassStarted = true;boolean isClassOver = false;
int numStudents = rand.nextInt(30);
float gradePointAverage = 3.2f;
double examScore = 97.362;
char section = 'B';
char section = 'B';
String instructor = "Jennifer Mankoff";
char section = 'B';
String instructor = "Jennifer Mankoff";
All non-primitives types inherit from Object
class
String
; note the capitalizationpublic final String COURSE = "CSE 340"; ...private final String SSN = "123-45-6789";
public final String COURSE = "CSE 340"; ...private final String SSN = "123-45-6789";
package private
public final String COURSE = "CSE 340"; ...private final String SSN = "123-45-6789";
package private
private
self
public final String COURSE = "CSE 340"; ...private final String SSN = "123-45-6789";
package private
private
self
protected
self
, subclasses, and packagepublic final String COURSE = "CSE 340"; ...private final String SSN = "123-45-6789";
package private
private
self
protected
self
, subclasses, and packagepublic
private
private
private
public
for fieldsfinal
final
// local variable cannot be modified ever!final double courseGrade = 95.0;
final
// local variable cannot be modified ever!final double courseGrade = 95.0;
// can't subclass // (for example to make a Student class) public final class Person { ... }
final
// local variable cannot be modified ever!final double courseGrade = 95.0;
// can't subclass // (for example to make a Student class) public final class Person { ... }
// can't override! public final int getValue() { return 0; }
static
static
final static double SALES_TAX_RATE = 0.07; // Class Constant (never changes)static double mTotalAmount = 3.56; // Class variable can change
static
final static double SALES_TAX_RATE = 0.07; // Class Constant (never changes)static double mTotalAmount = 3.56; // Class variable can change
static String toString(int i);// For example Integer.toString(100) => "100";
{visibility} [static] [final] returnType methodName(paramType paramName, ...) { ...}
{visibility} [static] [final] returnType methodName(paramType paramName, ...) { ...}
static
and final
are optional, special modifiersvisibility
is one of public
, private
, protected
, or empty for package privateSumming two numbers and returning the answer as a string
public String getSumOfTwoNumbersAsString(int first, int second) { int sum = first + second; return Integer.toString(sum); // could also return "" + sum}
{visibility} class ClassName { // Field declarations // Method definitions}
public class Student { // Class (static) variables - public static final String STUDENT_KEY = "STUDENT"; private static final String ID_PREFIX = "S"; // Instance Variables private String mIdNumber; private String mName; // Constructors - used to create an instance Student(String name, String idNumber) { this.name = mName; this.idNumber = mIdNumber; } // Methods public String getPrefixedIdNumber() { return ID_PREFIX + mIdNumber; }
// Getter public String getName() { return mName; } // Setter public void setName(String newName) { if (newName == null || newName == "") { newName = "Unknown"; } mName = newName; } ... // etc.}
An enum type is a special data type that enables for a variable to be a set of predefined constant
public enum EssentialGeometry { INSIDE, OUTSIDE };...EssentialGeometry where = EssentialGeometry.INSIDE;
A form of a conditional with different execution paths
public enum EssentialGeometry { INSIDE, ON_EDGE, OUTSIDE };...EssentialGeometry where = EssentialGeometry.INSIDE;switch (where) { case ON_EDGE: // do the edgy things break; case INSIDE: // do the inside things but also fall through // and do the OUTSIDE things because no break statement; case OUTSIDE: // do the outside things break; default: // do default things // automatically falls through}
Java Documentation (https://docs.oracle.com/en/java/javase/13/docs/api/)
Online Java Practice Problems:
Strongly, statically typed language
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
s | Start & Stop the presentation timer |
t | Reset the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |