Java without BlueJ
public static void public static void main main (String[] (String[] args args) )
Java without BlueJ public static void main main (String[] - - PowerPoint PPT Presentation
Java without BlueJ public static void main main (String[] (String[] args args) ) public static void Java without BlueJ BlueJ is an BlueJ (IDE) for Java Java . is an Integrated Development Environment Integrated Development Environment (IDE)
public static void public static void main main (String[] (String[] args args) )
BlueJ BlueJ is an is an Integrated Development Environment Integrated Development Environment (IDE) for (IDE) for Java Java. . BlueJ BlueJ provides an provides an editor editor and access to the standard and access to the standard Java Java compiler compiler and and run run-
time system. Its innovation lies in its capabilities for . Its innovation lies in its capabilities for creating objects and invoking methods on them creating objects and invoking methods on them interactively interactively (supporting the passing of arguments and return of results). Thi (supporting the passing of arguments and return of results). This s works through a graphical representation of works through a graphical representation of classes classes and and object
instances and simple instances and simple point point-
and-
click operation. This lets us
immediately start immediately start testing testing newly written classes newly written classes without having without having to write any testing code to write any testing code. . Inspectors Inspectors let us see let us see running results running results. . Additionally, Additionally, BlueJ BlueJ provides a mechanism for provides a mechanism for recording recording a series a series
defined correct correct results results for those tests. These recordings can be for those tests. These recordings can be re re-
run (with the (with the results checked automatically) on the class each time the class results checked automatically) on the class each time the class code is changed code is changed – – regression testing regression testing. . As code is continually As code is continually being maintained, this is a huge help! being maintained, this is a huge help! C h a p t e r 6 C h a p t e r 6 C h a p t e r 6
But what if we don But what if we don’ ’t have t have BlueJ BlueJ? ? How do we get anything written, compiled and run? How do we get anything written, compiled and run? How do we test stuff? How do we test stuff?
But what if we don But what if we don’ ’t have t have BlueJ BlueJ? ? How do we get anything written, compiled and run? How do we get anything written, compiled and run? How do we test stuff? How do we test stuff?
But what if we don But what if we don’ ’t have t have BlueJ BlueJ? ? How do we get anything written, compiled and run? How do we get anything written, compiled and run? How do we test stuff? How do we test stuff?
Java Development Kit (JDK) (JDK) provides no way
Java program) to construct
class DemoMain { public static void main (String[] args) { } } class class DemoMain DemoMain { { public static void public static void main main (String[] (String[] args args) ) { { } } } }
class DemoMain { public static void main (String[] args) { } } class class DemoMain DemoMain { { public static void public static void main main (String[] (String[] args args) ) { { } } } } class DemoMain { /** * Print arguments supplied to this program. */ public static void main (String[] args) { for (String s : args) { System.out.println (s); } } } class class DemoMain DemoMain { { /** /** * Print arguments supplied to this program. * Print arguments supplied to this program. */ */ public static void main (String[] public static void main (String[] args args) ) { { for (String s : for (String s : args args) { ) { System.out.println System.out.println (s); (s); } } } } } }
class DemoMain { /** * Print arguments supplied to this program. */ public static void main (String[] args) { for (String s : args) { System.out.println (s); } } } class class DemoMain DemoMain { { /** /** * Print arguments supplied to this program. * Print arguments supplied to this program. */ */ public static void main (String[] public static void main (String[] args args) ) { { for (String s : for (String s : args args) { ) { System.out.println System.out.println (s); (s); } } } } } }
compile compile invoke invoke main main
% javac DemoMain.java % java DemoMain % % javac javac DemoMain.java DemoMain.java % % java java DemoMain DemoMain % javac DemoMain.java % java DemoMain % % % javac javac DemoMain.java DemoMain.java % % java java DemoMain DemoMain % % % javac DemoMain.java % java DemoMain % java DemoMain one two:a-b –three % % javac javac DemoMain.java DemoMain.java % % java java DemoMain DemoMain % % java java DemoMain DemoMain one
two:a-
b – –three three % javac DemoMain.java % java DemoMain % java DemoMain one two:a-b –three
two:a-b –three % % % javac javac DemoMain.java DemoMain.java % % java java DemoMain DemoMain % % java java DemoMain DemoMain one
two:a-
b – –three three
two:a two:a-
b – –three three % % class DemoMain { /** * Print arguments supplied to this program. */ public static void main (String[] args) { for (String s : args) { System.out.println (s); } } } class class DemoMain DemoMain { { /** /** * Print arguments supplied to this program. * Print arguments supplied to this program. */ */ public static void main (String[] public static void main (String[] args args) ) { { for (String s : for (String s : args args) { ) { System.out.println System.out.println (s); (s); } } } } } }
compile compile invoke invoke main main
InputReader InputReader Responder Responder SupportSystem SupportSystem
SupportSystem object, then click
start() method.
SupportSystem object, then click
start() method.
class TechSupportMain { /** * Print arguments supplied to the program */ public static void main (String[] args) { new SupportSystem ().start (); } } class class TechSupportMain TechSupportMain { { /** /** * Print arguments supplied to the program * Print arguments supplied to the program */ */ public static void main (String[] public static void main (String[] args args) ) { { new new SupportSystem SupportSystem ().start (); ().start (); } } } }
SupportSystem object, then click
start() method. Without
% javac TechSupport.java % java TechSupport % javac TechSupport.java % java TechSupport % javac TechSupport.java % java TechSupport Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > % javac TechSupport.java % java TechSupport Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > % javac TechSupport.java % java TechSupport Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > Your software is a load of rubbish ... % javac TechSupport.java % java TechSupport Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > Your software is a load of rubbish ... Your software is a load of rubbish ... % javac TechSupport.java % java TechSupport Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > Your software is a load of rubbish ... I need a bit more information on that. % javac TechSupport.java % java TechSupport Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > Your software is a load of rubbish ... I need a bit more information on that. class TechSupportMain { /** * Print arguments supplied to the program */ public static void main (String[] args) { new SupportSystem ().start (); } } class class TechSupportMain TechSupportMain { { /** /** * Print arguments supplied to the program * Print arguments supplied to the program */ */ public static void main (String[] public static void main (String[] args args) ) { { new new SupportSystem SupportSystem ().start (); ().start (); } } } }
compile compile invoke invoke main main
The The main main method of the method of the class class to which to which java java is applied must is applied must have the header: have the header: The The compiler compiler from from Sun Sun’ ’s s standard standard Java Java Development Kit Development Kit. This compiles . This compiles .java .java files to files to .class .class files. files.
javac javac javac Launches the Launches the Java Virtual Machine Java Virtual Machine (JVM), (JVM), which invokes the which invokes the main main method of the method of the class class to which it is applied. We give it the to which it is applied. We give it the name name of the class only (no
.class suffix). suffix). java java java public static void main (String[] args) public static void public static void main main (String[] (String[] args args) )