Week 5, Notes 1

A new data type -- int

To date, we have assigned only values of type double to variables.

Values of type double contain a decimal point.

 

Often we need only whole numbers, e.g., for a counter.

 

If you want a variable to hold a whole number, declare a variable of type int, e.g.,

    int i;

    i = 0;

Useful Math class methods

abs() – takes one parameter and returns its absolute value

pow() – takes two parameters and returns the 1st parameter raised to the power that is the second parameter.

Reducing a complicated formula to java

 

Use parentheses where necessary to group operations.

 

Finding methods using the API

The Java Application Programming Interface (API) lists all the classes and the methods they define that are supplied with the Java Software Development Kit (SDK).  Use this link: http://docs.oracle.com/javase/8/docs/api/

 

The API has three frames:

  1. The list of supplied packages – a package is just a grouping of related classes.
  2. The classes in the selected package (or all of the classes regardless of their package if ‘All Classes’ is selected).
  3. All methods for the selected class.

 

For example, select java.lang in window 1 and Math in window 2 and inspect the methods supplied by the Math class.

 

Example

See ../demos/W05N01.java