3) Methods - A Deeper Look
3) Methods - A Deeper Look
3) Methods - A Deeper Look
Static methods can be called without the need for an object of the class to exist.
Java is able to keep track of which method is currently executing, how local
variables of methods are maintained in memory and how a method knows
where to return after it completes execution.
import java.util.Scanner;
if (y > maximumValue)
maximumValue = y;
if (z > maximumValue)
maximumValue = z;
return maximumValue;
}
}
The set of packages available in Java is quite large. Java includes packages for
complex graphics, advanced graphical user interfaces, printing, advanced
networking, security, database processing, multimedia, accessibility (for people
with disabilities), concurrent programming, cryptography, XML processing
and many other capabilities.
// RandomNumbers.java
// Shifted and scaled random integers.
import java.security.SecureRandom;
// loop 20 times
for (int i = 1; i <= 20; i++)
{
// pick random integer from 1 to 6
int face = 1 + randomNumbers.nextInt(6);
Method Overloading
(Optional) GUI and Graphics Case Study: Colors and Filled Shapes
// DrawSmiley.java
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
import javax.swing.UIManager.*;
// DrawSmileyTest.java
// Test application that displays a smiley face.
import javax.swing.JFrame;
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
obj.add(panel);
obj.setSize(500, 500);
obj.setVisible(true);
obj.setLocationRelativeTo(null);
}
}