Objects First With Java - Chapter 7 - School of Computing

Objects First With Java - Chapter 7 - School of Computing

Java without BlueJ public static void main (String[] args) Java without BlueJ BlueJ is an Integrated Development Environment (IDE) for Java. BlueJ provides an editor and access to the standard Java compiler and run-time system. Its innovation lies in its capabilities for creating objects and invoking methods on them interactively (supporting the passing of arguments and return of results). This works through a graphical representation of classes and object instances and simple point-and-click operation. This lets us immediately start testing newly written classes without having to write any testing code. Inspectors let us see running results. Additionally, BlueJ provides a mechanism for recording a series of interactive tests on a class together with user-defined correct results for those tests. These recordings can be re-run (with the results checked automatically) on the class each time the class code is changed regression testing. As code is continually 6 r te

being maintained, this is a huge help! p a h C Java without BlueJ But what if we dont have BlueJ? How do we get anything written, compiled and run? How do we test stuff? Write (using any editor) each Java class in a separate file, whose name is the class name with the suffix: .java For example, the Date class goes in the file Date.java To compile, we need a command window (e.g. Command Prompt in Windows Accessories or any Unix window). Change directory (cd) to wherever the .java files are. Java without BlueJ But what if we dont have BlueJ? How do we get anything written, compiled and run?

How do we test stuff? Change directory (cd) to wherever the .java files are. To compile, use the command: javac Date.java If no errors, this produces the file: Date.class .class files contain Java byte code. Dont try to look at it these files dont hold anything humans can read! Java without BlueJ But what if we dont have BlueJ? How do we get anything written, compiled and run? How do we test stuff? .class files contain Java byte code. Dont try to look at it these files dont hold anything humans can read! How do we create class objects and execute their methods? The standard Java Development Kit (JDK) provides no way (outside of a Java program) to construct objects! But it does have a way to invoke a (very particular) static method for which, of course, we only need the class (not an object).

Java without BlueJ class DemoMain { public static void main (String[] args) { } } Only a static method called main, with exactly the above signature, can be run with the standard command. Java without BlueJ class DemoMain { /** * Print arguments supplied to this program. */ public static void main (String[] args) { for (String s : args) { System.out.println (s);

} } } Only a static method called main, with exactly the above signature, can be run with the standard command. Java without BlueJ class DemoMain { /** * Print arguments supplied to this program. */ public static void main (String[] args) { for (String s : args) { System.out.println (s); } } } % javac DemoMain.java

% java DemoMain compile invoke main Java without BlueJ class class DemoMain DemoMain {{ /** /** ** Print Print arguments arguments supplied supplied to to this this program. program. */ */ public

public static static void void main main (String[] (String[] args) args) {{ for for (String (String ss :: args) args) {{ System.out.println System.out.println (s); (s); }} }} }} %% %% compile

javac javac DemoMain.java DemoMain.java java java DemoMain DemoMain %% java java DemoMain DemoMain one one two:a-b two:a-b three three one one two:a-b two:a-b three three %%

invoke main Java without BlueJ For example, the BlueJ project tech-support-complete: SupportSystem InputReader Responder With BlueJ, we make a SupportSystem object, then click the start() method. Java without BlueJ For example, the BlueJ project tech-support-complete: With BlueJ, we make a SupportSystem object, then click the start() method. Without BlueJ, we have to program: class TechSupportMain { /** * Print arguments supplied to the program */

public static void main (String[] args) { new SupportSystem ().start (); } } Java without BlueJ class class TechSupportMain TechSupportMain {{ /** /** ** Print Print arguments arguments supplied supplied to to the the program program */ */

public public static static void void main main (String[] (String[] args) args) {{ new new SupportSystem SupportSystem ().start ().start (); (); }} }} compile % javac TechSupport.java invoke main % 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 Your software software is is aa load load of of rubbish rubbish ... ... I need a bit more information on that. Java without BlueJ w e i v e R

javac The compiler from Suns standard Java Development Kit. This compiles .java files to .class files. Launches the Java Virtual Machine (JVM), which invokes the main method of java the class to which it is applied. We give it the name of the class only (no .class suffix). The main method of the class to which java is applied must have the header: public static void main (String[] args)

Recently Viewed Presentations

  • 管理研究所 Emba「研究方法」 6.論文撰寫與研究倫理

    管理研究所 Emba「研究方法」 6.論文撰寫與研究倫理

    If you wish to view the manuscript and the review form simultaneously, click on the HTML or PDF icons - the manuscript will open in a new window. Leave the new window open, switch back to the main window, and...
  • Shani Mootoo, Valmikis Daughter (2008) She would embark

    Shani Mootoo, Valmikis Daughter (2008) She would embark

    "Located in South Trinidad, the town of San Fernando is second in size only to Port of Spain in the North of the island.In a country with two major ethnic groups, San Fernando is also regarded, to some extent, as...
  • Their Eyes Were Watching God - macllange

    Their Eyes Were Watching God - macllange

    How do the motifs of the horizon, the pear tree and the bees factor into Janie's leaving? What is ironic about Nanny's plan for Janie? Complete reading of Ch 4 and dialectical journal. Be prepared to identify and discuss vital...
  • A Brief History of Planetary Science

    A Brief History of Planetary Science

    Joule-Thompson Expansion Consider two pistons that move to force a fluid through a narrow plug Pi before the process is larger than Pf after it Process is adiabatic (insulated) Can be achieved by a pump circulating fluid through a pipe...
  • Fables - Mr. DIDONATO'S CLASSROOM

    Fables - Mr. DIDONATO'S CLASSROOM

    How to Write a Fable. Choose the Moral or Lesson. Because the moral is the crux of a fable, it's often helpful to begin outlining your fable by determining the moral. The moral of a fable should relate to or...
  • Arthropoda - phsfusco.org

    Arthropoda - phsfusco.org

    Arthropoda Jointed Legged Animals Introduction More than a million artrhopods have been identified to date. More have yet to be discovered Unbelievable diversity of animals Subphyla Subphylum Chelicerata - spiders, ticks, mites , scorpions, and horseshoe crabs Subphylum Mandibulata Class...
  • Soc3306a - University of Western Ontario

    Soc3306a - University of Western Ontario

    Soc3306a Individual Assignment 6
  • Models of Learning and Motivation - EdShare Soton

    Models of Learning and Motivation - EdShare Soton

    Evaluating Justifying a decision or course of action Checking, hypothesising, critiquing, experimenting, judging Analysing Breaking information into parts to explore understandings and relationships Comparing, organising, deconstructing, interrogating, finding Applying Using information in another familiar situation Implementing, carrying out ...