public class RoundStuff
{
public static final double PI = 3.14
public static final double area(double radius)
{
return ( PI * ~~~)
}
}
public class RoundStuffDemo
{
public static void main(String[] args)
{
System.out.println( RoundStuff.area(radius) + "square inches.");
}
-cannot refer to an instance variable of the class
-cannot invoke a non-static method of the class
-a static method can invoke another static method
-a static method has no this (static method belongs to class area, so no instance created)
-belongs to the class as a whole, and not just to one obj
-there's only one copy of a static variable per class (cf. each obj has its own copy of instance variables)
-all obj of the class can read and change a static variable
-a static method can access static variable
-static variables can be used in static, non static both
-non static variables cannot be used in static
private static int myStaticVariable;
-declared and initialized at the same time (recommended) / if not, explicitly initialized
private static int myStaticVariable = 0;
-a static variable should always be defined private
exception: constant ( pi=3.14, BIRTH_YEAR = 1954 ...)
no import needed
all methods & data are static
pow a b a 의 b승
abs 절대값
min
max
round 반올림
ceil 올림
floor 버림
sqrt 제곱
Byte bObj = 5;
Short sObj = 15;
byte b = bObj.byteValue();
short s = sObj.shortValue();
short s = sObj; //automatic unboxing
Integer.MAX_VALUE, MIN
Double.MAX_VALUE, MIN
Boolean.TRUE
parseInt
parseDouble
toString
char toUpperCase
char toLowerCase
boolean isUpperCase, Lower
boolean isWhitespace
boolean isLetter
boolean isDigit
boolean isLetterOrDigit
main memory consists of a long list of num address called byte
memory location: entire chunk of memory that holds the data
reference: memory address where an obj is located
class type = reference type
variable1과 variable2가 같은 주소를 가짐, 같은 변수를 갖게됨
any change to the value of the parameter cannot change the value of its argument
any change to the value of parameter can change the value of its argument
special constant that may be assigned to a variable of any class type
method cannot be invoked using a variable that is initialized to null
public Person(Person original)
{
if (original == null)
{
System.out.println("Fatal error.");
System.exit(0);
}
name = original.name;
born = new Date(original.born);
if (original.died == null)
died = null;
else
died = new Date(original.died);
}
Person class:
obj of the class Person has a date of birth(not null)
date of death is equal to or later than the date of birth
should create an obj that is a separate, independent
values are same as original
string은 copy constructors 안써도댐
class String contains no mutator methods that can change any of the data in a String obj
String is immutable class
Deep copy: copy that has no references in common with the original (예외: immutable obj)
Shallow copy: not a deep copy, can cause dangerous privacy leak
contains fundamental classes (Math, String, wrapper ...)
import automatically
automatically produce documentation
/**
@param
@return
@throws
@deprecated
@see
@author
@version
*/
to run javadoc, give the following command in console
javadoc -d Documentation_Directory Package_Name
javadoc ClassName.java
javadoc *.java