Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

1. Java is an example of a(n)
a) machine language
b) assembly language
c) high-level language
d) fourth generation language
e) all of the above

2. What does the following code output?

DecimalFormat dfQuestion = new DecimalFormat("#0.###E0");
System.out.println(dfQuestion.format(12.7896987));

a) 12.80E0
b) 12.79E0
c) 12.800E1
d) 1.28E2
e) 0.0128E3

3. If x is an int and y is a float, which of the following is an illegal assignment statement?

a) y = x;
b) x = y;
c) y = (float) x;
d) x = (int) y;
e) all of the above are legal

4. To compare two strings lexicographically, which of the following String methods should be used?

a) equals
b) equalsIgnoreCase
c) compareTo
d) ==
e) all of the above

5. In order to declare a constant, you would use which of the following Java reserved words?

a) private
b) static
c) int
d) final
e) class

6. If two variables contain aliases of the same object then

a) The object may be modified using either alias
b) The object cannot be modified unless there's but a single reference to it
c) A third alias is created if/when the object is modified
d) The object will become an "orphan" if both variables are set to null
e) Answers (a) and (d) are correct

7. Say you write a program that has the following statement in it:
Random rand;

But you fail to include an import statement for java.util.Random (or java.util.*). What will happen when you attempt to compile and run your program.

a. The program won't run, but it will compile with a warning about the missing class.
b. The program won't compile - you'll receive a syntax error about the missing class.
c. The program will compile, but you'll receive a warning about the missing class.
d. The program will encounter a runtime error when it attempts to access any member of the Random class
e. none of the above

8. Consider the following enumeration:
enum Speed { FAST, MEDIUM, SLOW };
Which of the following statements is correct?

a) The ordinal value of MEDIUM is 2
b) The ordinal value of SLOW is 3
c) The name of the Speed enumeration whose ordinal value is zero is FAST
d) The name of the Speed enumeration whose ordinal value is one is SLOW
e) None of the above

9. Given two String variables, s1 and s2, to determine if they are the same length, which of the following conditions would you use?

a) (s1.equals(s2))
b) (s1.length( ).equals(s2))
c) (s1.length( ).equals(s2.length( ))
d) (s1.length( ) == s2.length( ))
e) length(s1) == length(s2)

10.The String class' compareTo method does which of the following:

a) compares two string in a case-independent manner
b) yields true or false
c) yields 0 if the two strings are identical
d) returns 1 if the first string comes lexically before the second string
e) none of the above

11.What will be displayed by the following command: System.out.println(Math.pow(3, 3-1));

a) 9.0
b) 8.0
c) 6.0
d) 4.0
e) 27.0

12.The relationship between classes and objects is best described as:

a) classes are instances of objects
b) objects are instances of classes
c) objects and classes are the same thing
d) classes are programs while objects are variables
e) objects are the instance data of classes

13.A class' constructor usually defines which of the following

a) how an object is initialized
b) how an object is interfaced
c) the number of instance data in the class
d) the number of methods in the class
e) if the instance data are accessible outside of the object directly

14.Having multiple methods of the same name in a class where each method has a different number of or type of parameters is known as:

a) encapsulation
b) information hiding
c) tokenizing
d) importing
e) method overloading

15.Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?

a) foo(0, 0.1);
b) foo(0 / 1, 2 * 3);
c) foo(0);
d) foo( );
e) foo(1 + 2, 3 * 0.1);

16.Every Iterator has which of the following:

a) a hasNext( ) method
b) a hasFirst( ) method
c) a hasNextInt( ) method
d) a isEmpty( ) method
e) none of the above

17.The statement if (x < 0) y = x; else y = 0; can be rewritten using a conditional operator as

a) y = (x < 0) ? x : 0;
b) x = (x < 0) ? y : 0;
c) (x < 0) ? y = x : y = 0;
d) y = (x < 0);
e) y = if (x < 0) x : 0

18.Consider the following paint method:

public void paint(Graphics page)
{
int x, y = 200;
page.setColor(Color.blue);
for (x = 100; x < 200; x += 20)
page.fillRect(x, y, 10, y-x);
}

This paint method will draw several bars (sort of like a bar graph). How many bars will be displayed?

a) 4
b) 5
c) 6
d) 10
e) 20

19.It is easier to correct errors found in a program if

a) they are identified early in the development cycle
b) they are identified during testing
c) they are identified during program use
d) they are identified during maintenance
e) all of the above are equally true, errors are easily corrected in any of these stages

20.It is a bad programming habit to build an initial program and then spend a great deal of time modifying the code until it is acceptable. This is known as which of the following:

a) the prototyping approach
b) the waterfall model
c) iterative development
d) the recursive approach
e) the build-and-fix approach

21.The idea that an object can exist separate from the executing program that creates it is called which of the following:

a) transience
b) static
c) persistence
d) serialization
e) finality

22.In general, spending more time on a better design for a software will do which of the following:

a) shorten testing time
b) slightly reduce maintenance efforts
c) slightly increase maintenance efforts
d) greatly reduce maintenance efforts
e) not alter the time it takes for any other stage whatsoever

23.Which of the following interfaces would be used to implement a class that represents a group of objects?

a) Collection
b) Speaker
c) Comparable
d) MouseListener
e) KeyListener

24.Which of the following Layout Manager types would you use if you want GUI components to be placed at the North, South, East, West and Center of a container?

a) FlowLayout
b) BorderLayout
c) BoxLayout
d) GridLayout
e) TabbedPane

25.Assume this statement: int[] values = {9,4,12,2,6,8,18}; Now the statement: System.out.println(values[7]); will do:

a) output 7
b) output 18
c) output nothing
d) cause an ArrayOutOfBoundsException to be thrown
e) cause a syntax error

Short answer questions:

Answers for the following questions should not exceed three sentences.

26.What is a class variable? How is it defined in Java?

27.Explain how favoring composition over inheritance may improve ObjectOriented Design.
28.What is a wrapper class and when is it usually useful? Give an example of a standard wrapper class?

29.What is the main difference between applets and normal Java programs? Briefly explain.

30.Name all the visibility modifiers in Java. Which one is the preferred visibility for instance variables of a class?

Programming questions:

31.Write a code fragment that declares a two-dimensional 10x10 array of integers called myArray and then initialize each element of the array to have the value of i * j where i and j are the two indices of the element. For instance, the value for element myArray[5][3] must be set to 15 (i.e. 5 * 3).

32.Write an interface named XYInterface that contains two int constants, X = 5 and Y = 10 and a method called useXY which receives no parameters and returns an integer value. (You don't need to implement the XYInterfac)

33.String s1 is said to overlap String s2 if all of the characters in s1 also appear in s2 (in any order). Write a method called testOverlap that takes two strings (called s1 and s2) as input parameters and returns a boolean value that is true if s1 overlaps s2 and false otherwise.

34.Write a class called Employee. Each employee should have a name, an identification number, a position, and an hourly wage.

a) Write a method that is passed the int value of the number of hours worked for the week as a parameter, and returns the pay for the Employee (including overtime, which is 1.5 * hourly wages for each hour over 40).

b) Write a raise method that is passed an increase (or decrease) in hourly wages and updates the Employee's hourly wages appropriately. The amount passed is strictly the amount of increase or decrease, not a new hourly wages. If the amount of increase (or decrease) is more than what the Employee currently makes, do not adjust the hourly wage, but arise an exception called InvalidRaise.

Java, Programming

  • Category:- Java
  • Reference No.:- M91698779

Have any Question?


Related Questions in Java

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As