Java in 24 Hours, Sams Teach Yourself (Covering Java 9) by Cadenhead Rogers
Author:Cadenhead, Rogers [Cadenhead, Rogers]
Language: eng
Format: azw3
ISBN: 9780134663630
Publisher: Pearson Education
Published: 2017-09-08T04:00:00+00:00
FIGURE 15.1
The output of the PrimeFinder application.
Most statements in the application are used to look for prime numbers. The following statements are used to implement threads in this program:
Line 3—The Runnable interface is applied to the PrimeFinder class.
Line 4—A Thread object variable is created with the name go but isn’t assigned a value.
Lines 22–25—If the go object variable has a value of null, which indicates the thread hasn’t been created yet, a new Thread object is created and stored in the variable. The thread is started by calling the thread’s start() method, which causes the run() method of the PrimeFinder class to be called.
Lines 28–44—The run() method looks for a sequence of prime numbers beginning with 2, storing each one in the primes string buffer by calling its append() method.
There’s something unusual in the main() method of this application when a PrimeFinder object is created to begin execution of the program. Here’s the statement:
new PrimeFinder();
Normally you’d expect to see that object assigned to a variable, like so:
Click here to view code image
PrimeFinder frame = new PrimeFinder();
However, because there’s no need to refer to that object again, storing it in a variable is not necessary. Calling new to create the object causes the program to run.
It’s a good programming practice in Java to store objects in variables only when those objects are needed after their creation.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9914)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9795)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8296)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6825)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6555)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6421)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Kotlin in Action by Dmitry Jemerov(5062)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4316)
Functional Programming in JavaScript by Mantyla Dan(4038)
Solidity Programming Essentials by Ritesh Modi(3995)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3786)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3730)
The Ultimate iOS Interview Playbook by Avi Tsadok(3705)
