28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2 ■ Setting Up Your <strong>Java</strong> 8 IDE: An Introduction to NetBeans 8.0<br />

Click the divider line between the code editor pane and the Output tab, at bottom, and, holding down the<br />

mouse button, drag this divider line upward, revealing the Output tab contents, as demonstrated in Figure 2-11.<br />

The Output tab will contain different types of output in NetBeans, such as compile operation output from Ant,<br />

run operation output (shown in the figure), profiler operation output (which you will be exploring in the next section),<br />

and even output from the application itself.<br />

You may have noticed in Figure 2-10 that the code for this bootstrap <strong>Java</strong> 8/<strong>Java</strong>FX application contains a<br />

(System.out.println("Hello World!"); <strong>Java</strong> statement in line 25, so if you wanted to see the application that<br />

you are currently running print to the Output pane (sometimes referred to in programming circles as the Output<br />

Console), click the Say “Hello World” button in the “Hello World!” application (running on top of the IDE).<br />

Once you click this button, “Hello World!” will appear in the Output tab, under the red text that says it is<br />

executing the InvinciBagel.jar file. A .jar (<strong>Java</strong> Archive) file is the distributable format for your <strong>Java</strong> application.<br />

Part of the compile process is creating this file, so if your compiled version works, you can have the .jar file ready to<br />

distribute if your application design and programming are complete!<br />

A .jar file does not contain your actual <strong>Java</strong> 8 code, but rather a compressed, encrypted “<strong>Java</strong> byte stream”<br />

version of the application, which the JRE can execute and run (like NetBeans 8.0 is doing now). The path that is<br />

attached to the front of the InvinciBagel.jar file tells you where the compiled .jar file resides and where NetBeans<br />

is accessing it from currently to run it. On my system this location was C:\Users\user\Documents\NetBeansProjects\<br />

InvinciBagel\dist\run1331700299\InvinciBagel.jar.<br />

Let’s take a look at some of the other Output tab text to see what NetBeans did to get to the point where it could<br />

run the .jar file for this project. First, the compiler deletes and rebuilds the build-jar-properties file, in the<br />

\NetBeansProjects\InvinciBagel\build folder, based on the unique attributes of your game application.<br />

Next, Ant creates a \NetBeansProjects\InvinciBagel\dist\ distribution folder to hold project .jar files and<br />

then, detecting <strong>Java</strong>FX usage, launches ant-javafx.jar to add <strong>Java</strong>FX capabilities to the Ant build engine, which<br />

will create the .jar file. Finally, you will see a warning to change the manifest.custom.codebase property from an<br />

asterisk value (which means “everything”) to a specific value. I may get into the manifest and permissions area of<br />

application development later in the book, after you are a bit more advanced. <strong>Java</strong>FX is then launched, and the<br />

.jar file is built.<br />

Ant is the build engine, or build tool, that creates your .jar file. Other build engines, such as Maven and Gradle,<br />

can also be used in NetBeans, because as you now know, NetBeans is extensible!<br />

Ant is used in the Eclipse IDE as well and is an Apache open-source project that has been around for a very long<br />

time. To learn more about the Ant build system and what it does, visit the Ant web site (http://ant.apache.org).<br />

Next, you will explore the profiling capabilities in NetBeans 8.0, which can analyze your code at runtime and<br />

let you know how efficiently (or inefficiently) your <strong>Java</strong> 8 code is running. This is important for a game, especially an<br />

arcade game or any game that is moving sprites around in real-time on a user’s screen. You will be learning game<br />

concepts and design in Chapter 6 of this book.<br />

Profiling Your <strong>Java</strong> 8 Game Project in NetBeans 8.0<br />

To launch the <strong>Java</strong> 8 code profiling utility, using the Profile menu at the top of the IDE, select Profile Project<br />

(InvinciBagel) (the first menu item), as illustrated in Figure 2-12, or use the Profile Project shortcut icon, which is<br />

visible in the collapsed screen view given in Figure 2-13 (you can tell that I collapsed the screenshot by the <strong>Java</strong> code<br />

line numbering in the code editor pane, which contains only lines 1 and 38, the first and last numbers in the range;<br />

I removed lines 2–37, using Photoshop).<br />

www.it-ebooks.info<br />

31

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!