Why can I use Runtime.getRuntime() in Eclipse

Hi Folks,
I am using Eclipse and I can't use Runtime.getRuntime() or freememory in order to make garbage collection program.Any ideas?

Java Code:

/*File:Rational.java
* Write a program that allocates 10000 Rational objects without saving any of them
in variables so that they all become garbage. Once you’ve done so, measure the
amount of free memory before and after garbage collection and use the difference to
report how many bytes were freed, as shown in the following sample run:
*/
import acm.program.*;
import java.util.*;
import java.lang.*;
import acm.util.*;
/**
* The Rational class is used to represent rational numbers, which
* are defined to be the quotient of two integers.
*/
public class Rational {
private static int totalrational=1000;
public static void main (String[]arg){
Runtime myRuntime = new Runtime.getRuntime();
myRuntime.freememory();
for(int i=0; i<totalrational; i++){
Rational a= new Rational(1, 2);
Rational b = new Rational(1, 3);
Rational c = new Rational(1, 6);
Rational sum = a.add(b).add(c);
System.out.println(a + " + " + b + " + " + c + " = " + sum);
}
}
/**
* Creates a new Rational initialized to zero.
*/
public Rational() {
this(0);
}
/**
* Creates a new Rational from the integer argument.
* @param n The initial value
*/
public Rational(int n) {
this(n, 1);
}

And this is the error I am getting:

Java Code:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Runtime.getRuntime cannot be resolved to a type
The method freememory() is undefined for the type Runtime
at Rational.main(Rational.java:33)

According to a website we can get this kind of error if appropriate import is missing at the top.is that right?

This has nothing to do with Eclipse and nothing to do with imports (since Runtime is part of the java.lang package and available to all) but all to do with calling getRuntime() incorrectly. This is a static method not a constructor. There's no place for "new" here.

Also, what is this supposed to do?:

Java Code:

myRuntime.freememory();

It will return an int but you appear to be discarding this return value making it a wasted method call.

Thank you guys,u have been helpful.I sorted the problem by your help.:D

So it were all compilation problems and you could've found a solution by actually reading what the compiler had to say. It had totally nothing to do with Eclipse. When will people actually read diagnostic messages or the API documentation? It sure would lower the traffic on all the forums ...