1.java Fundamentals The Java Language
1.java Fundamentals The Java Language
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Course
Java
Programming Language
Syntax Control flow
Android
What Is Java?
Java
Programming Language This course!
Syntax Control flow
Runtime Environment
Configuration Threading
Java Fundamentals:
Security Input/output
The Java Environment
JRE vs. JDK
Host Environment
(Windows / Linux / Mac / Browser / Android)
Demo
Setting up the JDK
Many choices!
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
System.out.println(“Hello World”);
System.out.println
(
“Hello World”
System.out.println ( “Hello World” );
)
;
package com.pluralsight.myproject;
package com.pluralsight.accounting.myproject;
package com.pluralsight.coursemgmt.myproject;
Members Become Part of the Package
package com.pluralsight.myproject;
Main
public class Main {
public static void main(Strings[] args) { com.pluralsight.myproject.Main
}
}
Package Name and Source File Structure
Main.java src
Main. com
package ccoomm.pluralsight.example; java
public class Main { pluralsight
public static void main(Strings[] args) {
example
}
}
Main.java
Demo
Packages
Demo
Creating and Running a NetBeans Project
Summary
Execute programs from the command line with the “java” command
- Remember to use the full class name including the package name
- On Windows must include JRE bin folder in Path environment variable
Programs are made up of statements
- Statements end with a semicolon
- Parts separated by zero or more whitespaces
Use comments to add notes and hide statements from the compiler
Packages provide organization
- Assure uniqueness
- Most IDE’s tie source code file structure to package names
Variables, Data Types, and Math Operators
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
Variables
Primitive data types
Arithmetic operators
Type conversion
Variables
int dataValue;
dataValue =
100;
otherValue firstValue
int firstValue = 100;
100 15000
int otherValue = firstValue;
firstValue = 50;
Arithmetic Operators
Prefix/postfix Compound
Basic operators
operators assignment operators
Basic Math Operators
Operator Floating Point Example Integer Example
Add + 1.0 + 2.0 3.0 1 +2 3
Subtract - 5.0 - 4.0 1.0 5 -4 1
Multiply * 4.0 * 2.0 8.0 4 *2 8
Divide / 13.0 / 5.0 2.6 13 / 5 2
Modulus % 13.0 % 5.0 3.0 13 % 5 3
Prefix / Postfix Operators
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
Conditional logic
Basic looping
Arrays
For-each loop
The switch statement
Conditional Logic
Relational operators
Conditional assignments
The if statement
Logical operators
Relational Operators
Operator Integer, Character Boolean
Floating Point Example Example
Example
Greater than > 5 > 4 ‘c’ > ‘a’ not available
5 >= 4 ‘c’ >= ‘a’
Greater than or equal to >= not available
4 >= 4 ‘a’ >= ‘a’
Less than < 4 < 5 ‘a’ < ‘c’ not available
4 <= 5 ‘a’ <= ‘c’
Less than or equal to <= not available
4 <= 4 ‘a’ <= ‘a’
true == true
Equal to == 5 == 5 ‘c’ == ‘c’
false == false
Not equal to != 4 != 5 ‘a’ != ‘c’ true != false
Conditional Assignment
Assign a value to a variable based on the
result of a condition int v1 = 7;
int v2 = 5;
if( ... )
if( ... )
Block Statements and Variable Scope
A variable declared within a block is
float students = 30.0;
not visible outside of the block float rooms = 4.0;
- A variable’s range of visibility is known
as the variable’s scope if(rooms > 0.0) {
System.out.println(students);
System.out.println(rooms);
float avg = students / rooms;
System.out.println(avg);
Logical Operators
Operator What Resolves to True
And & true & true
Or | false | true true | false true | true
Exclusive or (XOR) ^ false ^ true true ^ false
Negation ! false
int iVal = 1;
System.out.println(sum);
Arrays
theVals
System.out.println(sum);
For-each Loop
Executes a statement once for each
member in an array for (loop-variable-declaration :array )
- Handles getting collection length statement ;
- Handles accessing each value
float[] theVals = { 10.0f, 20.0f, 15.0f };
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
Classes
Using classes
Classes as reference types
Encapsulation and access modifiers
Method basics
Field accessors and mutators
Classes in Java
Java is an object-oriented language
Objects encapsulates data, operations,
and usage semantics
- Allows storage and manipulation details
to be hidden
- Separates “what” is to be done from
“how” it is done
Classes provide a structure for
describing and creating objects
Classes
Flight.java
A class is a template for creating an object class Flight {
- Declared with the class keyword followed by
the class name
- Java source file name normally has same
name as the class
• We’ll talk more about this shortly
- Body of the class is contained within brackets
}
Classes
Flight.java
A class is made up of both state and class Flight {
executable code int passengers;
- Fields int seats;
• Store object state Flight() {
- Methods seats = 150;
passengers = 0;
• Executable code that manipulates state and }
performs operations
void add1Passenger() {
- Constructors if(passengers < seats)
• Executable code used during object passengers += 1;
}
creation to set the initial state
}
Using Classes
passengers
Use the new keyword to create a class 0
instance (a.k.a. an object) nycToSf
seats
- Allocates the memory described by
the class 150
slcToDallas
- Returns a reference to the allocated
memory
passengers
Flight nycToSf; 10
nycToSf = new Flight();
seats
Flight slcToDallas = new Flight();
150
slcToDallas.add1Passenger();
Classes Are Reference Types
passengers
flight2.add1Passenger(); 150
System.out.println(flight2.passengers); 1 flight2
flight2 = flight1;
System.out.println(flight2.passengers); 0 passengers
flight1.add1Passenger(); 10
flight1.add1Passenger();
seats
System.out.println(flight2.passengers); 2 150
Encapsulation and Access Modifiers
• Start of each word, including the first, is upper case class TrainingVideo { ... }
return;
}
Exiting from a Method
A method exits for one of MyClass m = new MyClass();
three reasons m.showSum(7.5, 1.4, 0
3);
- The end of the method is reached System.out.println(“II’’mm bbaacckk”);
return;
}
Method Return Values
A method returns a single value public class Flight {
private int passengers;
- A primitive value private int seats;
// constructor and other methods elided for clarity
- A reference to an object public boolean hasRoom(Flight f2) {
- A reference to an array int total = passengers + f2.passengers;
if (total <= seats)
• Arrays are objects return true;
else
return false;
}
}
Method Return Values
A method returns a single value public class Flight {
private int passengers;
- A primitive value private int seats;
// constructor and other methods elided for clarity
- A reference to an object public boolean hasRoom(Flight f2) {
- A reference to an array int total = passengers + f2.passengers;
return total <= seats;
• Arrays are objects
}
Method Return Values
A method returns a single value public class Flight {
private int passengers;
- A primitive value private int seats;
// constructor and other methods elided for clarity
- A reference to an object public boolean hasRoom(Flight f2) {
- A reference to an array int total = passengers + f2.passengers;
return total <= seats;
• Arrays are objects }
}
Accessors and Mutators
public class Flight {
private int passengers;
private int seats;
// other members elided for clarity
}
Demo
CalcEngine with Accessors and Mutators
Summary
A class is a template for creating an object
- Declared with class keyword
- Class instances (a.k.a. objects) allocated with new keyword
Classes are reference types
Use access modifiers to control encapsulation
Methods manipulate state and perform operations
- Use return keyword to exit and/or return a value
Fields store object state
- Interaction normally controlled through accessors(getters) and mutators(setters)
Class Initializers and Constructors
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
public Passenger() { }
• If no explicit constructors, Java provides one
}
- A class can have multiple constructors public Passenger(int freeBags) {
this.freeBags = freeBags;
• Each with a different parameter list
}
Passenger bob = new Passenger();
bob.setCheckedBags(3);
parameter list }
}
Constructor Visibility
public class Passenger {
Use access modifiers to control // fields & methods elided for clarity
this.flightNumber = flightNumber;
}
public Flight(char flightClass) {
this.flightClass = flightClass;
}
}
Initialization Blocks
public class Flight {
private int passengers, flightNumber, seats = 150;
Initialization blocks shared across all private char flightClass;
constructors private boolean[] isSeatAvailable;
public Flight() {
- Executed as if the code were placed at isSeatAvailable = new boolean[seats];
the start of each constructor for(int i = 0; i < seats; i++)
isSeatAvailable[i] = true;
- Enclose statements in brackets }
outside of any method or constructor
public Flight(int flightNumber)
{ this();
this.flightNumber = flightNumber;
}
public Flight(char flightClass)
{ this();
this.flightClass = flightClass;
}
}
Initialization Blocks
public class Flight {
private int passengers, flightNumber, seats = 150;
Initialization blocks shared across all private char flightClass;
constructors private boolean[] isSeatAvailable;
p{ublic Flight() { }
- Executed as if the code were placed at isSeatAvailable = new boolean[seats];
the start of each constructor for(int i = 0; i < seats; i++)
isSeatAvailable[i] = true;
- Enclose statements in brackets }
outside of any method or constructor
public Flight(int flightNumber)
{ this();
this.flightNumber = flightNumber;
}
public Flight(char flightClass)
{ this();
this.flightClass = flightClass;
}
}
Initialization and Construction Order
public class OverInitializedClass {
Field private int theField ;= 1;
Initialization public int getTheField() { return theField ; }
{
theField = 2;
}
Initialization
Block public OverInitializedClass() {
theField = 3;
OverInitializedClass c =
}
new OverInitialize dClass();
}
Constructor
System.out.println(c.getTheField();
1
3
2
Summary
Objects should be created in some useful state
Field initializers provide an initial value as part of the declaration
Every class has at least one constructor
- If no explicit constructor, Java provides one with no arguments
- You can provide multiple constructors with differing argument lists
One constructor can call another
- Call must be first line
Initialization blocks share code across constructors
Keep the initialization and construction order in mind
A Closer Look at Parameters
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
Parameter immutability
Constructor & method overloading
Variable number of parameters
Parameter Immutability
}
Parameter Immutability: Classes
flightNumber
Flight val1 = new Flight(10);
10 Flight val2 = new Flight(20);
val1 // print val1 & val2 flight # val1 10
val2 20
flightNumber swap(val1, val2);
val2
20 // print val1 & val2 flight # val1 10
val2 20
i
void swap(Flight i, Flight j) {
Flight k = i;
i = j;
j
j = k;
k // print i & j flight # i 20
} j 10
Parameter Immutability
i
void swapNumbers(Flight i, Flight j) {
int k = i.getFlightNumber();
j i.setFlightNumber(j.getFlightNumber());
j.setFlightNumber(k);
k i 20
10 // print i & j flight #
j 10
}
Overloading
A class may have multiple versions of its constructor or methods
Known as “overloading”
Number of parameters
Overloading
public class Passenger {
// fields & methods elided for clarity
public Passenger() {
}
Overloading
A class may have multiple versions of its constructor or methods
Known as “overloading”
public Flight() {
}
}
Overloading
A class may have multiple versions of its constructor or methods
Known as “overloading”
Class Inheritance
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
Inheritance basics
Member hiding and overriding
The Object class
Object equality
The super keyword
Final and abstract
Inheritance and constructors
Class Inheritance
A class can be declared to inherit (a.k.a. derive) from another class
Use the “extends”keyword
Class Inheritance
public class CargoFlight extends Flight {
float maxCargoSpace = 1000.0f;
float usedCargoSpace;
Class Inheritance
parameter
Class Inheritance
like this or as complex as necessary
@Overrode ANNOTATION
Object
Flight Passenger
CargoFlight
Object References
parameter
Object o = new
Passenger(); o = new
Flight[5];
Object[] stuff = new Object[3];
stuff[0] = new Flight(); o = new CargoFlight();
o.add1Package(1.0, 2.5, 3.0);
stuff[1] = new Passenger(0, 2);
stuff[2] = new CargoFlight();
Presenter
2016-05-20 11:18:28
--------------------------------------------
Really useful when passing as a method
Object References
parameter
o Passenger(); o = new
Flight[5];
o = new CargoFlight();
o.add1Package(1.0, 2.5, 3.0);
Method Description
clone Create a new object instance that duplicates the current instance
hashCode Get a hash code for the current instance
getClass Return type information for the current instance
finalize Handle special resource cleanup scenarios
toString Return string of characters representing the current instance
equals Compare another object to the current instance for equality
Presenter
2016-05-20 11:18:29
--------------------------------------------
Because all classes inherit from the Ob jec
t
Equality
class … let’s use the Object class’
method, “equals”
…toIt bdeep
What does it mean en
equdals?
class Flight {
// other members elided for clarity
Flight f1 = new Flight(175); private int flightNumber;
Flight f2 = new Flight(175); private char flightClass;
Using Abstract
But can also be called by other *concret*
methods
By default, base class’ no-argument Can explicitly call a base class constructor
constructor is called using super followed by parameter list
Must be first line of constructor
Presenter
2016-05-20 11:18:32
--------------------------------------------
NO ARGUMENT constructor
if(s1 == s2)
// do something
if(s1.equals(s2))
// do something
String s3 = s1.intern();
String s4 = s2.intern();
if(s3 == s4)
// do something
int iVal = 100; int i = 2, j = 3;
int result = i * j;
String sVal = String.valueOf(iVal);
System.out.println
(
i + " * " + j + " = " + result);
public class Flight {
int flightNumber;
char flightClass;
// other members elided for clarity
@Overrride Flight myFlight = new Flight(175);
public String toString() { System.out.println(
if(flightNumber > 0) "My flight is " + myFlight);
return "Flight #" + flightNumber;
else
return "Flight Class " + flightClass;
}
}
StringBuilder sb = new StringBuilder(40);
Flight myFlight = new Flight(175); String
- location = “Florida”;
int time = 9;
int pos = sb.length() - “ on “.length()
I flew to Florida on Flight #175
- myFlight.toString().length();
sb.insert(pos, “ at “);
sb.insert(pos + 4, time);
int time = 9;
int pos = sb.length() - " on ".length()
I flew to Florida on Flight #175
- myFlight.toString().length();
StringBuilder sb = new StringBuilder(40);
Flight myFlight = new Flight(175); String
- location = "Florida";
int time = 9;
int pos = sb.length() - " on ".length()
I flew to Florida o
ant 9Flight #175
- myFlight.toString().length();
sb.insert(pos, " at ");
sb.insert(pos + 4, time);
Integer d = Integer.valueOf(100);
int e = d.intValue();
Integer f = Integer.valueOf(e);
Float g = Float.valueOf(18.125f);
float h = g.floatValue();
Integer a = 100;
int b = a;
Integer c = b;
String s = “87.44”;
Integer d = Integer.valueOf(100);
double s1 = Double.parseDouble(s);
int e = d.intValue();
Double s2 = Double.valueOf(s);
Integer f = Integer.valueOf(e);
Float g = Float.valueOf(18.125f);
float h = g.floatValue();
public class Flight {
Integer flightNumber;
Character flightClass;
// other members elided for clarity
Object[] stuff = new Object[3];
@Overrride
stuff[0] = new Flight(); stuff[1] public String toString() {
= new Passenger(0, 2); if(flightNumber != null)
stuff[2] = 100; return "Flight #" + flightNumber;
else if(flightClass != null)
return "Flight Class " + flightClass;
else
return "Flight identity not set ";
}
}
Integer i1000A = 10 * 10 * 10;
Integer i1000B = 100 * 10;
if(i1000A == i1000B)
// do something
if(i1000A.equals(i1000B))
// do something
Integer i8A = 4 * 2;
Integer i8B = 2 * 2 * 2;
if(i8A == i8B)
// do something
public class Passenger {
private final int freeBags;
// other members elided for clarity
}
public class Flight {
public class Passenger { static final int MAX_FAA_SEATS = 550;
private final int freeBags; private int seats;
// other members elided for clarity // other members elided for clarity
}
public class CrewMember {
private FlightCrewJob job;
// other members elided for clarity
public CrewMember(FlightCrewJob job) {
-
this.job = job;
- }
public void setJob(FlightCrewJob job) {
this.job = job;
public enum FlightCrewJob {
Pilot, }
CoPilot, }
CrewMember judy =
FlightAttendant, new CrewMember( FlightCrewJob.CoPilot);
AirMarshal // . . .
} Judy.setJob(FlightCrewJob.Pilot);
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
The try block contains the The catch block contains The finally block contains
“normal” code to execute the error handling code cleanup code if needed
int i = 12;
int j = 2;
try { 0
int result = i / (j - 2);
System.out.println(result);
} catch(Exception e) {
System.out.println(
"Error: " + e.getMessage()); Error: / by zero
e.printStackTrace();
}
Error Handling with Exceptions
BufferedReader reader = null;
int total = 0;
try {
reader =
new BufferedReader(new FileReader("C:\\Numbers.txt")); C:\Numbers.txt
String line = null; 5
while ((line = reader.readLine()) != null) 12
6
total += Integer.valueOf(line);
4
System.out.println("Total: " + total);
} catch(Exception e) {
System.out.println(e.getMessage());
} finally
{ try {
if(reader != null)
reader.close();
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
Exception Class Hierarchy
Object
Throwable
Error Exception
Each exception type can Each catch is tested in order First assignable
have a separate catch block from top to bottom catch is selected
} finally {
. . .
}
Error Handling with Exceptions
BufferedReader reader = null;
int total = 0;
try {
. . .
C:\Numbers.txt
} catch(Exception e) {
System.out.println(e.getMessage()); 5
} catch(NumberFormatException e) { 12
6
System.out.println(“Invalid value: “ +
e.getMessage()); 4
} finally {
. . .
}
Error Handling with Exceptions
BufferedReader reader = null;
int total = 0;
try {
. . .
Exception
} catch(NumberFormatException e) {
System.out.println(“Invalid value: “ +
e.getMessage());
} catch(FileNotFoundException e) { RuntimeException IOException
System.out.println(“Not found: “ +
e.getMessage());
... FileNotFoundException
} catch(IOException e) {
System.out.println(“Error interacting with file: “ +
e.getMessage());
NumberFormatException
} finally {
. . .
}
Exceptions and Methods
methodA
void methodA() {
. . .
try {
methodB();
} catch(. . .) {
. . . methodB
}
void methodB() {
} . . .
methodC();
methodC
} void methodC() {
. . .
methodD(); methodD
} void methodD() {
. . .
// Does something
// that throws an
// an exception
}
Exceptions and Methods
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
What is a package?
Packages as a namespace
Importing packages
Limiting access to package contents
Distributing packages and archive files
What Is a Package?
package xxxxxx ;
public class Flight {
// members elided for clarity
}
Packages Create a Namespace
Package name is part of the type name
package com.pluralsight.travel ;
public class Flight {
// members elided for clarity
}
Packages Create a Namespace
Package name is part of the type name
package com.pluralsight.travel ;
com.pluralsight.travel.Flight lax175 =
public class Flight {
// members elided for clarity new com.pluralsight.travel.Flight(175);
}
Determining a Type’s Package
Compiler needs to know each type’s package
Explicitly qualifying each type is impractical
package com.xyzcompany.bar;
public class Flight {...}
Single Type Import
package com.pluralsight.travel;
public class Flight {...}
package com.xyzcompany.bar;
public class Flight {...}
Type Imports
Type imports guide compiler to map simple names to qualified names
Use import keyword followed by qualified name
Useful for creating types and features to support functionality provided by the
package
Types and features are not meant to be used stand-alone
com
package com.pluralsight.travel;
public class Flight {...} pluralsight
travel
package com.pluralsight.travel;
public class Passenger {...}
Flight.class Passenger.class
Archive Files
Package folder structure can be placed into an archive file
Commonly known as a jar file
Places package folder structure into a single file
Supports compressing content
NetBeans Maven
Demo
Distributing CalcEngine as a Jar File
Summary
A package is a group of related types
- Package declaration must appear in source file before any type declarations
Type name qualified by package name
- Use import statements to map simple names to qualified names
Packages serve as an access boundary
Packages simplify distribution
- Types organized hierarchically according to the package name
- Archive files store package hierarchy in a single file
Creating Abstract Relationships with Interfaces
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
What an interface is
Implementing an interface
Implementing multiple interfaces
Declaring an interface
What Is an Interface?
An interface defines a contract
Provides no implementation
}
}
Implementing an Interface
public class Flight implements Comparable {
// others members elided for clarity
private int flightTime; // minutes past midnight
}
Implementing Multiple Interfaces
public class FlightIterator
implements Iterator<Person>
public class Flight
{ private CrewMember[] crew; implements Comparable<Flight>, Iterable<Person> {
private Passenger[] roster;
// others members elided for clarity
private int index = 0;
private int flightTime;
public FlightIterator(
private CrewMember[] crew;
CrewMember[] crew, Passenger[] roster) {
private Passenger[] roster;
this.crew = crew;
this.roster = roster; public int compareTo(Flight f) {
} Flight f = (Flight) o;
boolean hasNext() { return flightTime - f.flightTime;
return index < (crew.length + roster.length); }
}
public Person next() { public Iterator<Person> iterator() {
Person p = (index < crew.length) ? return new FlightIterator(crew, roster);
crew[index] : roster[index – crew.length]; }
index++;
return p; }
}
}
Implementing Multiple Interfaces
Flight lax045 = new Flight(45);
// Add crew members:
// Pilot Patty, CoPilot Karl, Marshal Mary
// Add Passengers:
// Bob, Jane, Steve, Lisa
Jim Wilson
@hedgehogjim | blog.jwhh.com | jimw@jwhh.com
What to Expect in This Module
Static members
Static initialization blocks
Nested types
Inner classes
Anonymous classes
Static Members
Static members are shared class-wide
Not associated with an individual instance
Field Method
A value not associated with a specific instance Performs an action not tied to a specific instance
All instances access the same value Can access static fields only
Static Members
class Flight {
allPassengers
// other members elided for clarity
Flight.resetAllPassengers()
0 int passengers;
void add1Passenger() {
; System.out.println(
if(hasSeating()) {
0 Flight.getAllPassengers());
lax045 passengers += 1;
Flight lax045 = new Flight(); passengers allPassengers += 1;
lax045.add1Passenger(); } else
lax045.add1Passenger();
0 handleTooMany();
}
Field Method
A value not associated with a specific instance Performs an action not tied to a specific instance
All instances access the same value Can access static fields only
Static import
Provides short hand for accessing static
members
Static Members
import static com.pluralsight.travel.Flight.resetAllPassengers;
import static com.pluralsight.travel.Flight.getAllPassengers;
Flight.resetAllPassengers();
System.out.println(
Flight.getAllPassengers());
System.out.println(
Flight.getAllPassengers());
Static Initialization Blocks
CrewMember p =
CrewManager.FindAvailable(FlightCrewJob.Pilot);
CrewMember c =
CrewManager.FindAvailable(FlightCrewJob.CoPilot);
CrewMember a =
CrewManager.FindAvailable(FlightCrewJob.AirMarshal);
Nested Types
A nested type is a type declared within another type
Classes can be declared within Interfaces can be declared within
classes and interfaces classes and interfaces
if(steve.getRewardProgram().getLevel() == platinum.getLevel())
System.out.println("Steve is platinum");
Nested Types
public class Passenger implements Comparable {
// others members elided for clarity
public static class RewardProgram {
private int memberLevel;
private int memberDays;
public int getLevel() { return level; }
public void setLevel(int level) { this.level = level; }
public int getMemberDays() { return memberDays; }
public void setMemberDays(int days) { this.memberDays = days; }
}
private RewardProgram rewardProgram = new RewardProgram();
public RewardProgram getRewardProgram() {
return rewardProgram;
}
}
Nested Types
Nested types serve differing purposes
Structure and scoping Inner classes
No relationship between Each instance of the nested class is associated
instances of nested and enclosing with an instance of the enclosing class
type
Static classes nested within classes Non-static classes nested within classes