Java: Method Exercises 5
This page discusses - Java: Method Exercises 5.
Java: Method Exercises 4
This page discusses - Java: Method Exercises 4.
Java: Method Exercises 3
This page discusses - Java: Method Exercises 3.
Java: Method Exercises 2
This page discusses - Java: Method Exercises 2.
Java: Method Exercises 1
This page discusses - Java: Method Exercises 1.
Threads
Threads vs Processes.
Thread Questions
Which areas of memory do separate threads share?.
switch Statement - Overview
Purpose of switch: select one of many possible statements to execute.
switch Example - Random Insults
The following class could be useful for generating random insults in response to erroneous user input..
Java: Method FAQs
Q: Do we always have to write a class name in front of static method calls?.
Examples - Method and loop review
The examples in this program are intended for reviewing methods and loops..
Example - Variations on max()
Write a method to compute the maximum of two double values. Here are some possible solutions..
Example -- drawHouse
This example shows how to build our own methods that call other methods of ours..
Example - CircleMain.java
Here is the program which uses the CirclePanel class ..
Example - CirclePanel.java
The Java Graphics class draws a circle with drawOval(), whose parameters are not entirely intuitive..
Static/Class methods
Static methods use no instance variables of any object of the class they are defined in..
Methods - Vocabulary
There may be an access modifier at the front of a method header..
Methods - OOP
A good example of a static methods in Java is the Math or Character classes..
Methods - Calling
What happens when a method is called.
Methods - Declaring
Notation: Everything between square brackets, "[" and "]", is optional..
Methods - Example
This example shows a simple method that computes the area of a rectangle..
Methods - Introduction
The word method is commonly used in Object-Oriented Programming and is used in Java..
'while' Statement
The purpose of the while statement is to repeat a group of Java statements many times..
Loops - Introduction
The purpose of loop statements is to repeat Java statements many times. There are several kinds of loop statements in Java..
Loop Idioms
Loops are often used to accomplish the same kinds of tasks, so many loops tend to be one of several common styles..
For-each Loop
The basic for loop was extended in Java 5 to make iteration over arrays and other collections more convenient..
'for' Loop
The for and equivalent while statements have these forms..
Example: String reverse
The following program reverses a string in a very straightforward, but rather inefficient way..
Loop break statement
Loops are often used to accomplish the same kinds of tasks, so many loops tend to be one of several common styles..
if Statement - Overview
The purpose of the if statement is to make decisions..
if-else Flowchart equivalent
There are several graphical ways to show the flow of programs..
'if' Statement - 'else if' style
It is common to make a series of tests on a value, where the else part contains only another if statement..
'if' Statement - if inside if
You can put an if statement inside another if statement..
'if' Statement - Indentation
Indent to make programs readable.
'if' Statement - Braces
If the true or false part of and if statement has only one statement, you do not need to use braces..
'else' Not Required
It is not necessary to have the else part of an if statement. Maybe only 50% of the time there is an else part..
if Statement - Overview
The purpose of the if statement is to make decisions..
Exceptions - More
There are many exceptions, but they can be put into two groups: checked exceptions and unchecked exceptions.
Exception Usage
The most common exceptions to catch are number conversion exceptions and I/O exceptions..
Exceptions
Java throws an exception.
Assertions
Assertions are used to stop execution when "impossible" situations are detected.
Java Review: Control Flow
Java uses the dominant imperative control flow paradigm..