0% found this document useful (0 votes)
3 views16 pages

JavaExamQuestionsDarkMode - Tex 1

The document is a comprehensive question bank for a Java exam, covering various topics such as basic OOP concepts, inheritance, interfaces, and polymorphism. It includes multiple-choice questions with correct answers and explanations for each question. The content is structured to aid in understanding Java programming principles and practices.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

JavaExamQuestionsDarkMode - Tex 1

The document is a comprehensive question bank for a Java exam, covering various topics such as basic OOP concepts, inheritance, interfaces, and polymorphism. It includes multiple-choice questions with correct answers and explanations for each question. The content is structured to aid in understanding Java programming principles and practices.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Comprehensive Java Exam Question Bank

Java Exam - ‫ﺑﻨﻚ اﻷﺳئﻠﺔ اﻟﺸﺎﻣﻞ‬

‫المحتويات‬

1
(Basic OOP) ‫ المفاهيم األساسية والوراثة‬:ً ‫أوال‬

In Java, the method that transfers the thread from the running state to the time waiting state :Q
is:
a) Stop() b) Sleep() c) Terminate() d) Delay()

b) Sleep() :‫الجواب‬

،‫ ﻟﻔﺘﺮة زﻣﻨﻴﺔ ﻣﺤﺪدة‬Timed Waiting ‫ إﱃ ﺣﺎﻟﺔ‬Running ‫ ﻣﻦ ﺣﺎﻟﺔ‬Thread ‫ ﺗﻘﻮم ﺑﻨﻘﻞ اﻟـ‬sleep() ‫ اﻟﺪاﻟﺔ‬:‫الشرح‬
.Waiting ‫ ﺗﻨﻘﻠﻬﺎ إﱃ‬wait() ‫ﺑﻴﻨﻤﺎ‬

We can extend String class. :Q


a) True b) False

b) False :‫الجواب‬

.‫ )وراﺛﺔ( ﻣﻨﻬﺎ‬Inheritance ‫ وﺑﺎﻟﺘﺎﻟﻲ ﻻ ﻳﻤﻜﻦ ﻋﻤﻞ‬،final class ‫ ﻓﻲ اﻟﺠﺎﻓﺎ ﻣﻌﺮﻓﺔ ﻛـ‬String ‫ اﻟﻜﻼس‬:‫الشرح‬

The data fields in an interface are: :Q


d) both static and final

d) both static and final :‫الجواب‬

.final ‫ و‬,implicitly) public, static) ً ‫ ﺗﻜﻮن ﺿﻤﻨﻴﺎ‬Interface ‫( داﺧﻞ اﻟـ‬Variables) ‫ اﻟﻤﺘﻐﻴﺮات‬:‫الشرح‬

Non-abstract classes are called: :Q


d) concrete classes

d) concrete classes :‫الجواب‬

Concrete ‫ ﻣﻨﻪ ﻳﺴﻤﻰ‬Objects ‫( وﻳﻤﻜﻦ إﻧﺸﺎء‬abstract methods) ‫ اﻟﻜﻼس اﻟﺬي ﻻ ﻳﺤﺘﻮي ﻋﲆ دوال ﻣﺠﺮدة‬:‫الشرح‬
.Class

Interfaces can have constructors. :Q


b) False

b) False :‫الجواب‬

.Constructors ‫ وﻻ ﺗﺤﺘﻮي ﻋﲆ‬،‫ ﻣﻨﻬﺎ ﻣﺒﺎﺷﺮة‬Objects ‫ ﻻ ﻳﻤﻜﻦ إﻧﺸﺎء‬Interfaces ‫ اﻟـ‬:‫الشرح‬

Reusability is an advantage for inheritance. :Q


a) True

a) True :‫الجواب‬

2
.Parent Class ‫( اﻟﻤﻮﺟﻮد ﻓﻲ اﻟـ‬Code Reusability) ‫( ﺗﺴﻤﺢ ﺑﺈﻋﺎدة اﺳﺘﺨﺪام اﻟﻜﻮد‬Inheritance) ‫ اﻟﻮراﺛﺔ‬:‫الشرح‬

Final methods support dynamic polymorphism. :Q


b) False

b) False :‫الجواب‬

‫ ﻻ ﻳﻤﻜﻦ ﻋﻤﻞ‬final ‫ اﻟﺪوال اﻟﻤﻌﺮﻓﺔ ﻛـ‬.Method Overriding ‫ ﻳﻌﺘﻤﺪ ﻋﲆ‬Dynamic Polymorphism :‫الشرح‬
.‫ ﻟﻬﺎ‬Override

What is the output of the following program? (Inheritance & Super) ClassB extends ClassA. :Q
Override m1 & m2. Calls involve super.
d) BDAC

d) BDAC :‫الجواب‬

‫< ﻳﺴﺘﺪﻋﻲ‬- (B ‫ )ﻧﺴﺨﺔ‬m2 ‫< ﻳﺴﺘﺪﻋﻲ‬- A ‫ ﻓﻲ‬super.m1 ‫< ﻳﺴﺘﺪﻋﻲ‬- B ‫ ﻓﻲ‬e.m1() ‫ اﺳﺘﺪﻋﺎء‬:‫ اﻟﺘﺴﻠﺴﻞ‬:‫الشرح‬
.(B (C ‫< ﻳﻌﻮد ﻟـ‬- A ‫< ﻳﻌﻮد ﻟـ‬- D ‫( ﺛﻢ‬super.m2 (B

What is the output? (Constructors) Shape prints ”Base”, Circle extends Shape prints ”Derived”. :Q
c) Base Derived

c) Base Derived :‫الجواب‬

‫ ﺛﻢ ﻳﻜﻤﻞ‬،”Base” ‫ ﻓﻴﻄﺒﻊ‬،ً ‫( أوﻻ ً ﺿﻤﻨﻴﺎ‬Shape) ‫ ﻳﺘﻢ اﺳﺘﺪﻋﺎء ﻛﻮﻧﺴﻨﺮﻛﺘﻮر اﻷب‬،()new Circle ‫ ﻋﻨﺪ إﻧﺸﺎء‬:‫الشرح‬
.‫ﻛﻮﻧﺴﺘﺮﻛﺘﻮر اﻻﺑﻦ‬

Which of the following is FALSE about abstract classes in Java? :Q


d) A class can inherit from multiple abstract classes.

d :‫الجواب‬

.(Multiple Inheritance of classes) ‫ اﻟﺠﺎﻓﺎ ﻻ ﺗﺪﻋﻢ اﻟﻮراﺛﺔ اﻟﻤﺘﻌﺪدة ﻟﻠﻜﻼﺳﺎت‬:‫الشرح‬

We can make a class abstract by: :Q


Using the abstract keyword

abstract keyword :‫الجواب‬

.abstract ‫ ﺑﺎﺳﺘﺨﺪام اﻟﻜﻠﻤﺔ اﻟﻤﻔﺘﺎﺣﻴﺔ‬:‫الشرح‬

Which of the following is true about interfaces? (1. Fields, 2. Instance, 3. Multiple Impl, 4. Many :Q
classes)
1, 3 and 4

3
1, 3 and 4 :‫الجواب‬

.(‫ ﺧﺎﻃﺊ‬2 ‫ ﻣﺒﺎﺷﺮة )اﻟﺨﻴﺎر‬Interface ‫( ﻣﻦ اﻟـ‬Instance) ‫ ﻻ ﻳﻤﻜﻦ إﻧﺸﺎء ﻛﺎﺋﻦ‬:‫الشرح‬

Correct Interface Syntax: :Q


d) interface A { void print(); }

d :‫الجواب‬

.ً ‫ ﺿﻤﻨﻴﺎ‬public abstract ‫ واﻟﺪوال ﺗﻜﻮن‬،interface ‫ ﻗﺒﻞ ﻛﻠﻤﺔ‬abstract ‫ ﻻ ﻧﻜﺘﺐ‬:‫الشرح‬

Use of ’final’ keyword applies to: :Q


All of the above

All of the above :‫الجواب‬

.‫ ﻗﻴﻤﺔ ﺛﺎﺑﺘﺔ ﻻ ﺗﺘﻐﻴﺮ‬:override. Variable final ‫ ﻻ ﻳﻌﻤﻞ ﻟﻪ‬:Method final .‫ ﻻ ﻳﻮرث‬:Class final :‫الشرح‬

Final Variable Re-assignment (final int i = 20; i = 30;) :Q


Compiler Error

Compiler Error :‫الجواب‬

.‫ ﺑﻌﺪ إﻋﻄﺎﺋﻪ ﻗﻴﻤﺔ أوﻟﻴﺔ‬final ‫ ﻻ ﻳﻤﻜﻦ ﺗﻐﻴﻴﺮ ﻗﻴﻤﺔ ﻣﺘﻐﻴﺮ‬:‫الشرح‬

(Tracing & Polymorphism) ‫ التتبع وتعدد األشكال‬:ً‫ثانيا‬

Nested Method Calls: m3 throws, m2 catches & re-throws, m1 catches. Main continues. :Q
b) BA

b) BA :‫الجواب‬

.‫ ﻻ ﻳﺮى ﺧﻄﺄ‬Main ‫ اﻟـ‬.A ‫ ﻳﻤﺴﻚ وﻳﻄﺒﻊ‬m1 <- ‫ وﻳﻌﻴﺪ رﻣﻴﻪ‬B ‫ ﻳﻤﺴﻚ وﻳﻄﺒﻊ‬Exception -> m2 ‫ ﻳﺮﻣﻲ‬m3 :‫الشرح‬

Tracing Q1: Polymorphism calculation (ClassA=9, ClassB=9, ClassC=super*2, ClassD=super*3) :Q


9.0, 9.0, 18.0, 27.0

9.0, 9.0, 18.0, 27.0 :‫الجواب‬

.super ‫ ﻳﺘﻢ ﺣﺴﺎب اﻟﻘﻴﻢ ﺑﻨﺎًء ﻋﲆ اﻟﻮراﺛﺔ واﺳﺘﺪﻋﺎء‬:‫الشرح‬

Tracing Q2: MyCB extends MyCA. printData(x+y) vs printInfo(). :Q


Output: ”2 1” then Compilation Error

4
Error :‫الجواب‬

.Casting ‫( دون‬c) ‫ وﻻ ﻳﻤﻜﻦ اﺳﺘﺪﻋﺎؤﻫﺎ ﺑﻤﺮﺟﻊ اﻷب‬،‫ ﻣﻮﺟﻮدة ﻓﻘﻂ ﻓﻲ اﻻﺑﻦ‬printInfo :‫الشرح‬

Analyze: Class B extends A. new B(). Class A constructor prints ”i=7”. :Q


b) The constructor of class A is called and it displays ”i from A is 7”

b :‫الجواب‬

.‫ اﻷب أوﻻ ً ﺑﺸﻜﻞ ﺗﻠﻘﺎﺋﻲ‬Constructor ‫ ﻳﺘﻢ اﺳﺘﺪﻋﺎء‬،‫ ﻣﻦ ﻛﻼس اﻻﺑﻦ‬Object ‫ ﻋﻨﺪ إﻧﺸﺎء‬:‫الشرح‬

Polymorphism inside Constructor: A calls setI(20). B overrides setI(*3). new B(). :Q


d) ... displays ”i from A is 60”

d :‫الجواب‬

.Polymorphism ‫( ﺑﺴﺒﺐ اﻟـ‬B) ‫ اﻟﺨﺎﺻﺔ ﺑﺎﻻﺑﻦ‬setI ‫ ﻳﺘﻢ اﺳﺘﺨﺪام داﻟﺔ‬،‫ ﺣﺘﻰ داﺧﻞ ﻛﻮﻧﺴﺘﺮﻛﺘﻮر اﻷب‬:‫الشرح‬

Constructor Chaining: Circle9 calls this(), this(), super(). :Q


e) BEDC

e) BEDC :‫الجواب‬

.‫( ﺛﻢ اﻟﻌﻮدة ﻟﻸﺑﻨﺎء‬B) ‫< ﺗﻨﻔﻴﺬ اﻷب‬- (...)Circle9() -> this(1.0) -> this(radius...) -> super :‫ اﻟﺘﺴﻠﺴﻞ‬:‫الشرح‬

Compile error: m(Student x). Called with Person/Object. :Q


c) & d)

c) & d) :‫الجواب‬

.Casting ‫ دون‬Subclass ‫( ﻟﺪاﻟﺔ ﺗﺘﻮﻗﻊ‬Object ‫ أو‬Person ‫ )ﻣﺜﻞ‬Superclass ‫ ﻻ ﻳﻤﻜﻨﻚ ﺗﻤﺮﻳﺮ‬:‫الشرح‬

Method Overriding: Person calls getInfo(). Student overrides getInfo() -> ”Student”. :Q
b) Person Student

b :‫الجواب‬

getInfo ‫)( ﺗﺴﺘﺪﻋﻲ‬Person”. new Student().printPerson” ‫)( ﺗﻄﺒﻊ‬new Person().printPerson :‫الشرح‬


.”Student” ‫ ﻓﺘﻄﺒﻊ‬Student ‫اﻟﺨﺎﺻﺔ ﺑـ‬

Private Methods: Same code but getInfo() is private in Person. :Q


a) Person Person

a :‫الجواب‬

5
.‫ ﻧﺴﺨﺘﻬﺎ ﻓﻘﻂ‬Person ‫ ﻓﺘﺮى‬،‫ ﻟﻬﺎ‬Override ‫ ﻻ ﺗﻮرث وﻻ ﻳﺘﻢ ﻋﻤﻞ‬private ‫ اﻟﺪوال اﻟـ‬:‫الشرح‬

Runtime Polymorphism: Base b = new Derived(); [Link](); (normal method) :Q


Derived::show() called

Derived :‫الجواب‬

.‫ ﻟﺬا ﻳﺘﻢ اﺳﺘﺪﻋﺎء داﻟﺔ اﻻﺑﻦ‬،Derived ‫ ﻧﻮع اﻟﻜﺎﺋﻦ اﻟﻔﻌﻠﻲ ﻫﻮ‬.‫ اﻟﺪاﻟﺔ ﻣﻮﺟﻮدة ﻓﻲ اﻷب واﻻﺑﻦ‬:‫الشرح‬

Overriding Final Method: Derived tries to override final void show(). :Q


Compiler Error

Compiler Error :‫الجواب‬

.‫ ﻟﻬﺎ‬Override ‫ ﻻ ﻳﻤﻜﻦ ﻋﻤﻞ‬final ‫ اﻟﺪوال اﻟﻤﻌﺮﻓﺔ ﻛـ‬:‫الشرح‬

Static Method Hiding: Base b = new Derived(); [Link]() (static method). :Q


Base::show() called

Base :‫الجواب‬

.(Base) ‫ ﻳﺘﻢ اﺳﺘﺪﻋﺎؤﻫﺎ ﺑﻨﺎًء ﻋﲆ ﻧﻮع اﻟﻤﺮﺟﻊ‬.Polymorphism ‫ ﻻ ﺗﺪﻋﻢ اﻟـ‬static ‫ اﻟﺪوال اﻟـ‬:‫الشرح‬

Method Calls: DoPrint(Base o). x=Base, y=Derived, z=Derived. DoPrint(y). :Q


Base Derived Derived

A :‫الجواب‬

.Derived ‫ وﻳﺘﻢ اﺳﺘﺪﻋﺎء ﻧﺴﺨﺔ اﻟـ‬Polymorphism ‫ ﻟﺬا ﻳﺤﺼﻞ‬،static ‫ ﻟﻴﺴﺖ‬print :‫الشرح‬

Overriding Private Method with Public: Base private foo, Derived public foo. :Q
Compiler Error / No Override

Compiler Error :‫الجواب‬

.‫ وﻻ ﻳﻤﻜﻦ اﻟﻮﺻﻮل ﻟﻠﺪاﻟﺔ اﻟﺨﺎﺻﺔ ﻣﻦ ﻣﺮﺟﻊ اﻷب‬،Override ‫ ﻻ ﻳﻌﺘﺒﺮ‬:‫الشرح‬

Field Polymorphism: A a = new B(). Accessing field a.c. :Q


ABBA

A :‫الجواب‬

.‫ ﺑﻴﻨﻤﺎ اﻟﺪوال ﺗﺘﺒﻊ اﻟﻜﺎﺋﻦ‬،‫( وﻟﻴﺲ ﻧﻮع اﻟﻜﺎﺋﻦ‬A) ‫( ﺗﺘﺒﻊ ﻧﻮع اﻟﻤﺮﺟﻊ‬Variables) ‫ اﻟﺤﻘﻮل‬:‫الشرح‬

6
Private ”Overriding”: Base private flipper, Derived public flipper. new Clidlet().flipper(). :Q
Clidlet (Child’s version)

Clidlet :‫الجواب‬

.ً ‫ ﻟﺬا ﺗﻌﺮﻳﻒ داﻟﺔ ﺑﻨﻔﺲ اﻻﺳﻢ ﻓﻲ اﻻﺑﻦ ﻳﻌﺘﺒﺮ داﻟﺔ ﺟﺪﻳﺪة ﺗﻤﺎﻣﺎ‬،private ‫ اﻟﺪاﻟﺔ ﻓﻲ اﻷب‬:‫الشرح‬

Static Method Hiding (Again): A extends B. Both have static sing(). A a = new A(); B b = new A(); :Q
fa la

fa la :‫الجواب‬

.(B (Static Hiding ‫( ﻷن اﻟﻤﺮﺟﻊ‬B (la ‫)( ﺗﺴﺘﺪﻋﻲ‬A. [Link] ‫( ﻷن اﻟﻤﺮﺟﻊ‬A (fa ‫)( ﺗﺴﺘﺪﻋﻲ‬[Link] :‫الشرح‬

Explain Compilation Errors (Tracing Q3) :Q


Various Errors

Errors :‫الجواب‬

:‫الشرح‬

.‫( أﺧﺮى‬package) ‫ ﻻ ﻳﺮى ﻓﻲ ﺣﺰﻣﺔ‬Default Access ‫ ﻣﺘﻐﻴﺮ ﺑـ‬:Line 29 .1


.‫ ﻣﻦ ﻛﻼس آﺧﺮ دون إﻧﺸﺎء ﻛﺎﺋﻦ‬Instance ‫ اﺳﺘﺪﻋﺎء داﻟﺔ‬:Line 35 .2
.abstract ‫ ﻟﺬا ﻳﺠﺐ أن ﻳُﻌﺮّف اﻟﻜﻼس ﻛـ‬،abstract ‫ اﻟﻜﻼس ﻳﺤﺘﻮي ﻋﲆ داﻟﺔ‬:Line 42 .3
.Casting ‫ دون‬Child Reference ‫ إﱃ‬Parent Object ‫ ﻻ ﻳﻤﻜﻦ إﺳﻨﺎد‬:Line 49 .4

Constructor Chaining Error (Program 1: Class A has arg-constructor, B calls default) :Q


Compilation fails

Fails :‫الجواب‬

.‫ وﻫﺬا ﻏﻴﺮ ﻣﻮﺟﻮد‬،‫)( اﻟﻤﺨﻔﻲ‬super ‫ ﺗﺤﺎول اﺳﺘﺪﻋﺎء‬Class B .‫ ﻻ ﺗﺤﺘﻮي ﻋﲆ ﻛﻮﻧﺴﺘﺮﻛﺘﻮر اﻓﺘﺮاﺿﻲ‬Class A :‫الشرح‬

(Exceptions) ‫ معالجة األخطاء‬:ً‫ثالثا‬

Output: m1 prints ”wish”, throws. Main prints ”good” (skipped). Catch ”luck”. Finally ”in”. :Q
b) wish luck in exam

b :‫الجواب‬

.(finally (in ‫( ﺛﻢ‬catch (luck ‫ ﻳﻨﺘﻘﻞ ﻟـ‬.good ‫ وﺗﺠﺎوز‬try ‫ ﻓﻴﺘﻮﻗﻒ ﺗﻨﻔﻴﺬ‬،throw ‫ ﻳﺤﺪث‬:‫الشرح‬

7
Nested Try-Catch: V, try W, 9/0 error, catch Y, Z. :Q
e) VWYZ

e) VWYZ :‫الجواب‬

.catch ‫ واﻟﺬﻫﺎب ﻟﻠـ‬X ‫ ﻓﻴﺘﻢ ﺗﺠﺎوز‬،ArithmeticException ‫( ﻳﺮﻣﻲ‬[Link](9/0 ‫ اﻟﺴﻄﺮ‬:‫الشرح‬

Unchecked Exception example: :Q


a) ArithmeticException

a :‫الجواب‬

.RuntimeException ‫ ﻫﻲ اﻟﺘﻲ ﺗﺮث ﻣﻦ‬Unchecked Exceptions ‫ اﻟـ‬:‫الشرح‬

What exception is thrown? int[] list = new int[5]; [Link](list[5]); :Q


b) ArrayIndexOutOfBoundsException

b :‫الجواب‬

.‫ ﺧﺎرج اﻟﺤﺪود‬list ‫ ﻃﻠﺐ‬.(4 ‫ إﱃ‬0 ‫ ﻣﻦ‬indices ‫ )اﻟـ‬5 ‫ اﻟﻤﺼﻔﻮﻓﺔ ﺣﺠﻤﻬﺎ‬:‫الشرح‬

Catch Block Ordering: catch(Exception) then catch(RuntimeException). :Q


d) Compile error

d :‫الجواب‬

.‫ ﻷن اﻻﺑﻦ ﻟﻦ ﻳﺘﻢ اﻟﻮﺻﻮل إﻟﻴﻪ‬،‫( ﻗﺒﻞ اﻟﻜﻼس اﻻﺑﻦ‬Exception) ‫ ﻟﻠﻜﻼس اﻷب‬catch ‫ ﻻ ﻳﺠﻮز وﺿﻊ‬:‫الشرح‬

Exception Propagation: p() throws NumberFormat. Main catches. :Q


a) Displays NumberFormatException

a :‫الجواب‬

.main ‫ اﻟﻤﻮﺟﻮد ﻓﻲ‬catch ‫ وﻳﻨﺘﻘﻞ اﻟﺘﺤﻜﻢ ﻟﻠـ‬،‫ ﻳﺘﻮﻗﻒ ﺗﻨﻔﻴﺬﻫﺎ‬،p ‫ اﻟﺨﻄﺄ ﻳﺤﺪث ﻓﻲ‬:‫الشرح‬

Finally Block: Error (2/0) in try. No catch. Finally exists. :Q


b) Welcome... Finally... then error message

b :‫الجواب‬

.‫ ﻗﺒﻞ إﻧﻬﺎء اﻟﺒﺮﻧﺎﻣﺞ وﻋﺮض اﻟﺨﻄﺄ‬finally ‫ ﻳﺠﺐ ﺗﻨﻔﻴﺬ ﺑﻠﻮك‬:‫الشرح‬

Predict output: throw 10; :Q


Compiler Error

8
Error :‫الجواب‬

.Throwable ‫ ﻳﺠﺐ رﻣﻲ ﻛﺎﺋﻨﺎت ﺗﺮث ﻣﻦ‬.(int) ‫ ﻻ ﻳﻤﻜﻨﻚ رﻣﻲ ﻗﻴﻢ ﺑﺪاﺋﻴﺔ‬،‫ ﻓﻲ اﻟﺠﺎﻓﺎ‬:‫الشرح‬

Output: throw new Test(); (Test extends Exception). Catch, then Finally. :Q
A) Got Test Exception - Inside finally

A :‫الجواب‬

.finally ‫ ﺛﻢ ﺗﻨﻔﻴﺬ ﻛﻮد اﻟـ‬،‫ وﻃﺒﺎﻋﺔ اﻟﺮﺳﺎﻟﺔ‬catch ‫ ﻳﺘﻢ اﻟﺘﻘﺎط اﻟﺨﻄﺄ ﻓﻲ اﻟـ‬:‫الشرح‬

Logic Error: int z = y/x (x=0). No try-catch. :Q


C) Compiles fine but throws ArithmeticException

C :‫الجواب‬

.Compilation ‫( وﻟﻴﺲ‬Runtime) ‫( ﺧﻄﺄ وﻗﺖ اﻟﺘﺸﻐﻴﻞ‬integers) ‫ اﻟﻘﺴﻤﺔ ﻋﲆ ﺻﻔﺮ‬:‫الشرح‬

Exception Scope: int b = 20/a; (Error here). Print b. :Q


Divide by zero error - inside finally

Msg :‫الجواب‬

.‫( ﻟﻦ ﺗﻨﻔﺬ ﻷن اﻟﺒﺮﻧﺎﻣﺞ ﻗﻔﺰ ﻋﻨﺪ ﺣﺪوث اﻟﺨﻄﺄ‬println(”b = ” + b ‫ ﺟﻤﻠﺔ اﻟﻄﺒﺎﻋﺔ‬:‫الشرح‬

Exception inside Loop: catch(Exception) before catch(IndexOutOfBounds). :Q


A) Compiler error

A :‫الجواب‬

.‫ ﻻ ﻳﺠﻮز وﺿﻊ اﻷب ﻗﺒﻞ اﻻﺑﻦ‬...ArrayIndex ‫ ﻫﻮ اﻷب ﻟـ‬Exception :‫الشرح‬

String Concatenation (A->B->C exception flow). :Q


abdec

abdec :‫الجواب‬

.c ‫ ﻳﻤﺴﻚ وﻳﻀﻴﻒ‬e (finally). A ‫ ﻳﻤﺴﻚ وﻳﻀﻴﻒ‬B .‫ ﻳﺮﻣﻲ ﺧﻄﺄ‬d. C ‫ ﻳﻀﻴﻒ‬a, b. B ‫ ﻳﻀﻴﻒ‬A :‫الشرح‬

Variable Scope & Increment (count++ in try/catch). :Q


5

5 :‫الجواب‬

.(outer try (1)، inner try (2)، inner block (3)، inner catch (4)، outer catch (5 ‫ ﻳﺰداد ﻓﻲ‬count :‫الشرح‬

9
Hierarchy: Super class of all errors? :Q
Throwable

Throwable :‫الجواب‬

.Error ‫ و‬Exception ‫ ﻫﻮ اﻟﺠﺬر ﻟﻜﻞ ﻣﻦ‬Throwable :‫الشرح‬

Nested Try with Error: throw Error -> catch Error -> throw Runtime -> catch Throwable. :Q
phew

phew :‫الجواب‬

.Throwable ‫( ﺗﻢ اﻹﻣﺴﺎك ﺑﻪ ﺑﻮاﺳﻄﺔ‬Runtime) ‫ اﻟﺨﻄﺄ اﻟﺜﺎﻧﻲ‬.‫ اﻟﺨﻄﺄ اﻷول ﺗﻢ اﻹﻣﺴﺎك ﺑﻪ‬:‫الشرح‬

(Arrays & Strings) ‫ والنصوص‬،‫ القوائم‬،‫ المصفوفات‬:ً‫رابعا‬

The method length() of a File returns: :Q


c) Number of bytes in a file

c) Bytes :‫الجواب‬

.bytes ‫ ﺗﻌﻴﺪ ﺣﺠﻢ اﻟﻤﻠﻒ ﺑﻮﺣﺪة اﻟـ‬File ‫)( ﻓﻲ ﻛﻼس‬length ‫ اﻟﺪاﻟﺔ‬:‫الشرح‬

ArrayList method for size: :Q


a) size()

a) size() :‫الجواب‬

.‫)( ﻟﻤﻌﺮﻓﺔ ﻋﺪد اﻟﻌﻨﺎﺻﺮ‬size ‫ ﺗﺴﺘﺨﺪم اﻟﺪاﻟﺔ‬ArrayList ‫ اﻟـ‬:‫الشرح‬

Collection implementing dynamic array: :Q


c) ArrayList

c) ArrayList :‫الجواب‬

.‫ ﻫﻲ ﺗﻄﺒﻴﻖ ﻟﻤﻔﻬﻮم اﻟﻤﺼﻔﻮﻓﺔ اﻟﺪﻳﻨﺎﻣﻴﻜﻴﺔ‬ArrayList ‫ اﻟـ‬:‫الشرح‬

Analyze: [Link](3, ”Hong Kong”) on list of size 3. :Q


a) Runtime error

a :‫الجواب‬

.add ‫ ﻳﺠﺐ اﺳﺘﺨﺪام‬.‫ ﺗﺴﺒﺐ ﺧﻄﺄ ﻷن ﻫﺬا اﻟﻤﻮﻗﻊ ﻏﻴﺮ ﻣﻮﺟﻮد‬index 3 ‫ ﻟﻠـ‬set ‫ ﻣﺤﺎوﻟﺔ ﻋﻤﻞ‬:‫الشرح‬

10
Insert at specific position: :Q
c) [Link](1, ”Chicago”)

c :‫الجواب‬

.‫( ﺗﻘﻮم ﺑﺈزاﺣﺔ اﻟﻌﻨﺎﺻﺮ وإﺿﺎﻓﺔ اﻟﻌﻨﺼﺮ اﻟﺠﺪﻳﺪ‬add(index, element ‫ اﻟﺪاﻟﺔ‬:‫الشرح‬

ArrayList Removal: remove(”red”) from ”red”, ”green”, ”red”. :Q


b) {”green”, ”red”, ”green”}

b :‫الجواب‬

.‫( ﺗﺤﺬف أول ﻇﻬﻮر ﻟﻠﻌﻨﺼﺮ ﻓﻘﻂ‬remove(Object ‫ اﻟﺪاﻟﺔ‬:‫الشرح‬

Removing inside a loop (Logic check). :Q


Logic Error

Info :‫الجواب‬

.‫ ﻋﻜﺴﻴﺔ ﻟﻀﻤﺎن ﻓﺤﺺ ﺟﻤﻴﻊ اﻟﻌﻨﺎﺻﺮ‬Loop ‫–( أو اﺳﺘﺨﺪام‬i) ‫ ﻳﺠﺐ إﻧﻘﺎص اﻟﻌﺪاد‬،Loop ‫ ﻋﻨﺪ اﻟﺤﺬف داﺧﻞ‬:‫الشرح‬

[Link](Object[]) without Comparable. :Q


d) Runtime error

d :‫الجواب‬

.Comparable ‫ ﻳﺠﺐ أن ﻳﻄﺒﻖ اﻟﻜﻼس واﺟﻬﺔ‬،Objects ‫ ﻟﺘﺮﺗﻴﺐ ﻣﺼﻔﻮﻓﺔ‬:‫الشرح‬

String Equality: s1 == s2 vs [Link](s2). :Q


c) false true

c :‫الجواب‬

.(true) ‫ ﺗﻘﺎرن اﻟﻤﺤﺘﻮى‬false)، equals) ‫ == ﺗﻘﺎرن اﻟﺬاﻛﺮة‬:‫الشرح‬

Object Equality: new Object() == new Object(). :Q


a) false false

a :‫الجواب‬

.(‫ ﺗﻌﻤﻞ ﻣﺜﻞ == )ﺗﻘﺎرن اﻟﺬاﻛﺮة‬equals ‫ اﻟﺪاﻟﺔ‬،‫ اﻷﺳﺎﺳﻲ‬Object ‫ ﻓﻲ ﻛﻼس‬:‫الشرح‬

(JDBC & Files) ‫ والملفات‬JDBC :ً‫خامسا‬

11
JDBC: Method for insert, update, delete? :Q
c) executeUpdate()

c :‫الجواب‬

.‫)( ﻟﻼﺳﺘﻌﻼم‬executeQuery ‫ و‬،(DML) ‫)( ﻟﺠﻤﻞ اﻟﺘﻌﺪﻳﻞ‬executeUpdate ‫ ﻧﺴﺘﺨﺪم‬:‫الشرح‬

Changing DBMS in JDBC requires changing Java code? :Q


a) True (No change needed)

a :‫الجواب‬

.Driver ‫ اﻟﺘﻐﻴﻴﺮ ﻳﻜﻮن ﻓﻘﻂ ﻓﻲ اﻟـ‬،‫ اﻟﻜﻮد اﻟﻤﻜﺘﻮب ﺑﺎﻟﺠﺎﻓﺎ ﻳﺒﻘﻰ ﻛﻤﺎ ﻫﻮ‬:‫الشرح‬

Check if file exists: :Q


b) new File(”c:\temp\[Link]”).exists()

b :‫الجواب‬

.Escape ‫ ﻧﺴﺘﺨﺪم \\ﻷن \ﺣﺮف‬Windows ‫ ﻓﻲ‬.()exists ‫ ﻧﺴﺘﺨﺪم اﻟﺪاﻟﺔ‬:‫الشرح‬

(Coding Solutions) ‫ الحلول البرمجية‬:ً‫سادسا‬

1. UML Mapping (Circle & Resizable) :Q

GeometricObject Interface . 1 / / 1

} GeometricObject interface public 2


; ( ) getPerimeter double public 3
; ( ) getArea double public 4
{ 5
6
Resizable Interface . 2 / / 7

} Resizable interface public 8


; ( percent int ) resize void public 9
{ 10
11
Circle Class . 3 / / 12
} GeometricObject implements Circle class public 13

; 1.0 = radius double protected 14


15
} ( radius double ) Circle public 16
; radius = radius . this 17
{ 18
19

Override @ 20
} ( ) getPerimeter double public 21
; PI . Math * radius * 2 return 22
{ 23
24

12
Override @ 25
} ( ) getArea double public 26
; radius * radius * PI . Math return 27
{ 28
{ 29

30
ResizableCircle Class . 4 / / 31
} Resizable implements Circle extends ResizableCircle class public 32
33
} ( radius double ) ResizableCircle public 34

; ( radius ) super 35
{ 36
37
Override @ 38
} ( percent int ) resize void public 39
; ( 100.0 / percent ) * radius = radius . this 40

{ 41
{ 42

2. ArrayList & instanceof :Q

; student_arraylist package 1
; ArrayList . util . java import 2

3
} Main class public 4
} ( args [ ] String ) main void static public 5
" s1 " object Student a Create ( A / / 6
; ( 123 , " Ahmad " ) Student new = s1 Student 7
8

" p1 " object Person a Create ( B / / 9


; ( " Haneen " ) Person new = p1 Person 10
11
" persons " ArrayList an Create ( C / / 12
; ( ) < > ArrayList new = persons < Person > ArrayList 13
14

list the to objects Add ( D / / 15


; ( s1 ) add . persons 16
; ( p1 ) add . persons 17
18
( E ) in method using information Print ( F / / 19
; ( persons ) printList 20

{ 21
22
" printList " method Write ( E / / 23
} ( list < Person > ArrayList ) printList void static public 24
} ( list : p Person ) for 25
} ( Student instanceof p ) if 26

ID and Name print , student If / / 27


Downcasting / / ; p ( Student ) = s Student 28
. s + " : ID , " + ( ) getName . s + " : Name Student " ) println . out . System 29
; ( ( ) getID
} else { 30
Name print , Person just If / / 31

; ( ( ) getName . p + " : Name Person " ) println . out . System 32


{ 33
{ 34
{ 35
{ 36

3. Threading Search :Q

13
; advfinal package 1

2
} Runnable implements SearchArray class public 3
; a [ ] int 4
for search to number The / / ; n int 5
6
} ( n int , a [ ] int ) SearchArray public 7

; a = a . this 8
; n = n . this 9
{ 10
11
} ( ) findElement int public 12
} ( + + i ; length . a > i ; 0 = i int ) for 13

; i return ( n = = [ i ] a ) if 14
{ 15
; 1 - return 16
{ 17
18
Override @ 19

} ( ) run void public 20


; ( ) findElement = index int 21
} ( 1 - = ! index ) if 22
; ( index + " index at " + n + " Found " ) println . out . System 23
} else { 24
; ( " . found not " + n ) println . out . System 25

{ 26
{ 27
{ 28
29
Main in Usage / / 30
*/ 31

; ( 3 ) newFixedThreadPool . Executors = threadExecuter ExecutorService 32


; ( ( 2 , array ) SearchArray new ) execute . threadExecuter 33
; ( ) shutdown . threadExecuter 34
/* 35

4. JDBC Connection :Q

} Company class public 1


; null = conn Connection 2
3
} ( ) openConnection void public 4
} try 5
; ( " JDBC . sqlite . org " ) forName . Class 6

; ( " db . CompanyDB \ \ : D : sqlite : jdbc " ) getConnection . DriverManager = conn 7


} ( e Exception ) catch { 8
; ( ) printStackTrace . e 9
{ 10
{ 11
12

} ( ) closeConnection void public 13


} try 14
; ( ) close . conn ( null = ! conn ) if 15
} ( ex SQLException ) catch { 16
; ( ) printStackTrace . ex 17
{ 18

{ 19
20
} ( ) displayEmployees void 21
} try 22
; ( ) createStatement . conn = stmt Statement 23

14
; ( " Employees FROM * SELECT " ) executeQuery . stmt = rs ResultSet 24
25
; ( " tSalary \ tempName \ empID " ) println . out . System 26
} ( ( ) next . rs ) while 27
; ( " empID " ) getInt . rs = id int 28

; ( " empName " ) getString . rs = name String 29


; ( " Salary " ) getDouble . rs = salary double 30
; ( salary + " t \ " + name + " t \ " + id ) println . out . System 31
{ 32
} ( e SQLException ) catch { 33

; ( ) printStackTrace . e 34
{ 35
{ 36
{ 37

5. File I/O :Q

; advfinal package 1
; * . io . java import 2
; Scanner . util . java import 3
4
} ReadWrite class public 5

} ( args [ ] String ) main void static public 6


} try 7
( drive D from Reading ) Input Setup / / 8
; ( " txt . weights \ \ : D " ) File new = inputFile File 9
; ( inputFile ) Scanner new = input Scanner 10
11

Output Setup / / 12
; ( " txt . result \ \ : D " ) PrintWriter new = output PrintWriter 13
14
; 0 = sum double 15
; 0 = count int 16
17

file through Loop / / 18


} ( ( ) hasNext . input ) while 19
} ( ( ) hasNextDouble . input ) if 20
; ( ) nextDouble . input = + sum 21
; + + count 22
} else { 23

tokens double - non Skip / / ; ( ) next . input 24


{ 25
{ 26
27
Write and Average Calculate / / 28
} ( 0 < count ) if 29

; count / sum = average double 30


; ( average + " : weight Average " ) println . output 31
} else { 32
; ( " . found data No " ) println . output 33
{ 34
35

resources Close / / 36
; ( ) close . input 37
; ( ) close . output 38
39
} ( ex FileNotFoundException ) catch { 40
; ( " file find cannot " ) println . out . System 41

} ( ex IOException ) catch { 42
; ( " file from read cannot " ) println . out . System 43
{ 44

15
{ 45
{ 46

16

You might also like