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

  • Family Centered Care December 2, 2011 Robert Lucio,

    Family Centered Care December 2, 2011 Robert Lucio,

    Cultural competence is a developmental process that evolves over an extended period of time. Individuals, organizations and systems are at various levels of awareness, knowledge and skills along the cultural competence continuum. T. Bazron, B. Dennis K. & Isaacs Towards...
  • Management of AREDV masihi 29/11/92

    Management of AREDV masihi 29/11/92

    No systematic reviews of effectiveness of MCA Doppler as a surveillance tool in high risk or SGA fetuses were identified. A systematic review of 31 observational studies (involving 3337 fetuses) found that MCA Doppler had limited predictive accuracy for adverse...
  • DARS - Arizona State University

    DARS - Arizona State University

    Degree Audit Report(DARS) What is it? A report that matches your registered courses at ASU and completed courses (ASU+transfer) against your major's graduation requirements. How is it different than an unofficial transcript? The transcript shows your completed ASU courses in...
  • acumanage.com

    acumanage.com

    External Evaluation HIV/AIDS Workplace Policies and Programmes GTZ / ILO Partnership 2003 - 2007 Strategic Perspective and Impact Beneficiary opinion Methodology Evaluation object
  • Equations with indices We can solve some equations

    Equations with indices We can solve some equations

    Equations with indices. We can solve some equations using techniques we learnt in GCSE (for other types we will need logarithms, a new technique)
  • Atomic Structure - Coach Coker's Chemistry

    Atomic Structure - Coach Coker's Chemistry

    J.J. Thomson (1897) with the Cathode Ray Tube Discovery of the Electron Actual Cathode Ray in action Thomson's Atomic Model Robert A. Millken 1909 Millikan's Oil Drop Experiment Helps to calculate the mass & charge of an electron How it...
  • Higher PE - PE Dept

    Higher PE - PE Dept

    Higher PE Emotional Factors Emotional Factors The main emotional factors that impact on performance are; Happiness/Sadness Anger Fear Happiness/Sadness Is an emotional state of mind. Ranging from feeling content and joy (happy) to a feeling of despair, grief or sorrow...
  • Effects of atrazine on thyroid hormone induction of

    Effects of atrazine on thyroid hormone induction of

    Effects of atrazine on thyroid hormone induction of metamorphosis in the axolotl (Ambystoma mexicanum) Pam Clarkson