Concurrent Programming with Java
Lab Manual, Version 1.0, F. Astha Ekadiyanto,
2002.
Lab 2: Building Application
A Java Application is when a Java bytecode (namely MobileSystem.class)
can be executed directly by running interpreter program java.exe (see
The HelloWorld Ritual).
What actually executed by the interpreter is to create a thread in Java Virtual
Machine and execute the public static main( String args[] ) method in
the MobileSystem.class.
So, by declaring statements in the main method, one can control how the java
interpreter execute the MobileSystem.class. The arguments given when
executing the java class will automatically passed into the String args[]
array in the manner that any space-separated Strings is considered a single
String object.
The main() method is a static method. This means that it can be executed directly (placed in a Thread object on Java Virtual Machine) without even creating the objects defined in the MobileSystem.class. Thus in order to create any required objects, we should define them in the main() method. This line of code below will do the work.
MobileSystem vodaphone=new MobileSystem("Vodaphone");
The code above will create the MobileSystem Object and execute the constructor
to build the topology. Now to use the object to detect coverage of points
given in the arguments.
Accessing arguments should be performed in a loop since it is stored in the
args[] array. An array always starts with a 0 (zero) index. The size
of array is defined by the length field of the array object. Since there
are two arguments required to compose an x,y coordinate, the array should be
handled as if it is a pseudo 2 dimensional array. Furthermore, since the arguments
are Strings and we require a double datatype, then a parsing to double process
should be performed.
for (int i=0; i<(args.length/2); i++) { double x,y; x = Double.parseDouble(args[i*2]); y = Double.parseDouble(args[(i*2)+1]);... (the rest of the code)}
After a coordinate can be extracted from the argument array, then using findRbs(x,y)
method in Msc, we could search for an Rbs with the Cell that covers
the coordinate.
It the function returns an object reference, then an Rbs is found. But
when it has a null reference, then the coordinate is out of range
or cannot be served.
Rbs servingStation = vodaphone.findRbs(x,y); if (servingStation != null) { System.out.println("\n\nThe point "+x+","+y+" covered by "+servingStation+"."); showNeighbors(servingStation); } else { System.out.println("\n\nThe point "+x+","+y+" cannot be served.\n"); }
The complete codes of this stage is in the followings.
File name : MobileSystem.java
public class MobileSystem extends Msc { // the constructors and other methods are not shown here. |
The following will show an example of the application execution over some given arguments.
C:\Lab2>java MobileSystem 100 200 150 170 The point 100.0,200.0 covered by RBS ID:RBS-3, Cell location at x=90.0,y=190.0 serving area= 1039.23048. Neighboring RBS are: RBS ID:RBS-2, Cell location at x=125.0,y=210.0 serving area= 1039.23048 RBS ID:RBS-1, Cell location at x=95.0,y=230.0 serving area= 800.0 RBS ID:RBS-5, Cell location at x=125.0,y=170.0 serving area= 1256.6370614359173 RBS ID:RBS-9, Cell location at x=55.0,y=170.0 serving area= 1256.6370614359173 RBS ID:RBS-8, Cell location at x=90.0,y=150.0 serving area= 1256.6370614359173 The point 150.0,170.0 cannot be served. |