Lecture Notes: Esc 101
Date:
25/01/2008
Consider the following code:
public Class Test{
public static void main(strings args[]){
..........
}
}
The meaning of these terms are given below:
void:- does not return any value. Only has side effects.
main :- method
strings:- type
args:- variables of type string
Now consider the following two functions:
f(x)=x^2 //definition of the function; we are not evaluating it right
now.(an error at the time of evaluation is called Runtime Error.
g(x) = x^3 if f(x)<3 // we are not evaluating them right now
or= 27 if f(x) >=3
Note that the type of function can be different from the type of its
arguments. To see this consider the following function:
f(x,y)= floor(sqrt(x^2-y^2)) , x can be integer, y can be reals, but f
is an integer.
if x<y then we will get run time error in evaluating f(x,y).
It is an error when we are evaluating & not when we are defining f.
Let us consider the following method which computes the function f(x):
double f(double x){
return(x*x);
}
Understanding Methods:
Methods are:
1) blocks of code
2) have names
3) can be called from other places in your program
4) they accomplish some work or task.
Given below is a sample orgainzation of methods within a class.
public Class Test{
method1 : must have a main method that can call other methods
method2:
method3:
...................
}
Below is a method that computes the function g:
double g(double x){
if (f(x)>=3)
return 27
else
return x*x*x
}
Contents of a box of small size can always be put into a box of large
size.
public static void main(string args[]){
double x =3;
System.out.println(g(x)); // here g(x) is not a string but it will be
converted to string.
}
any expression can be converted to a string.