Question (1): (10 Marks, each 1 mark) Put a Circle a Round the Correct Answer

Full text


ةناقتلاو مولعلا ةعماج تامولعملا ةناقتو بوساحلا مولع ةيلك سويرلاكب مظن تامولعملا ماعلل لصفلا ةياهن تاناحتمإ 2017 -2018 ةنسلا ةثلاثلا لصفلا سداسلا ةعفدلا 2016 / 2015 IS ررقملا : ةهجوملا ةجمربلا ( 2 ) خيراتلا : 21 / 5 / 2018 م نمزلا : 3 عاس تا ماعلل لصفلا فصتنم تاناحتمإ 2016 -2017 ةنسلا ىلولأا لصفلا لولأا ةعفدلا 2017 / 2016 CS ررقملا : خيراتلا : / 11 / 2016 م نمزلا : ةعاس نسلإا ... نقرلا ... ةلئسلأا عيمج نع بجأ * يلع لمتشت ناحتملإا ةقرو 7 تاحفص *

Question (1): (10 Marks, each 1 mark)

Put a Circle a Round the Correct Answer

1- Which of the following statements creates a Path named p to a FileStream named f? a. Path p = new Path("C:\\Java\\MyFile.txt");

b. Path p = f("C:\\Java\\MyFile.txt");

c. Path p = f.getPath ("C:\\Java\\MyFile.txt"); d. Path p = getPath(new f("C:\\Java\\MyFile.txt"));

2- The Path class getName() method returns ___________. a. the String representation of a Path

b. an absolute Path

c. the first item in a Path’s list of name elements d. the last item in a Path’s list of name elements

3- The statement: JFrame myFrame = new JFrame(); creates a JFrame that is _______. a. invisible and has no title

b. invisible and has a title c. visible and has no title d. visible and has a title

4- Java’s print() and println() methods are defined in the ___________ class. a. BufferedOutputStream

b. System c. PrintStream d. Print

5- A JFrame that contains a JButton object named button1 that should execute an

actionPerformed() method when clicked. Which statement is needed in the JFrame class? a. addActionListener(this);


6- A class can implement __________. a. one listener

b. two listeners

c. as many listeners as it needs d. exactly 3 listeners

7- If a class contains two components that might each generate an event, you can determine which component caused the event by using the method.

a. addActionListener() b. getSource()

c. whichOne() d. identifyOrigin()

8- To group several components such as JCheckBoxes so that a user can select only one at a time, you create a __________.

a. JCheckBoxGroup b. CheckBoxGroup c. JButtonGroup d. ButtonGroup

9- When you create a JFrame named myFrame, you can set its layout manager to BorderLayout with the statement ___________.

a. myFrame.setLayout = new BorderLayout(); b. myFrame.setLayout(new BorderLayout()); c. setLayout(myFrame = new BorderLayout()); d. setLayout(BorderLayout(myFrame));

10. The statement ___________ ensures that components are placed from left to right across a JFrame surface until the first row is full.

a . setLayout(FlowLayout.LEFT); b. setLayout(new FlowLayout(LEFT));

c. setLayout(new FlowLayout(FlowLayout.LEFT));


Question (2) (20 Marks, 10,10)


Complete the following sentences

1- If you try to delete a file that does not exist, a ……… is thrown.

2- If you try to delete a file but you don’t have permission, an ……… thrown.

3- You can use the ………. () method of the Attributes class to retrieve useful information about a file.

4- A file channel is ………, meaning that you can search for a specific file location and operations can start at any specified position.

5- A ……….. is a type of component that holds other components so you can treat a group of them as a single entity.

6- A ……….. is a component into which a user can type a single line of text data.

7- ……… are popup windows that can help a user understand the purpose of components in an application.

8- You tell your class to expect ActionEvents with the ………,, method.

9-When you create a ………. you can group several components, such as JCheckBoxes, so a user can select only one at a time.

10- The ……….t manager is the default manager class for all content panes.

(B) Match A with B


A ---B

1 setText() A setBackground()


2 setLayout() B write(int c)


3 setDefaultCloseOperation() C FlowLayout


4 BufferedReader D JComboBox


5 ItemStateChanged(ItemEvent) E ReadLine ()


6 BufferedWriter F EXIT_ON_CLOSE


7 Content Pane G Menu


8 addItem(Object) H ActionListener


9 actionPerformed(ActionEvent) I ItemListener


10 Mnemonic J getText()



Question (3)(24 Marks, each 2 Marks)

What is the function of each of the following statements?

ةيلبتلا لمجلا نم هلمج لك ةفيظ و يهبم

1- Import static java.nio.file.AccessMode.*;


2- BasicFileAttributes attr = Attributes.readBasicFileAttributes(filePath);

---3- JTextField response = new JTextField(10); frame.add(response);

---4- response.setText("Thank you");

---5- button.setToolTipText("Click this button");

---6- con.setLayout(new GridLayout(4, 5));


---Write a Java statement that performs:

ةيلبتلا هيلمعلا يدؤت بفبج ةغلب ةلمج بتكأ :

1-Create a JLabel named greeting that holds the words “Good day”

---2- Add the greeting object to the JFrame object named aFrame

---3- Assign the Font:

Font headlineFont = new Font("Monospaced", Font.BOLD, 36); to the label greeting.

---4- Create a JButton with the label “Press Me When Ready”

---5-Create a ButtonGroup, aGroup , then Create a JCheckBox aBox, and then Add aBox to aGroup.


---6- add the JMenuBar to a JFrame, the menu bar is created as follows: JMenuBar mainBar = new JMenuBar();



Question (4) (16 Marks, 10, 6)

1- Read the following code and then answer the given questions

1- import java.nio.file.*; 2- import*; 3- public class ReadFile 4- {

5- public static void main(String[] args)

6- {

7- Path file = Paths.get("C:\\Java\\Chapter.13\\Grades.txt"); 8- InputStream input = null;

9- Try

10- {

11- input = file.newInputStream();

12- BufferedReader reader = new BufferedReader(new InputStreamReader(………));

13- String s = null; 14- s = reader.readLine(); 15- System.out.println(s); 16- input.close(); 17- } 18- catch (IOException e) 19- { 20- System.out.println(e); 21- } 22- } 23-}


1- What change you can made if we cancel statement in line (8) رطسلا يف ولوحلا ءاغلإ نت اذإ وب موقتس يرلا ليدعتلا وىاه


--- 2- Complete statement in line (12)? 12 رطسلا يف ةلوجلا لوكأ

--- 3- Explain what statement in line 14 do?14 رطسلا يف ةلوجلا لعفت اذاه حرشأ


---4- What does the program do? جهانربلا ارى لعفي اذاه

--- 5- What change you do to read and print all data in the file? لهاك جهانربلا عبطي و ارقيل ويرجتس يرلا ليدعتلا وىاه

؟فلولا يوتحه


2- Read the following code and then answer the given questions

1- void actionPerformed(ActionEvent e)

2- {

3- Object source = e.getSource();

4- if (source == button1)

5- system.out.println( “ You Choose Red”)

6- else

7- system.out.println (“ You Choose White”)

8- }


1- When this function does execute? ولادلا هرى ريفنت نتي يته

---2- What is the function of the method getSource() in line 3? رطسلا يف ولادلا ةفيظو يىاه؟3

---3- What is the output of the execution of the code? ؟8–1 رطسلاا يف ةلادلا ريفنت جتان وىاه