1 / 25

First Java Program with NetBeans

First Java Program with NetBeans. Computing Department University of Surrey Amir r Razavi. Contents. Introduction Setting Up a Project Creating a new Java class library Creating a new Java application Configuring the compilation classpath Creating and Editing Java Source Code

coopera
Download Presentation

First Java Program with NetBeans

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. First Java Program with NetBeans Computing Department University of Surrey Amir r Razavi

  2. Contents • Introduction • Setting Up a Project • Creating a new Java class library • Creating a new Java application • Configuring the compilation classpath • Creating and Editing Java Source Code • Creating a Java package and class file • Editing a Java file • Finding all usages of a class name • Compiling and Running a Project • Setting the main class and execution arguments • Running the main project • Modifying for Image Processing

  3. Introduction • Using NetBeans IDE • Following the standard Java by NetBeans • Image Processing by NetBeans • Free Full Software and Proper Documentations and support http://www.netbeans.org/

  4. Creating a new Java class library • Choose File > New Project (Ctrl-Shift-N).

  5. Creating a new Java class library • Under Categories, select General. Under Projects, select Java Class Library and click Next

  6. Creating a new Java class library • Under Project Name, enter MyLib. Change the Project Location to any directory on your computer.

  7. Creating a new Java application • Choose File > New Project. Under Categories, select General. Under Projects, select Java Application and click Next

  8. Creating a new Java application • Under Project Name, enter MyProg1.

  9. Configuring the compilation classpath • Right-click the MyProg1 project in the Projects window and choose Properties.

  10. Configuring the compilation classpath • Select Compiling Sources and click Add Project.

  11. Configuring the compilation classpath • Select the MyLib project folder. The Project JAR Files pane shows the JAR files that can be added to the project. Notice that it shows a JAR file for MyLib even though we have not actually built the JAR file yet. This JAR file will get built when we build and run the MyApp project. Click Add Project JAR Files.

  12. Creating a Java package and class file • Expand the MyLib project node. Right-click the Source Packages node and choose New > Java Class. Name the class LibClass, type org.me.mylib in the Package field, and click Finish. LibClass.java opens in the Source Editor.

  13. Creating a Java package and class file • In LibClass.java, place the caret on the line between the class declaration (public class LibClass {) and the constructor (public LibClass() {). Type or paste in the following method code:

  14. Editing a Java file • Select the Main.java tab in the Source Editor. • Delete the // TODO comment in the main method and type the following: • String result = LiPress Ctrl-Space to open the code completion box. The project offers code completion for all classes and methods in the project's compilation classpath. Select LibClass and press Enter.

  15. Editing a Java file • Press Alt-Shift-I to create an import statement for org.me.mylib.LibClass.

  16. Editing a Java file • Enter a period after LibClass. The code completion box opens again. Select the acrostic method to see popup Javadoc for the method. Enter the acrostic method with its default argument: args, then type a closing parenthesis and semicolon. The final line should look like this: • String result = LibClass.acrostic(args);

  17. Editing a Java file • Press Enter to start a new line. Then type sout and press space. The sout abbreviation expands to System.out.println(""); with the caret between the quotation marks. Type Result = inside the quotation marks and + result after the quotation marks. The final line should look like this: System.out.println("Result = " + result);

  18. Finding all usages of a class name

  19. Setting the main class and execution arguments

  20. Running the main project • Choose Run > Run Main Project (F6) from the Run menu. Double-click the Output window to maximize it so you can see all the output. Note that Ant builds MyLib.jar first and then compiles MyApp using it. Finally, it prints the output from the program, Result = Hello (the acrostic of the phrase that was passed to the program as an argument).

  21. Modifying for Image Processing

  22. Modifying for Image Processing

  23. Modifying for Image Processing

  24. Modifying for Image Processing

  25. Modifying for Image Processing

More Related