1 / 49

CHAPTER 7 & 8 REVIEW QUESTIONS

CHAPTER 7 & 8 REVIEW QUESTIONS. ______ class is used to create a frame using Swing. The default layout manager of JPanel object is ______. The default layout manager of JFrame object is ______. The default allignment of a FlowLayout manager is ______ allignment.

brauns
Download Presentation

CHAPTER 7 & 8 REVIEW QUESTIONS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHAPTER 7 & 8REVIEW QUESTIONS • ______ class is used to create a frame using Swing.

  2. The default layout manager of JPanel object is ______.

  3. The default layout manager of JFrame object is ______.

  4. The default allignment of a FlowLayout manager is ______ allignment.

  5. Adding radio button components to an object of ________ class will create a mutually exclusive relationship between them.

  6. A panel can not be displayed by itself.

  7. You can place multiple components inside a GridLayout cell.

  8. You can place multiple components inside a BorderLayout region.

  9. You can place a panel inside a BorderLayout region.

  10. You can write a class that extends the JPanel class.

  11. What kind of Listener should be used for JButton and JTextField objects?

  12. What kind of Listener should be used for JCheckBox and JRadioButton objects?

  13. What import statement must you include in your code to use a ActionListener class?

  14. Which class is used to create a Border object?

  15. The type of parameter in the setVisible() method of JFrame class is:

  16. The type of parameter in the actionPerformed() method of ActionListener interface is:

  17. The type of parameter in the itemStateChanged() method of ItemListener interface is:

  18. Which method in the ActionEvent class is used to identify the source of an action event?

  19. Given a JPanel object p, which of the followings is the correct statement to set the GridLayout manager of dimension 3 by 4 for p?

  20. The default alignment of FlowLayout manager is:

  21. What method is used to set a border around a panel?

  22. Each element of an array is accessed by a number known as a ________?

  23. The first subscript in an array is always ____.

  24. If n is the number of elements in an array, then the last subscript in this array is _____.

  25. The array field that holds the number of elements in an array is ______.

  26. To insert an item into an ArrayList object, you use this method.

  27. An array’s size declarator can be a negative integer expression.

  28. Both of the following declarations are legal and equivalent: int [] n; int n [];

  29. Java compiler does not display an error message when it processes a statement that uses an invalid subscript.

  30. Each row in a two-dimensional array can have a different length.

  31. An ArrayList automatically expands in size to accommodate the items stored in it. True or false?

  32. What will be the output when running the following program? public class MyClass { public static void main(String args[]) { int [][]a = { {3,5,1,2}, {0,1,3,4}, {1,2,9,8}}; int i=1; int j; for (j=1; j<=2; ++j){ a[i][j] += a[j][i]; } System.out.println(a[i][j-1]); } }

  33. What results from the following fragment of code? int x = 1; String [] names ={“Fred”, “Jim”, “Sheila” }; names[--x] += “.”; for (int i = 0; i < names.length; i++) { System.out.println(names[i]); }

  34. Given the following code fragment: int [] array = {2, 3, 6, 4, 1, 7, 9, 12}; int i = 1; int j = 2*i + 1; What is the value of array[j]?

  35. Given the following code fragment: int [][] array = new int[5][]; for (int i = 0; i < 5; i++) array[i] = new int[i+1]; for (int i = 0; i < 5; i++) for (int j = 0; j < array[i].length; j++) array[i][j] = i + j; • How many elements does array have?

  36. What import statement must you include in your code to use a Arrays and ArrayList class?

  37. To delete an item from an ArrayList object, you use this method.

  38. To determine the number of items stored in an ArrayList object, you use this method.

  39. Given the following method: static int sum(int[] a) { int s = 0; for (int i=0; i<a.length; i++) if (a[i]%2==0) s += a[i]; return s; } And given the following array: int [] m = {1, 2, 3, 4, 5, 6}; What is the value of sum(m)?

  40. What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=1; i<m.length; i++) m[i] = 2*m[i-1]; for (int n: m) System.out.print(n+ " "); System.out.println();

  41. Given the following code fragment: int [] array = {2, 3, 6, 4, 1, 7, 9, 12}; int i = 1; int j = 2*i + 1; • What is the value of array[j]?

  42. What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i<m.length; i++) m[i] = 2*m[i]; for (int n: m) System.out.print(n+ " "); System.out.println();

  43. What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i<m.length; i++) m[i] = m[i] + 2; for (int n: m) System.out.print(n+ " "); System.out.println();

  44. What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i< m.length–1; i++) m[i] = 2*m[i+1]; for (int n: m) System.out.print(n+ " "); System.out.println();

  45. What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i<m.length; i++) m[i] = (m[i]%2==0 ? m[i]/2 : 3*m[i]+1); for (int n: m) System.out.print(n+ " "); System.out.println();

  46. What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i<m.length; i++) m[i] = (i%2 == 0 ? 2*m[i] : m[i] + 2); for (int n: m) System.out.print(n+ " "); System.out.println();

  47. What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=1; i<m.length; i++) m[i] = m[i-1] + m[i]; for (int n: m) System.out.print(n+ " "); System.out.println();

  48. What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=1; i<m.length; i++) m[i] = m[i]- m[i-1]; for (int n: m) System.out.print(n+ " "); System.out.println();

  49. What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=1; i<m.length; i++) m[i] = (m[i-1]< m[i] ? m[i] : m[i-1]); for (int n: m) System.out.print(n+ " "); System.out.println();

More Related