java without bluej
play

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)


  1. Java without BlueJ public static void main main (String[] (String[] args args) ) public static void

  2. Java without BlueJ BlueJ is an BlueJ (IDE) for Java Java . is an Integrated Development Environment Integrated Development Environment (IDE) for . BlueJ provides an Java compiler BlueJ and access to the standard Java provides an editor editor and access to the standard compiler and run and run- -time system time system . Its innovation lies in its capabilities for . Its innovation lies in its capabilities for creating objects and invoking methods on them interactively creating objects and invoking methods on them interactively (supporting the passing of arguments and return of results). This (supporting the passing of arguments and return of results). Thi s works through a graphical representation of classes works through a graphical representation of classes and and object object instances and simple point instances and simple point- -and and- -click click operation. This lets us operation. This lets us immediately start testing immediately start 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, BlueJ BlueJ provides a mechanism for provides a mechanism for recording recording a series a series Additionally, of interactive tests on a class together with user- -defined defined correct correct of interactive tests on a class together with user results for those tests. These recordings can be for those tests. These recordings can be re re- -run run (with the (with the results results checked automatically) on the class each time the class results checked automatically) on the class each time the class 6 6 code is changed – – regression testing regression testing . . As code is continually As code is continually 6 code is changed r r r e e e t t t p being maintained, this is a huge help! p being maintained, this is a huge help! p a a a h h h C C C

  3. Java without BlueJ t have BlueJ BlueJ ? But what if we don’ But what if we don ’t have ? 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? Write (using any editor editor ) each Java class in a separate file, ) each Java class in a separate file, Write (using any Write (using any editor ) each Java class in a separate file, whose name is the class name with the suffix: .java .java whose name is the class name with the suffix: whose name is the class name with the suffix: .java For example, the Date Date class goes in the file class goes in the file Date.java Date.java For example, the For example, the Date class goes in the file Date.java To compile, we need a command window command window (e.g. (e.g. Command Command To compile, we need a To compile, we need a command window (e.g. Command Prompt in Windows Accessories in Windows Accessories – – or any Unix window). or any Unix window). Prompt Prompt in Windows Accessories – or any Unix window). Change directory ( ( cd cd ) to wherever the ) to wherever the .java .java files are. files are. Change directory Change directory ( cd ) to wherever the .java files are.

  4. Java without BlueJ t have BlueJ BlueJ ? But what if we don’ But what if we don ’t have ? 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? Change directory ( ( cd cd ) to wherever the ) to wherever the .java .java files are. files are. Change directory Change directory ( cd ) to wherever the .java files are. To compile, use the command: javac To compile, use the command: javac Date.java Date.java To compile, use the command: javac Date.java If no errors, this produces the file: Date.class If no errors, this produces the file: Date.class If no errors, this produces the file: Date.class .class files contain files contain Java byte code Java byte code . Don . Don’ ’t try to look at it t try to look at it .class .class files contain Java byte code . Don’t try to look at it – these files don these files don’ ’t hold anything humans can read! t hold anything humans can read! – – these files don’t hold anything humans can read!

  5. Java without BlueJ t have BlueJ BlueJ ? But what if we don’ But what if we don ’t have ? 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? .class files contain files contain Java byte code Java byte code . Don . Don’ ’t try to look at it t try to look at it .class .class files contain Java byte code . Don’t try to look at it – these files don these files don’ ’t hold anything humans can read! t hold anything humans can read! – – these files don’t hold anything humans can read! How do we create class objects objects and execute their and execute their methods methods ? ? How do we create class How do we create class objects and execute their methods ? Java Development Kit (JDK) (JDK) provides no way The standard Java Development Kit The standard Java Development Kit (JDK) provides no way provides no way The standard Java program) to construct (outside of a Java (outside of a Java program) to construct objects ! But it does program) to construct objects objects ! But it does ! But it does (outside of a have a way to invoke a (very particular) (very particular) static static method method – – have a way to invoke a have a way to invoke a (very particular) static method – for which, of course, we only need the class class (not an (not an object object ). ). for which, of course, we only need the for which, of course, we only need the class (not an object ).

  6. Java without BlueJ class DemoMain class DemoMain { { class DemoMain { public static void main public static void main (String[] (String[] args args) ) public static void main (String[] args) { { { } } } } } } Only a static static method called method called main , with exactly the with exactly the Only a main , Only a static method called main , with exactly the above signature , can be run with the standard command. , can be run with the standard command. above signature above signature , can be run with the standard command.

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

  8. Java without BlueJ class DemoMain class DemoMain { { class DemoMain { /** /** /** * Print arguments supplied to this program. * Print arguments supplied to this program. * Print arguments supplied to this program. */ */ */ public static void main (String[] args public static void main (String[] args) ) public static void main (String[] args) { { { for (String s : args for (String s : args) { ) { for (String s : args) { System.out.println (s); System.out.println (s); System.out.println (s); } } } } } } } } } compile compile % % javac % javac % javac javac DemoMain.java javac DemoMain.java javac DemoMain.java DemoMain.java DemoMain.java DemoMain.java % % % % % % javac DemoMain.java % javac DemoMain.java % javac DemoMain.java % % java java DemoMain DemoMain % % % java DemoMain % invoke main invoke main

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend