All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Hire a Tutor
AI Study Help
New
Search
Search
Sign In
Register
study help
computer science
java programming
Questions and Answers of
Java Programming
In Java, a program with a graphical user interface has more than one thread. Explain how you can prove that.
Why is the stop method for stopping a thread deprecated? How do you terminate a thread?
Give an example of why you would want to terminate a thread.
Suppose you surround each call to the sleep method with a try/catch block to catch an InterruptedException and ignore it. What problem do you create?
What is a race condition? How can you avoid it?
Consider the ArrayList implementation from Section 16.2. Describe two different scenarios in which race conditions can corrupt the data structure.
Consider a stack that is implemented as a linked list, as in Section 16.3.1. Describe two different scenarios in which race conditions can corrupt the data structure.
Consider a queue that is implemented as a circular array, as in Section 16.3.4.Describe two different scenarios in which race conditions can corrupt the data structure.
What is a deadlock? How can you avoid it?
What is the difference between a thread that sleeps by calling sleep and a thread that waits by calling await?
What happens when a thread calls await and no other thread calls signalAll or signal?
In the algorithm animation program of Section 22.6, we do not use any conditions. Why not?Data from section 22.6
Write a program in which multiple threads add and remove elements from a java.util.LinkedList. Demonstrate that the list is being corrupted.
Implement a stack as a linked list in which the push, pop, and isEmpty methods can be safely accessed from multiple threads.
Implement a Queue class whose add and remove methods are synchronized. Supply one thread, called the producer, which keeps inserting strings into the queue as long as there are fewer than ten
Enhance the program of Exercise ••• E22.3 by supplying a variable number of producer and consumer threads. Prompt the program user for the numbers.Data from exercise 22.3Implement a Queue class
Reimplement Exercise • E22.4 by using the ArrayBlockingQueue class from the standard library.Data from exercise E22.4 Enhance the program of Exercise ••• E22.3 by supplying a
Modify the ArrayList implementation of Section 16.2 so that all methods can be safely accessed from multiple threads.Data from section 16.2
Write a program WordCount that counts the words in one or more files. Start a new thread for each file. For example, if you call java WordCount report.txt address.txt Homework.java then the program
Enhance the program of Exercise •• E22.7 so that the last active thread also prints a combined count. Use locks to protect the combined word count and a counter of active threads.Data
Add a condition to the deposit method of the BankAccount class in Section 22.5, restricting deposits to $100,000 (the insurance limit of the U.S. government). The method should block until sufficient
Write a program Find that searches all files specified on the command line and prints out all lines containing a reserved word. Start a new thread for each file. For exam ple, if you call java Find
Implement the merge sort algorithm of Chapter 14 by spawning a new thread for each smaller MergeSorter. Use the join method of the Thread class to wait for the spawned threads to finish. Look up the
Write a program that shows two cars moving across a window. Use a separate thread for each car.
Modify Exercise •• Graphics P22.3 so that the cars change direction when they hit an edge of the window.Data from graphics P22.3 Write a program that shows two cars moving across a window. Use
Enhance the SelectionSorter of Section 22.6 so that the current minimum is painted in yellow.Data from section 22.6
Enhance the SelectionSortViewer of Section 22.6 so that the sorting only starts when the user clicks a “Start” button.Data from section 22.6
Instead of using a thread and a pause method, use the Timer class introduced in Section 10.9 to ani mate an algorithm. Whenever the timer sends out an action event, run the algorithm to the next step
Implement an animation of the merge sort algorithm of Chapter 14. Reimplement the algorithm so that the recursive calls sort the elements inside a subrange of the original array, rather than in their
Enhance Exercise ••• Graphics P22.8 so that it shows two frames, one for a merge sorter and one for a selection sorter. They should both sort arrays with the same values.Data from exercise
Reorganize the code of the sorting animation in Section 22.6 so that it can be used for generic animations.Provide a class Animated with abstract methods public void run() public void draw (Graphics
What is the IP address of the computer that you are using at home? Does it have a domain name?
Can a computer somewhere on the Internet establish a network connection with the computer at your home? If so, what information does the other computer need to establish the connection?
What is a port number? Can the same computer receive data on two different ports?
What is a server? What is a client? How many clients can connect to a server at one time?
What is a socket? What is the difference between a Socket object and a ServerSocket object?
Under what circumstances would an UnknownHostException be thrown?
What happens if the Socket constructor’s second argument is not the same as the port number at which the server waits for connections?
When a socket is created, which of the following Internet addresses is used?a. The address of the computer to which you want to connectb. The address of your computerc. The address of your ISP
What is the purpose of the accept method of the ServerSocket class?
After a socket establishes a connection, which of the following mechanisms will your client program use to read data from the server computer?a. The Socket will fill a buffer with bytes.b. You will
Why is it not common to work directly with the InputStream and OutputStream objects obtained from a Socket object?
When a client program communicates with a server, it sometimes needs to flush the output stream. Explain why.
Try out the HEAD command of the HTTP protocol. What command did you use?What response did you get?
Connect to a POP server that hosts your e-mail and retrieve a message. Provide a record of your session (but remove your password). If your mail server doesn’t allow access on port 110, access it
How can you communicate with a web server without using sockets?
What is a URL? How do you create an object of class URL? How do you connect to a URL?
Modify the WebGet program to print only the HTTP header of the returned HTML page. The HTTP header is the beginning of the response data. It consists of several lines, such as HTTP/1.1 200 OK Date:
Modify the WebGet program to print only the title of the returned HTML page. An HTML page has the structure ... ... For example, if you run the program by typing at the command line java WebGet
Modify the BankServer program so that it can be terminated more elegantly. Provide another socket on port 8889 through which an administrator can log in. Support the commands LOGIN password, STATUS,
Modify the BankServer program to provide complete error checking. For example, the program should check to make sure that there is enough money in the account when withdraw ing. Send appropriate
Write a program to display the protocol, host, port, and file components of a URL. Look at the API documentation of the URL class.
Write a client application that executes an infinite loop thata. Prompts the user for a number.b. Sends that value to the server.c. Receives a number from the server.d. Displays the new number.Also
Implement a client-server program in which the client will print the date and time given by the server. Two classes should be implemented: DateClient and DateServer.The DateServer simply prints new
Write a simple web server that recognizes only the GET request (without the Host:request parameter and blank line). When a client connects to your server and sends a command, such as GET filename
Write a chat server and client program. The chat server accepts connections from clients. Whenever one of the clients sends a chat message, it is displayed for all other clients to see. Use a
A query such as http://aa.usno.navy.mil/cgi-bin/aa_moonphases.pl?year=2011 returns a page containing the moon phases in a given year. Write a program that asks the user for a year, month, and day and
A page such as http://www.nws.noaa.gov/view/states.php contains links to pages showing the weather reports for many cities in the fifty states.Write a program that asks the user for a state and city
A page such as: https://www.cia.gov/library/publications/the-world-factbook/geos/ countrytemplate_ca.html contains information about a country (here Canada, with the symbol ca-see
Design a set of database tables to store people and cars. A person has a name, a unique driver license number, and an address. Every car has a unique vehicle identification number, manufacturer,
Design a set of database tables to store library books and patrons. A book has an ISBN (International Standard Book Number), an author, and a title. The library may have multiple copies of each book,
Design a set of database tables to store sets of coins in purses. Each purse has an owner name and a unique ID. Each coin type has a unique name and a value. Each purse contains some quantity of
Design a set of database tables to store students, classes, professors, and classrooms.Each student takes zero or more classes. Each class has one professor, but a profes sor can teach multiple
Give SQL commands to create a Book table, with columns for the ISBN, author, and title, and to insert all textbooks that you are using this semester.
Give SQL commands to create a Car table, with columns for the vehicle identification number, manufacturer, model, and year of each car, and to insert all cars that your family members own.Exercises
Give a SQL query that lists all products in the invoice database of Section 24.2. Invoice Invoice_ Number INTEGER 11731 11732 11733 Customer_ Number INTEGER 3175 3176 3175 Payment DECIMAL (10, 2) 0
Give a SQL query that lists all customers in California. Invoice Invoice_ Number INTEGER 11731 11732 11733 Customer_ Number INTEGER 3175 3176 3175 Payment DECIMAL (10, 2) 0 249.50 0
Give a SQL query that lists all customers in California or Nevada. Invoice Invoice_ Number INTEGER 11731 11732 11733 Customer_ Number INTEGER 3175 3176 3175 Payment DECIMAL (10, 2) 0 249.50 0
Give a SQL query that lists all customers not in Hawaii. Invoice Invoice_ Number INTEGER 11731 11732 11733 Customer_ Number INTEGER 3175 3176 3175 Payment DECIMAL (10, 2) 0 249.50 0
Give a SQL query that lists all customers who have an unpaid invoice. Invoice Invoice_ Customer Payment Number Number INTEGER INTEGER DECIMAL(10, 2) 11731 3175 0 11732 3176 249.50 11733 3175 0
Give a SQL query that lists all products that have been purchased by a customer in California. Invoice Invoice_ Number INTEGER 11731 11732 11733 Customer_ Number INTEGER 3175 3176 3175 Payment
Give a SQL query that lists all line items that are part of invoice number 11731. Invoice Invoice_ Number INTEGER 11731 11732 11733 Customer_ Number INTEGER 3175 3176 3175 Payment DECIMAL (10, 2) 0
Give a SQL query that computes the sum of all quantities that are part of invoice number 11731. Invoice Invoice_ Customer Payment Number Number INTEGER INTEGER DECIMAL(10, 2) 11731 3175 0 11732 3176
Give a SQL query that computes the total cost of all line items in invoice number 11731. Invoice Invoice_ Number INTEGER 11731 11732 11733 Customer_ Number INTEGER 3175 3176 3175 Payment DECIMAL (10,
Give a SQL update statement that raises all prices by ten percent. Invoice Invoice_ Customer Payment Number Number INTEGER INTEGER DECIMAL(10, 2) 11731 3175 0 11732 3176 249.50 11733 3175 0
Give a SQL statement that deletes all customers in California Invoice Invoice_ Number INTEGER 11731 11732 11733 Customer_ Number INTEGER 3175 3176 3175 Payment DECIMAL (10, 2) 0 249.50 0
Pick a database system (such as DB2, Oracle, Postgres, or SQL Server) and determine from the web documentation:• What JDBC driver do you need? Is it automatically discovered?• What is the
Where is the file derby.jar located in your installation of the Java development kit?
Suppose you run the command java -classpath derby.jar;. TestDB database.properties as described in Section 24.3. Match the following five error messages to the error conditions they correspond to. 1.
What is the difference between a Connection and a Statement?
Of the SQL commands introduced in this chapter, which yield result sets, which yield an update count, and which yield neither?
How is a ResultSet different from an Iterator?
Write a Java program that creates a Coin table with coin names and values; inserts coin types penny, nickel, dime, quarter, half dollar, and dollar; and prints out the sum of the coin values. Use SQL
Write a Java program that creates a Car table with car manufacturers, models, model years, and fuel efficiency ratings. Insert several cars. Print out the average fuel efficiency.Use SQL commands
Improve the ExecSQL program and make the columns of the output line up. Use the getColumnDisplaySize method of the ResultSetMetaData class.
Modify the program in Section 24.5 so that the user has the choice of selecting an existing customer. Provide an option to search for the customer by name or zip code.Data from section 24.5
Write a Java program that uses the database tables from the invoice database in Section 24.2. Prompt the user for an invoice number and print out the invoice, format ted as in Chapter 12.
Write a Java program that uses the database tables from the invoice database in Section 24.2. Produce a report that lists all customers, their invoices, the amounts paid, and the unpaid balances.
Write a Java program that uses a library database of books and patron data, as described in Exercise • R24.2. Patrons should be able to check out and return books. Supply commands to print the
Write a Java program that creates a grade book for a class. Create and populate Student and Grade tables before running the program. The program should be able to display all grades for a given
Write a program that assigns seats on an airplane as described in Exercise P12.6 .Keep the seating information in a database.Data from exercise P12.6 Airline seating. Write a program that assigns
Write a program that keeps an appointment calendar in a database. An appointment includes a description, a date, the starting time, and the ending time; for example, Dentist 2016/10/3 17:30 18:30 CS1
Modify the ATM simulation program of Worked Example 24.1 so that the program pops up two ATM frames. Verify that the database can be accessed simultaneously by two users.Data from worked example 24.1
Write a program that uses a database of quizzes. Each quiz has a description and one or more multiple-choice questions. Each question has one or more choices, one of which is the correct one. Use
Enhance the program of Exercise •• P24.6 so that it stores the user’s responses in the database. Add Student and Response tables. (User is a reserved word in SQL.)Data from Exercise P24.6
Write a program that uses the database of Exercise ••• P24.7 and prints a report showing how all students performed on all quizzes.Data from exercise P24.7 Enhance the program of Exercise
Give some examples to show the differences between XML and HTML.
Design an XML document that describes a bank account.
Draw a tree view for the XML document you created in Exercise • R25.2 .Data from exercise R25.2 Design an XML document that describes a bank account.
Write the XML document that corresponds to the parse tree in Figure 2.Figure 2 Left shift ( < >) 0 0 Right shift with zero extension (>>>) 0
Showing 300 - 400
of 791
1
2
3
4
5
6
7
8