Blakes 21 Days Experience - Original Day 1 and Appendix A
Day 1, Getting Started with Java
- Sams Teach Yourself Java in 21 Days
- page 000 The page before Page 1 Introduction
- About the Author
- the book's official web site
- then you need to link to 21 Days page
- which have the links to:
- Download JDK 8
- Download NetBeans 8.0.2
- reserve
- page 002 mentions the book's official web site
and NetBeans
- java programming tools such as Eclipse. NetBeans
- Oracle's Java Development Kit
- available for free
- set of command-line tools for writing, compiling and testing Java programs
- reserve
- NetBeans
- source code for all the programs can be found in www.java21days.com | 21days | reserve
- page 006 solutions to exercices and answeres to certification questions can be found in 21days
- page 012 Selecting a Development Tool
- you must have software to edit, prepare, and run Java programs that use the most up to date version of the language Java 8
- Java Development Kit
- NetBeans
- an excelent free IDE
- from www.netbeans.org | NetBeans IDE download page
- used throughout this book
- to get started, read Appendix A
- appendix covers how to download and install the kit and use it to create a simple Java program to make sure it works
- page end with as soon as your ready ...
- page 013 starts out with set up the JDK & NetBeans using Appendix A
- when Appendix A is complete, continue with page 14 of Chapter 1
- which is listed in this document after Appendix A - Second Try's a Charm
- Top
Appendix A - First Try
- Top
- page 597 Appendix A
- reserve
Appendix A - Second Try's a Charm
- Top | Note: the links below do not go to the page listed, link goes to my screenshot for whatever is happening.
- page 597 Appendix A - Fri Jan 6, 2017 the JDK & NetBeans installed successfully.
- page 598 first view of the NetBeans 8.0.2 from the Finders window's Applications choice
- page 598 first view of NetBeans IDE after Splash Screen
- Selected the "New Project" button, the yellow folder with the green plus sign
- Note: it defaults to the "Java" Category on the left and "Java Application" on the right
- page 599 the New Project Window is first displayed
- page 600 Project Name and Project Location
- page 600 Project Location displays the root folder
- in Windows this is a subfolder of My Documents called NetBeansProjects
- on my apple "NetBeansProjects" is under "blakeprupis" as follows: /Users/blakeprupis/NetBeansProjects
- page 600 Project Name enter Java21, note the original name displayed is "JavaApplication1"
- page 600 after changing "Project Name" from JavaApplication1, a default name, to Java21
- page 600 Note that "The Create Main Class" text box changes to respond to the input entered in Project Name
- recommending java21.Java21 as the name of the main Java class in the project.
- page 600 Change this to Spartacus and click the Finish button.
- page 600 after changing "Create Main Class" from java21.Java21 to Spartacus.
- page 600 after pressing the Finish button, the window below is displayed.
- page 600 when NetBeans creates a new project, it sets up all the necessary files and folders and creates starting code for the main class.
- the window above shows the first class in your project, Spartacus open in the source editor
- page 601 Spartacus is a bare-bones Java class that consist of only a main() method.
- all the light grey lines of code in the class are comments that exist to explain the class's purpose and function
- comments are ignored when the class is run.
- page 601 to make the new class do something, add the following line of code on a new line right below the comment // TODO code application logic here:
- system.out.println("I am Spartacus!");
- page 601 the method System.out.println()displays a string of text - in this case, the sentence "I am Spartacus!"
- page 601 Right-clicked "Spartacus.Java" from the Projects Pane and selected "Compile Code" from the submenu.
- page 602 Right-clicked "Spartacus.Java" from the Projects Pane and selected "Run File" from the submenu.
- page 602 I am Spartacus! is displayed in the Output Pane.
- page 603 the book wants us too break the code to see how NetBeans behaves.
- This is the before shot, before I remove the semi-colon I entered with the new line.
- page 603 This is the after shot, after I removed the semi-colon I entered with the new line.
- page 603 By hoovering the mouse cursor to the red warning icon, a warning is displayed inside the yellow Tool Tip.
- page 603 Replacing the semi-colon gets rid of the error warnings.
- note that the "Save All" button is displaying a blue color for it's icon.
- page 603 Replacing the semi-colon gets rid of the error warnings.
- note that the "Save All" button is displaying a grey color for it's icon, indicating all files are saved.
- I also right-cliked Spartacus.java and selected "Run File" from the submenu.
- The Output pane displayed good results again.
- page 604 Expanding and Shrinking a pane
- page 604 double clicking the tab Spartacus.jave has this pane in the entire NetBeams Window
- page 604 double clicking the tab again brings back the other pane's views
- page 605 Oracle offers Training and Documentation resources at www.netbeans.org/kb
- The end of Appendix A
Reserve for the continuation of Chapter One
- Top
- page 014 After successfully completing Appendix A, we go back to Chapter 1
- page 014 An object is a self-contained element of a computer program that represents a related group of features and that is designed to accomplish specific tasks.
- page 015 A class is a template used to create an object. Every object created from the same class has similar features.
- Classes embody all features of a particular set of objects.
- When you write a program in an object-oriented language, you don't define individual objects.
- Instead, you define classes used to create those objects.
- The process of creating an object from a class is called instantiation, which is why objects are also called instances.
- page 016 When you write a Java prgram, you design and construct a set of classes.
- When your progran runs, objects created from those classes and used as needed.
- Your task as a Java programmer is to create the right set of classes to accomplish what your program needs to accomplish.
- page 016 the Java language includes the Java Class Library, more than 4000 classes that implament most of the functionality you will need.
- the class library handles numerious tasks,such as mathematical functions, text, graphics, user interaction, and networking.
- You can create a whole set of classes that reside in their own library.
- page 017 A Java class consists of two distinct types of information: attributes & behavior.
- page 017 Attributes are the data that differentiate one object from another.
- In other words, it's individual properties.
- page 017 Attributes are defined by variables.
- Instance variables are attributes that have values that differ from one object to another.
- page 018 Class variables that shares one value by all objects of that class.
- page 018 Behavior refers to things that a class of objects can do.
- Behavior for a class of objects is implemented using methods.
- page Methods are a group of related statements in a class that perform a specific task.
- Objects communicate with each other by using Methods.
- page 019 Creating a Class by doing this exercise.
- It looks like we can use the same code we created earlier to confirm that the JDK & NetBeans works correctly.
- The following screenshot is the Finder window displaying the folder where Spartacus.java resides
- The path of Spartacus.java - Macintosh HD/Users/blakeprupis/NetBeansProjects/Java21/src/Spartacus.java
Paths to different files
- Laptop / Windows
- C:\Program Files\Java\jdk1.8.0_112\
- C:\Program Files\Java\jre1.8.0_112\
- The path of Spartacus.java - C:\Users\Blake\Documents\NetBeansProjects\Java21\src\Spartacus.java
- iMac / OS X
- The path of the NetBeans installation files - Macintosh HD/Users/blakeprupis/Downloads/netbeans-8.0.2-javase-macosx.dmg
- The path of the application NetBeans 8.0.2 - Macintosh HD/Applications/NetBeans/NetBeans 8.0.2
- The path of Spartacus.java - Macintosh HD/Users/blakeprupis/NetBeansProjects/Java21/src/Spartacus.java
- reserve
Creating the Second Java program from this book
Only do this if you didn't create the last program.
page 019 It will be useful to have a project to hold the classes you create in this book
- Choose the menu command File, New Project. The New Project dialog appears.
- In the Categories pane, choose Java.
- In the Projects pane, choose Java Application and click Next. The New Java Application dialog opens.
- In the Project Name text field, enter the name of the project (I used Java21). The Project Folder field is updated as you type the name. Make a note of this folder, it's where your Java programs can be found on your computer.
- Deselect the check box Create Main Class.
- Click Finish.
page 020 To begin your first class, run NetBeans and start a new prgram.
- Choose the menu command File, New File. The New File dialog appears.
- In the Categories pane, choose Java.
- In the File Types pane, choose Empty Java File and click Next. The Empty Java File dialog opens.
- In the Class Name text field, enter MarsRobot. The file you're creating is shown in the Created File field, which can't be edited. This file has the name MarsRobot.java.
- Click Finish.
- page 020 The NetBeans source code editor opens with nothing in it.
- page 020 Fill it with the code in Listing 1.1. When you're done, save the file using the menu command File, Save. The file MarsRobot.java will be saved.
- class MarsRobot {
- String status;
- int speed;
- float temperature;
-
- void checkTemperature() {
- if (Temperature < -80) {
- status = "return home";
- speed = 5;
- }
- }
-
- void showAttributes() {
- System.out.println("Status: " + status);
- System.out.println("Speed: " + speed);
- System.out.println("Temperature: " + temperature);
- }
- }
Screenshots for the instructions above
"File" from the menu bar, "New File" from the submenu.
The "New File" dialog box
The "New File" dialog box
The "New Empty Java File" dialog box
- Top | Starting MarsRobot coding | Continue Chapter 1
- Note that Class name displays NewEmpty
- Project displays Java21
- Location displays Source Packages
- Created File is pointing to Users/blakeprupis/NetBeansProjects/Java21/src/NewEmpty.java
The "New Empty Java File" dialog box
The MarsRobot.java tab is created & displayed
after typing in the code, note line 7 "Temparature" should not be capitalized
Getting ready to save
The "Save All" button is now greyed out
Fixing my Typo
- page 021 When you save this file, if it has no errors, NetBeans automatically creates a MarsRobot class.
- This process is called compiling the class, and it uses a tool called a compiler.
- The compiler turns the lines of code into bytecode that the Java Virtual Machine can run.
About the MarsRobot Class
- page 021 The class statement in line 1 defines and names the MarsRobot class.
- Everything contained between the opening brace on Line 1 to the closing brace on Line 18 is part of this class.
About the Three Instance Variables
- page 021 The MarsRobot class contains three instance variables and two instance methods.reserve
- The instance variables are described in lines 2 thru 4
String status;
int speed;
float temerature;
- page 021 Each of these three variables store different types of information.
- status holds a String object, a group of letters, numbers, punctuation, and other characters
- String objects are created from the String class, which is part of the Java Class Library
- speed holds an int, a numberic integer value
- temperature holds a float, a floating-point number
Page 21 - The First Instance Method ...
- Top | Starting MarsRobot coding | Continue Chapter 1
- page 021 The first instance method in the MarsRobot class is defined below
void checkTemperature () {
if (temperature < -80) {
status = "return home";
speed = 5;
}
}
- page 021 Methods are defined in a manner similar to a class
- They begin with a statement that names the method,
- identifies the type of information the method produces,
- and defines other things.
- Page 22
- page 022 The checkTemperature() method is contained with the opening brace on line 6 and the closing brace on line 11.
- This method can be called on a MarsRobot object to find out its temperature.
- page 022 This method checks to see wheather the object's temperature instance variable has a value less than -80.
- If it does, two other instance variables are changed
- The status variable is changed to the text "return home"
- indicating that the temperature is too cold , and the robot is heading back to its base.
- The speed is changed to 5
- presumably, this is the fastest the robot can travel.
Page 22 - The Second Instance Method ...
- Top | Starting MarsRobot coding | Continue Chapter 1
- page 022 The second instance method, showAttributes() is defined in lines 13 thru 17
void showAttributes() {
System.out.println("Status: " + status);
System.out.println("Speed: " + speed);
System.out.println("Temperature: " + temperature);
}
- This method calls the method System.out.println()
- to display the values of three instance variables, along with some text explaining what each value represents.
- reserve
Time to save the file if you haven't done so.
Why You Cannot Run This Program
Two ways to put MarsRobot to use
- page 022 There are two ways to put MarsRobot class to use
- Create a separate Java program that creates an object belonging to that class
- Add a special class method called main() to the MarsRobot class so that it can be run as an application.
- Create an object of that class in that method.
The first option is chosen for this exercise
- page 022 Listing 1.2 contains the source code for MarsApplication, a Java class that creates a MarsRobot object,
- sets its instance variables
- and calls methods.
- page 022 Following the same steps as in the proceding listing, create a new Java file in NetBeans and name it MarsApplication
To begin the second class follow these steps in NetBeans.
- Choose File, New File from the menu. The New File dialog opens.
- In the Category pane choose Java
- In the File Types pane, choose Empty Java File and click Next. The Empty Java File dialog opens
- In the Class Name text field, enter MarsApplication. The file you're creating is shown in the Created File field and has the name MarsApplication.java.
- Click Finish.
Listing 1.2
class MarsApplication {
public static void main(String[] arguments) {
MarsRobot spirit = new MarsRobot();
spirit.status = "exploring";
spirit.speed = 2;
spirit.temperature = -60;
spirit.showAttributes();
System.out.println("Increasing speed to 3.");
spirit.speed = 3;
spirit.showAttributes();
System.out.println("Changing temperature to -90.");
spirit.temperature = -90;
spirit.showAttributes();
System.out.println("Changing the temperature.");
spirit.checkTemperature();
spirit.showAttributes();
}
}
- page 023 When you choose File, Save to save the file
- NetBeans automatically compiles it into the MarsApplication class
- which contains bytecode for the JVM to run.
- page 023 (TIP) you can find the source copy of the programs at the book's official website www.java21days.com
Run the Program
- Top
- page 024 after a successful compile, run the program
- the output is displayed in the Output pane
- its the output of the MarsApplication class
- below is the FIGURE 1.1 from page 24 displaying the Output pane
When I run the program I get the wrong output.
- Scroll down a little to view the correct output.
Now I have the correct output.
Displaying the Java code for the MarsApplication: Program or Class
- Top
- below is the LISTING 1.2 from page 23 displaying what should be in the source code pane
About the Java code for the MarsApplication: Program or Class
- Top | Back to Chap 5: Defining Instance Variables
- page 024 & 025 describes the MarsApplication Class or Program in more detail
- Line 2 - The main() method is created and named.
- All main() methods take this format
- the static keyword, indicates that the method is a class method shared by all MarsRobot objects
- Line 3 - A new MarsRobot object is created using the class as a template.
- the object is given the name spirit
- Lines 4-6 - Three instance variables of the spirit object are given values:
- status is set to text "exploring"
- speed is set to 2
- temperature is set to -60
- Line 8 - on this line and several that follow, the showAttributes() method of the spirit object is called
- this method displays the current values of the instance variables status, speed, and temperature.
- Line 9 - on this line and others that follow, a call to the System.out.println() method displays the text within parenthese to the output device (your monitor)
- Line 10 - the speed instance variable is set to the value of 3
- Line 13 - the temperature instance variable is set to the value of -90
- Line 16 - the checkTemperature method of the spirit object is called.
- this method checks to see whether the temperature instance variable is less than -80
- if it is, status and speed are assigned new values
Organizing Classes and Class Behavior
- Top
- page 025 Object-oriented programming in Java also requires three more concepts
- inheritance
- interfaces
- packages
- All three are mechanisms for organizing classes and class behavior
Inheritance - is a mechanism that enables one class to inhert the behavior and attributes of another class
- Top
- page 025 Inheritance, one of the most crucial concepts in object-oriented programming, has a direct impact on how you design and write your own Java classes.
- page 025 Inheritance is a mechanism that enables one class to inhert the behavior and attributes of another class
- page 025 Through Inheritance, a class automatically picks up the functionality of an existing class.
- The new class must only define how it is different from that existing class.
- page 025 With inheritance, all classes - including those you create and the ones in the Java Claa Library - are arranged in a strict hierarchy.
- page 025 A class that inherits from another class is called a subclass
- The class that gives the inheritance is called a superclass.
- page 025 A class can have only one superclass, but it can have an unlimited number of subclasses.
- Subclasses inherit all the attributes and behavior of their superclass.
- page 025 the class you create becomes a combination of its own features and all the features of the classes above it in the hierarchy,
- page 026 At the top of the Java class hierarchy is the class Object.
- page 026 All classes inherit from this superclass.
- Object is the most general class in the hierarchy.
- It defines behavior by all classes in the Java Class Library.
- page 027 Subclassing is the creation of a new class that inherits from an existing class.
- Subclassing is the mechanismfor defining new classes as the differences between those classes and their superclass.
- The only task in the subclass is to indicate the differences in behavior and attributes between the subclass and its superclass
- page 027 if you create a class that doesn't indicate a superclass, Java assumes that the new class inherits directly from Object.
- The MarsRobot class you created earlier did not specify a superclass, so it's a subclass of Object.
- page 027 Creating a Class Hierarchy
- If you're creating a large set of classes, it makes sence for your classes to inherit from the existing class hierarchy and to make up a hierarchy themselves.
- This gives your classes several advantages
- Functionality common to multiple classes can be put into a superclass, which enables it to be used repeatedly in all classes below it in the hierarchy.
- Changes to a superclass automatically are reflected in all its subclasses. There is no need to change or recompile any lower classes, they receive the new information through inheritance.
- for example ...
- page 030 Overiding when a method of the same name occurs in a subclass of a superclass.
- This works because Java searches from the bottom up in a hierarchy, until it finds the method's name.
- Any method with the same name that is further up in the hierarchy is ignored.
- reserve
- reserve
Interfaces - is a collection of methods that indicate a class has some behavior in addition to what it inherits from its superclasses
- Top
- page 031 Single inheritance makes the relationship netween classes and the functionality they implement easier to understand and design.
- However, it also can be restrictive, especially when you have similar behavior that needs to be duplicated across different branches of a class hierarchy.
- Java solves the problem of shared behavior by using interfaces.
- page 031 An interface is a collection of methods that indicate a class has some behavior in addition to what it inherits from its superclasses.
- The methods included in an interface do not define this behavior;
- that task is left for the classes that implement the interface.
- page 032 for example:
- The Comparable interface contains a method that compares two objects of the same class to see which one should appear first in a sorted list.
- Any class that implements this interface shows objects that it knows how to determine the sorting order for objects of that class.
- This behavior would be unavailable to the class without the interface
- page 032 More on Interfaces in Day 6, "Packages, Interfaces, and Other Class Features."
- note: I'm guessing it's a separate file using java code to create the method or methods.
Packages - enable groups of classes to be referrenced more easily in other classes
- Top
- page 032 Packages in Java are a way to group related classes and interfaces.
- Packages enable groups of classes to be referrenced more easily in other classes.
- They also eliminate potential naming conflicts among classes.
- page 032 Classes in Java can be referred to by a short name such as Object or a full name such as java.lang.Object
- page 032 by default, your Java classes can refer to the classes in the java.lang package using only short names.
- The java.lang package provides basic language features such as string handling and mathematical operations.
- To use classes from any other package, you must refer to them explicitly using their full package name or use the import command to import the package in your source code.
- page 032 Because the Color class is contained in the java.awt package, you normally refer to it in your programs with the notation java.awt.Color.
- page 032 If the entire java.awt package has been imported using import, the class can be referred to as Color.
- page 032 The package for a class is determined by the package statement.
- Many of the classes you create in this book are put in the com.java24hours package like so: package com.java24hours;
- page 032 the package statement must be the first line of the program.
- When it is omitted, as it was in the MarsRobot and MarsApplication programs you recently created,
- the class belongs to an unnamed package called the default package.
- reserve
Summary
- Top
- 032 first exposure to object-oriented programming.
- 033 At this point, you should have a basic understanding of classes, objects, attributes, and behavior. You also should be familiar with instance variables and methods.
- 033 by the time you finish the first week, you'll have working experience with objects, classes, inheritance, and all other aspects of the technology.
Q&A
- Top
- 033 Q Methods are functions defined inside classes. If they look like functions and act like functions, why aren't they called functions?
- 033 A Some object-oriented programming languages do call them functions. (C++ calls them member functions.)
- Other object-oriented languages differentiate between functions inside and outside the body of a class or object because in those languages the use of the separate terms is important to understanding how each function works.
- Because the difference is relevant in other languages and because the term method now is in common use in object-oriented terminology, Java uses the term as well.
- 033 Q What's the distinction between instance variables and methods and their counterparts, class variables and methods?
- 033 A Almost everything you do in a Java program involves instances (also called objects) rather than classes.
- However, some behavior and attributes make more sense if stored in the class itself rather than in the object.
- For example, the Math class in the java.xxng package (the dot extension file is unreadable) includes a class variable called PI that holds the approximate value of pi.
- This value does not change, so there's no reason why different objects of that class would need their own individual copy of the PI variable.
- On the other hand, every String object contains a method called length() that reveals the number of characters in that String.
- This value can defferent for each object of that class, so it must be an instance method.
- Class variables occupy memory until a Java program is finished running, so they should be used with care.
- If a class variable references an object, that object will remain in memory as well.
- This is a common problem causing a program to take up too much memory and run slowly.
- 034 Q When a Java class imports an entire package, does it increase the compiled size of that class?
- 034 A No. The use of the term "import" is a bit misleading.
- The import keyword does not add the bytecode of one class or one package to the class you are creating.
- Instead, itmakes it easier to refer to classes within another class.
- The sole purpos of importing is to shorten the class names when they're used in Java statements
- It would be cumbersome to always have to refer to full class names such as javax.swing.JButton and java.awt.Graphics in your code instead of calling them JButton and Graphics.
Quiz
- Top
- Review today's material by taking this three-question quiz.
Questions
- What is another word for class?
- Object
- Template
- Instance
- When you create a subclass, what must you define about that class?
- Nothing. Everything is defined already.
- Things that are different from its superclass
- Everything about the class
- What does an instance method of a class represent?
- The attributes of that class
- The behavior of that class
- The behavior of an object created from that class
- reserve
Answers
- B. A class is an abstract template used to create objects that are similar to each other.
- B. You define how the subclass is different from its superclass.
- The things that are similar are already defined for you because of inheritance.
- Answer A is technically correct, but if everything in the subclass is identical to the superclass, there's no reason to create the subclass.
- C. Instance methods refer to a specific object's behavior. Class methods refer to the behavior of all objects belonging to that class.
Certification Practice
- Top
- The following question is the kind of thing you could expect to be asked on a Java programming certification test. Answer it without looking at today's material.
- Which of the following statements are true? The answers are available online.
- All objects created from the same class must be identical.
- All objects created from the same class can have different attributes than each other.
- An object inherits attributes and behavior from the class used to create it.
- A class inherits attributes and behavior from its subclass.
Exercises
- Top
- To extend your knowledge of the subjects covered today, try the following exercises:
- The solutions available online.
- In the main() method of the MarsRobot class, create a second MarsRobot robot named opportunity, set up its instance variables, and display them.
- Create an inheritance hierarchy for the pieces of a chess set.
- Decide where the instance variables color, startingPosition, forwardMovement, and sideMovement should be defined in the hierarchy.
End of Day One
Download JDK 8 - Not Successful
Safari
Firefox
Questions that I answered for "Java SE Development Kit 8 Downloads" using the Firefox browser on my Apple
- for my apple
- do I select Mac OS X for 8U111 or 8U112
- I choosed Mac OS X for 8U112
- I was able to download the JDK from Oracle, then downloaded NetNeans 8.0.2 SE using the Safari browser
- then there is 8U111 or 8U112 Demos and Samples Downloads
- I would now need to use the 8U112 version since I selected that version for the JDK
- reserve
- for my laptop - haven't tried yet
- do I select Windows x86 or Windows x64 for 8U111 or 8U112
- then there is 8U111 or 8U112 Demos and Samples Downloads for Windows x86 or Windows x64
Download NetBeans - Not Successful
- Top
- The reason it wasn't successful was because I did motinstall the JDK from Oracle first.
Another Failure
- Are we suppose to run the other link first
- or just beef up version 7 ?
Java SE Development Kit 8 Downloads (8u112 for Mac OS X) - Success
Downloaded NetBeans IDE 8.0.2 using Java SE - Success
Using NetBeans
- Top | Appendix A
- page 598 first view of the NetBeans 8.0.2 from the Finders window's Applications choice
- the Finder window with Applications choosen, there's NetBeans 8.0.2
Splash Screen
- Top | Appendix A
- first view of the Splash Screen after selecting NetBeans 8.0.2 from the Finders window.
- the Splash screen for NetBeans 8.0.2
first view of NetBeans
- Top | Appendix A
- page 598 first view of NetBeans IDE after Splash Screen
- first time seeing NetBeans 8.0.2 on my Apple
- Selected the "New Project" button, the yellow folder with the green plus sign
- Note: it defaults to the "Java" Category on the left and "Java Application" on the right
New Project window
- Top | Appendix A
- page 599 the New Project Window is first displayed
- Top | Appendix A
- page 600 the book wants me to select the "Next" button
Name and Location
- Top | Appendix A
- page 600 Project Location displays the root folder
- in Windows this is a subfolder of My Documents called NetBeansProjects
- on my apple "NetBeansProjects" is under "blakeprupis" as follows: /Users/blakeprupis/NetBeansProjects
- page 600 Project Name enter Java21, note the original name displayed is "JavaApplication1"
After changing "Project Name"
- Top | Appendix A
- page 600 after changing "Project Name" from JavaApplication1, a default name, to Java21
- Top | Appendix A
- page 600 Note that "The Create Main Class" text box changes to respond to the input entered in Project Name
- recommending java21.Java21 as the name of the main Java class in the project.
- page 600 Change this to Spartacus and click the Finish button.
After changing "Create Main Class"
- Top | Appendix A
- page 600 after changing "Create Main Class" from java21.Java21 to Spartacus.
view code for first time
- Top | Appendix A
- page 600 after pressing the Finish button, the window below is displayed.
- Top | Appendix A
- page 600 when NetBeans creates a new project, it sets up all the necessary files and folders and creates starting code for the main class.
- the window above shows the first class in your project, Spartacus open in the source editor
- page 601 Spartacus is a bare-bones Java class that consist of only a main() method.
- all the light grey lines of code in the class are comments that exist to explain the class's purpose and function
- comments are ignored when the class is run.
- page 601 to make the new class do something, add the following line of code on a new line right below the comment // TODO code application logic here:
- system.out.println("I am Spartacus!");
- page 601 the method System.out.println()displays a string of text - in this case, the sentence "I am Spartacus!"
after inserting new line of code
Compile Code
- Top | Appendix A
- page 601 Right-clicked "Spartacus.Java" from the Projects Pane and selected "Compile Code" from the submenu.
Run File
- Top | Appendix A
- page 602 Right-clicked "Spartacus.Java" from the Projects Pane and selected "Run File" from the submenu.
Output Pane first appears
- Top | Appendix A
- page 602 I am Spartacus! is displayed in the Output Pane.
- Top | Appendix A
- The end of testing NetBeans and verifying that the JDK & NetBeans had a proper install.
Fixing Errors
the Before shot
- Top | Appendix A | Fixing Errors
- page 603 the book wants us too break the code to see how NetBeans behaves.
- This is the before shot, before I remove the semi-colon I entered with the new line.
- reserve
the After shot
The yellow Tool Tip
- Top | Appendix A | Fixing Errors
- page 603 By hoovering the mouse cursor to the red warning icon, a warning is displayed inside the yellow Tool Tip.
replacing the semi-colon gets rid of the error warnings
- Top | Appendix A | Fixing Errors
- page 603 Replacing the semi-colon gets rid of the error warnings.
- note that the "Save All" button is displaying a blue color for it's icon.
- reserve
after "Saving All" button pressed and "Run File" selected
- Top | Appendix A | Fixing Errors
- page 603 Replacing the semi-colon gets rid of the error warnings.
- note that the "Save All" button is displaying a grey color for it's icon, indicating all files are saved.
- I also right-cliked Spartacus.java and selected "Run File" from the submenu.
- The Output pane displayed good results again.
- reserve
Opening Sparticus.java to see the code
Sparticus.java displayed in the Projects pane, Start Page tab has focus
Sparticus.java displayed with it's submenu
Sparticus.java code is revealed
Creating a NetBeans alias and placing it into the Dock
- Top
- Right-click NetBeans 8.0.2 from the Finder Window
- and select "Make Alias" from the submenu
- the alias is placed in the same folder as NetBeans 8.0.2
- folder name and path: Applications/NetBeans
- Drag and drop "NetBeans 8.0.2 alias" onto the Dock
- the original "NetBeans 8.0.2 alias" from the NetBeans folder is still there
- the Cube icon is displayed in the Dock
- reserve
Expanding and Shrinking a pane
- Top | Appendix A | Fixing Errors
- The Normal view. 4 panes are displayed
- Project, Navigater, source editor / java programing code, Output panes
- we will do the following exercise
- page 604 double clicking the tab Spartacus.jave has this pane in the entire NetBeams Window
- page 604 double clicking the tab again brings back the other pane's views
- reserve
Expanding and Shrinking a pane
- Top | Appendix A | Fixing Errors
- page 604 double clicking the tab Spartacus.jave has this pane in the entire NetBeams Window
- Note the other Panes or Tabs are listed Vertically on the left side of the window.
- reserve
Expanding and Shrinking a pane
Install the Java SE Development Kit 8u112 for Windows x64 on my Laptop
- Top
- page xxx my laptop has a 64 bit processor
- reserve
- from the File Manager screen
- Path: Downloads/jdk-8u112-windows-x64.exe - This is the downloaded file used to install the JDK
- the jdk will use this path: C:\Program Files\Java\jdk1.8.0_112\
- preparing for the installation
- preparing for the installation
- Note the path: C:\Program Files\Java\jre1.8.0_112
- Running the JDK Installation
- Java SE Development Kit 8 Update 112 (64-bit) Successfully Installed on my Laptop
Installing NetBeans on the Laptop
- I will select Java SE Download for NetBeans IDE 8.0.2 Download
- note the incomplete file name: netbeans-8.0.2-jav.....exe
- from the File Manager screen
- path: Downloads/netbeans-8.0.2-javase-windows
- a couple of screens just wizzed by, then this screen got displayed
- note that this screen says: The installer will install the NetBeans IDE with the Java SE pack.
Installation Folders
- Install the NetBeans IDE to:
- C:\Program Files\NetBeans 8.0.2
- JDK for the NetBeans IDE:
- C:\Program Files\Java\jdk1.8.0_112
- reserve
- Summary screen displayed with the Install button to continue the installation.
- Installation is happening.
Setup Complete
First time viewing Netbeans on my Laptop
NetBeans seen from the Start Button
NetBeans seen from the Desktop
The Splash screen
The New Project button
After clicking the Next button
Changing Project Name
Changing Name to Create Main Class
First time seeing code
Adding the line of code
- Top
- I actually had an error until I capitalized System
Compiling the Java Code
Run File
After updating OS X, to run Dreamwaeaver CS6, I had to do the following
From Version 23
- set up Java on laptop & iMac
Back to the Top ?