Unit 1b

API

Application Programming Interface

  • A specification that tells programmers how to use classes and methods in a library

Libraries

Collections of classes written by other programers that have reusable methods

Packages

Groups of related classes and interfaces organized to avoid naming conflicts

Comments & Documentation Tags

Comments

Multi line comment: /* */

Documentation comment: /** */

Single line comment: //

Documentation Tags

  • Tags are used in some comments to improve the readability of the program.

  • @author is used to name the author of the code.

Java Methods

Method Call

It includes the mathod name, the return type, and the parameter list of parameters.

Method Signature

public static int add(int a, int b)

Overloaded Methods

Methods are overloaded when there are many methods with the SAME name, but different signatures with a different number or types or order of parameters


Static vs. Non-Static Methods

Class Methods (aka static methods) are methods that are called with the class name rather than using the object variables if being called from another class.

Instance Methods operate on individual objects of the class and can access that objact’s instance variables and other instance methods

Types of Methods

voidMethods: Methods with a void return type. This means that they do not return anything. They do something that can be observes by the user or by other code.

non-voidMethods: Methods that return a value that the code calling the method can use.

The Math Class

The Math class is a static class, meaning you call this class with its class name.

Example: Math.methodName ()

Random Integers

⭐Remember to Typecast the Math.random()*howMany and add parenthesis

Absolute Value

int x = 3 ;
int y = 4 ;
int a = Math.abs(int x) ;
// or
int b = Math.abs(double y) ;

Power Rule

int x = 5 ; 
int y = 2 ; 
int a = Math.pow(int x, int y);

Square Root

int x = 4 ;
int a = Math.sqrt(int x);

Objects

Class: A program entity that represents a template for a new type of object

Object/Instance: An entity that combines attributes (data) and behavior (methods)

Constructor

A constructor is a special method used to create an instance of a class.


Strings

Every charecter string is an object in java defined by the class

CSA Reference Sheet