Starting out with BlueJ

Lesson 3 - Running Methods of a Class

You can also test and debug classes (that are not dependent on other classes)
For Example

import java.io.*;

public class decision
{

public static void  start() throws IOException
 {input in = new input();
     
     System.out.println("Enter a number ");
   int n = in.getInt();
   if (n % 2 == 0)
     System.out.println("It is even");
   else
     System.out.println("It is odd");
    }
 
}
  • Copy and paste the above class into BlueJ. Call project decision. New Class - decision
  • Compile it.
  • Create an instance of it by right mouse clicking on it.
  • New - decision()
  • Right Mouse click on instance of class that has been created (in Red).
  • Click on start() function.