Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

جافا سؤال وجواب

879 views

Published on

Java interview questions Arabic

Published in: Education
  • Be the first to comment

جافا سؤال وجواب

  1. 1. ١        
  2. 2. ٢ ‫ﺍﻟﺮﺣﻴﻢ‬‫ﺍﻟﺮﲪﻦ‬‫ﺍﷲ‬‫ﺑﺴﻢ‬ ، ‫اﻟﻛرﯾم‬ ‫ﻟوﺟﮫ‬ ‫ﺧﺎﻟص‬ ‫وﯾﺟﻌﻠﮫ‬ ‫اﻟﻌﻣل‬ ‫ھذا‬ ‫ﯾﺗﻘﺑل‬ ‫أن‬ ‫ﷲ‬ ‫أﺳﺄل‬ ‫ﻻ‬ ‫وﻛذﻟك‬ ، ‫واﺣد‬ ‫ﺑﺳؤال‬ ‫وﻟو‬ ‫اﻟﻛﺗﺎب‬ ‫ﻓﻲ‬ ‫ﺳﺎھم‬ ‫ﻣن‬ ‫ﻛل‬ ‫وأﺷﻛر‬ ‫ﻣن‬ ‫ﯾﻘدﻣوه‬ ‫ﻟﻣﺎ‬ ‫ﻟﻠﺑرﻣﺟﺔ‬ ‫اﻟﻌرﺑﻲ‬ ‫اﻟﻔرﯾﻖ‬ ‫ﻣﻧﺗدﯾﺎت‬ ‫أﺷﻛر‬ ‫أﻧﺳﻰ‬ ‫ﺑﻌض‬ ‫أﺧذ‬ ‫ﺗم‬ ‫)وﻗد‬ ‫اﻟﻌرﺑﻲ‬ ‫ﻟﻠﻣﺣﺗوى‬ ‫إﺛراء‬. (‫ﻣﻧﮭم‬ ‫اﻷﺳﺋﻠﺔ‬ ... ‫اﻟﻐﯾب‬ ‫ظﮭر‬ ‫ﻓﻲ‬ ‫دﻋﺎﺋﻛم‬ ‫ﺻﺎﻟﺢ‬ ‫ﻣن‬ ‫اﻟﻣﺳﺎھﻣﯾن‬ ‫وﺟﻣﯾﻊ‬ ‫ﺗﻧﺳوﻧﻲ‬ ‫وﻻ‬..
  3. 3. ٣ ‫اﻟﻣﺣﺗوﯾﺎت‬ ‫اﻟﺻﻔ‬‫ـ‬‫ﺣﺔ‬ ‫اﻷﺳﺎﺳﯾﺎت‬ : ‫اﻷوﻟﻰ‬ ‫اﻟوﺣدة‬ ‫س‬١.................. ‫ﺟﺎﻓﺎ‬ ‫ﻟﻐﺔ‬ :....٨ ‫س‬٢................... ‫ﻣﻣﯾزاﺗﮭﺎ‬ :٨ ‫س‬٣.................. ‫اﺻداراﺗﮭﺎ‬ :٩ ‫س‬٤.......... ‫اﻟﺟﺎﻓﺎ‬ ‫ﻣﻊ‬ ‫اﻟوﻗت‬ :....٩ ‫س‬٥................... ‫اﻟﺟﺎﻓﺎ‬ ‫اﻧﺗﺷﺎر‬ :١٠ ‫س‬٦................ ‫اﻟﻣﺣﺟوزة‬ ‫اﻟﻛﻠﻣﺎت‬ :١١ ‫س‬٧‫ﺗﺳﻣﯾﺔ‬ ‫اﻋﺎدة‬ :class...............١١ ‫س‬٨:variable‫و‬value.................١١ ‫س‬٩:‫اﻟﻛوﻧﺳﺗراﻛﺗر‬...................١١ ‫س‬١٠:........... ‫ﻛﻼس‬ ‫ﻣن‬ ‫ﻛﺎﺋن‬ ‫إﻧﺷﺎء‬١٢ ‫س‬١١:private & protected & public.... ‫ﻟﻠﻣﺗﻐﯾرات‬١٢ ‫س‬١٢.......... ‫ﻣﺗﻐﯾر‬ ‫ﻓﻲ‬ ‫ﻗﯾﻣﺔ‬ ‫ﺗﺧزﯾن‬ :.١٣ ‫س‬١٣.... ‫ﻣﺗﻐﯾر‬ ‫ﻓﻲ‬ ‫ﻣﺗﻐﯾر‬ ‫ﻣﺳﺎواة‬ :١٤ ‫س‬١٤... ‫ﻟﻠﻣﺗﻐﯾر‬ ‫اﻹﺑﺗداﺋﯾﺔ‬ ‫اﻟﻘﯾﻣﺔ‬ ‫ﺗﻌطﻰ‬ ‫ﻟم‬ ‫إذا‬ :١٤ ‫س‬١٥......... ‫اﻟﻣﺗﻐﯾرات‬ ‫ﺗﺳﻣﯾﺔ‬ ‫ﻗواﻋد‬ :١٤ ‫س‬١٦‫اﻟﻣﺗﻐﯾرات‬ ‫ﻋﻠﻰ‬ ‫اﻟرﯾﺎﺿﯾﺔ‬ ‫اﻟﻌﻠﻣﯾﺎت‬ :.....١٥ ‫س‬١٧...... ‫ﻟﻠﻣﺗﻐﯾر‬ ‫ﻗﯾﻣﺔ‬ ‫ﺿﺑط‬ :١٦ ‫س‬١٨‫ﺑوﻟﯾﺎن‬ ‫اﻟﻣﺗﻐﯾر‬ :Boolean.....١٦
  4. 4. ٤ ‫س‬١٩:if & else............١٨ ‫س‬٢٠:Switch...........١٩ ‫س‬٢١‫اﻟـ‬ ‫أﻧواع‬ :Methods........٢١ ‫س‬٢٢‫اﻟـ‬ :Packages..........٢٢ ‫س‬٢٣:overriding & overloading....٢٢ ‫س‬٢٤:............ ‫اﻟﻣﺗﻐﯾرات‬ ‫أﻧواع‬٢٢ ‫س‬٢٥:escape sequence......٢٢ ‫س‬٢٦‫ﻣﻌﻧﻰ‬ :static.....٢٣ ‫س‬٢٧‫ﺑﺎﻛﺞ‬ :java.lang.*.......٢٣ ‫س‬٢٨...... ‫اﻟﻣﻘﺎرﻧﺔ‬ ‫ﺟﻣل‬ ‫ﻓﻲ‬ && ‫و‬ & :٢٣ ‫س‬٢٩(‫)اﻟداﻟﺔ‬ ‫اﻟطرﯾﻘﺔ‬ :toString().....٢٤ ‫س‬٣٠‫ﻋﻣل‬ :Compile...... ‫ﺟﺎﻓﺎ‬ ‫ﻟﻣﻠف‬٢٧ ‫س‬٣١.......... ‫اﻟﺟﺎﻓﺎ‬ ‫ﺑرﻧﺎﻣﺞ‬ ‫ﺗﺷﻐﯾل‬ :٢٧ ‫س‬٣٢‫ﻣﺻطﻠﺢ‬ :Casting........٢٧ ‫س‬٣٣................. ‫اﻟﺛواﺑت‬ :٢٨ ‫س‬٣٤:global & local & static & dynamic...٢٨ ‫س‬٣٥:String & StringBuffer...٢٩ ‫س‬٣٦‫ﻛﻼس‬ :GregorianCalendar....٢٩ ) ‫اﻟوراﺛﺔ‬Inheritance( ‫س‬٣٧) ‫اﻟوراﺛﺔ‬ ‫ﻣﻌﻧﻰ‬ :inheritance.... (٢٩
  5. 5. ٥ ‫س‬٣٨...... ‫اﻹﺑن‬ ‫ﻣن‬ ‫اﻷب‬ ‫إﻟﻰ‬ ‫اﻟوﺻول‬ :٣٠ ) ‫اﻹﺳﺗﺛﻧﺎءات‬Exceptions( ‫س‬٣٩............... ‫اﻹﺳﺗﺛﻧﺎءات‬ :٣٠ ‫س‬٤٠............. ‫اﻹﺳﺗﺛﻧﺎءات‬ ‫ﺣﻣل‬ :٣١ ‫س‬٤١............... ‫اﻹﺳﺗﺛﻧﺎءات‬ ‫أﻧواع‬ :٣١ ‫ﻋﺎم‬ ‫س‬٤٢............... ‫ﻛود‬ ‫اﻵﺳﻛﻲ‬ :٣٢ ‫س‬٤٣‫ﻣﺻطﻠﺢ‬ :Deprecated............٣٣ ‫س‬٤٤:Generic Class...............٣٣ ‫س‬٤٥:Interface...............٣٤ GUI ‫س‬٤٦‫اﻟرﺳوﻣﯾﺔ‬ ‫اﻟﻣﺳﺗﺧدم‬ ‫واﺟﮭﺔ‬ :GUI.......٣٤ ‫س‬٤٧:JFrame..........٣٥ ‫س‬٤٨‫اﺳﺗﺧدام‬ ‫طرق‬ :JFrame.........٣٥ ‫س‬٤٩....... ‫ﺑﺎﻟﻛود‬ ‫ﻣرﺋﯾﺔ‬ ‫واﺟﮭﺔ‬ ‫ﻋﻣل‬ :٣٥ ‫س‬٥٠:Swing..........٤٣ ‫س‬٥١‫ﻣﻛﺗﺑﺔ‬ :SWT...........٤٤ ‫س‬٥٢:static & methods.......٤٤ ‫س‬٥٣......... ‫اﻟواﺟﮭﺎت‬ ‫ﻣﻛﺗﺑﺎت‬ :٤٤ ‫س‬٥٤‫ﻛﻼس‬ :Color...... ‫واﻻﺧﺗﻼف‬٤٦
  6. 6. ٦ ‫س‬٥٥........... ‫ﻣﻌﯾﻧﺔ‬ ‫وﯾب‬ ‫ﺻﻔﺣﺔ‬ ‫ﻓﺗﺢ‬ :٤٦ ‫س‬٥٦:......... ‫اﻟﺑرﻧﺎﻣﺞ‬ ‫ﻟﻐﺎت‬ ‫ﺗﻌدد‬٤٧ ‫س‬٥٧‫اﻟﻣﻠﻔﺎت‬ :Properties.......٤٧ ‫س‬٥٨‫ﻓﺋﺔ‬ :Locale.............٤٨ ‫س‬٥٩‫ﻓﺋﺔ‬ :ResourceBuodle...........٤٨ ‫س‬٦٠......... ‫ﻧﺻﻲ‬ ‫ﻣﻠف‬ ‫ﻣﺣﺗوى‬ ‫ﻗراءة‬ :٤٩ ‫س‬٦١‫داﺧل‬ ‫اﻹﻗﻔﺎل‬ ‫أﻣر‬ :finally......٥١ ‫س‬٦٢‫اﻟﻔﺋﺔ‬ ‫ﺑﺎﺳﺗﻌﻣﺎل‬ ‫ﻣﻠف‬ ‫ﻗراءة‬ :Scanner......٥٢ ‫ﻋﺎم‬ ‫س‬٦٣‫اﻟـ‬ :JPA..............٥٣ ‫س‬٦٤:JVM & JRE & JDK........٥٣ Data Structure ‫س‬٦٥:Databases & Data Structures...٥٥ ‫س‬٦٦:LinkedList & ArrayList.....٦١ ‫س‬٦٧:LinkedList & List.....٦٣ ‫س‬٦٨.......... ‫ﻣﺻﻔوﻓﺔ‬ ‫ﺗرﺗﯾب‬ :٦٣ ‫ﻋﺎم‬ ‫س‬٦٩:Java Annotations......٦٤ ‫س‬٧٠..... ‫ﺟدﯾدة‬ ‫ﺣواﺷﻲ‬ ‫ﺑرﻣﺟﺔ‬ :٦٨ ‫س‬٧١........ ‫اﻟﺣواﺷﻲ‬ ‫ﻣﻌﺎﻟﺟﺔ‬ :٧٣
  7. 7. ٧ Databases ‫س‬٧٢:‫ﺑﺎﻟﺟﺎﻓﺎ‬ ‫أﻛﺳس‬ ‫ﺑﯾﺎﻧﺎت‬ ‫ﻗﺎﻋدة‬ ‫رﺑط‬......٨٢ Graphics 2D ‫س‬٧٣‫ھﻧدﺳﯾﺔ‬ ‫أﺷﻛﺎل‬ ‫رﺳم‬ :................٩٦ ‫ﺟﺎھزة‬ ‫ﻣﺷﺎرﯾﻊ‬ ٧٤........... ‫ﺑﺎﻟرﺳﺎم‬ ‫ﺷﺑﯾﮫ‬ ‫ﺑرﻧﺎﻣﺞ‬ ‫ﻋﻣل‬ :١٠٠ ٧٥:capture‫اﻟﺷﺎﺷﺔ‬ ‫ﺗﺻوﯾر‬..........١١٩ ٧٦:splash............. ‫اﻟﺗﺣﻣﯾل‬ ‫ﺟﺎري‬١٢٢ ٧٧:open net..........................١٢٤ ٧٨:count letter.... ‫اﻟﺣروف‬ ‫ظﮭور‬ ‫ﺣﺳﺎب‬١٢٥ ٧٩:draw Time.......... ‫ﺟدا‬ ‫رھﯾب‬١٢٧ ٨٠:Color.... ‫ﻧوﻋﮫ‬ ‫وﺗﻐﯾﯾر‬ ‫اﻟﺧط‬ ‫ﺗﻠوﯾن‬١٣٣ ٨١:clac......... ‫اﻟﺟﺎﻓﺎ‬ ‫ﺑﺎﺳﺗﺧدام‬ ‫ﺣﺎﺳﺑﺔ‬١٣٥ ‫اﻟﻛﺗﺎب‬ ‫ﻓﻲ‬ ‫اﻟﻣﺷﺎرﻛﯾن‬ ‫أﺳﻣﺎء‬١٤٣
  8. 8. ٨ ‫اﻷﺳﺎﺳﯾﺎت‬ ‫س‬١:‫؟‬ ‫ﺑداﯾﺎﺗﮭﺎ‬ ‫ھﻲ‬ ‫وﻣﺎ‬ ‫ﺟﺎﻓﺎ‬ ‫ﻟﻐﺔ‬ ‫ﻣﺎھﻲ‬ ‫ﺟﺎﻓﺎ‬)Java(‫ھﻲ‬‫ﻋﺑﺎرة‬‫ﻋن‬‫ﻟﻐﺔ‬‫ﺑرﻣﺟﺔ‬‫اﺑﺗﻛرھﺎ‬‫ﺟﯾﻣس‬‫ﺟوﺳﻠﯾﻧﺞ‬‫ﻓﻲ‬‫ﻋﺎم‬١٩٩٢‫م‬ ‫أﺛﻧﺎء‬‫ﻋﻣﻠﮫ‬‫ﻓﻲ‬‫ﻣﺧﺗﺑرات‬‫ﺷرﻛﺔ‬‫ﺻن‬،‫ﻣﯾﻛروﺳﯾﺳﺗﻣز‬‫وذﻟك‬‫ﻻﺳﺗﺧداﻣﮭﺎ‬‫ﺑﻣﺛﺎﺑﺔ‬‫اﻟﻌﻘل‬ ‫اﻟﻣﻔﻛر‬‫اﻟﻣﺳﺗﺧدم‬‫ﻟﺗﺷﻐﯾل‬‫اﻷﺟﮭزة‬‫اﻟﺗطﺑﯾﻘﯾﺔ‬‫اﻟذﻛﯾﺔ‬‫ﻣﺛل‬‫اﻟﺗﯾﻠﻔزﯾون‬،‫اﻟﺗﻔﺎﻋﻠﻲ‬‫وﻗد‬‫ﻛﺎﻧت‬ ‫ﻟﻐﺔ‬‫اﻟﺟﺎﻓﺎ‬‫ا‬ ً‫ﺗطوﯾر‬‫ﻟﻠﻐﺔ‬‫اﻟﺳﻲ‬‫ﺑﻼس‬‫ﺑﻼس‬)C(++،‫وﻋﻧد‬‫وﻻدﺗﮭﺎ‬‫أطﻠﻖ‬‫ﻋﻠﯾﮭﺎ‬‫ﻣﺑﺗﻛرھﺎ‬ "‫أواك‬"‫ﺑﻣﻌﻧﻰ‬‫ﺷﺟرة‬‫اﻟﺳﻧدﯾﺎن؛‬‫وھﻲ‬‫اﻟﺷﺟرة‬‫اﻟﺗﻲ‬‫ﻛﺎن‬‫ﯾراھﺎ‬‫ﻣن‬‫ﻧﺎﻓذة‬‫ﻣﻛﺗﺑﮫ‬‫وھو‬ ‫ﯾﻌﻣل‬‫ﻓﻲ‬‫ﻣﺧﺗﺑرات‬‫ﺻن‬،‫ﻣﯾﻛروﺳﯾﺳﺗﻣز‬‫ﺛم‬‫ﺗﻐﯾر‬‫اﻻﺳم‬‫إﻟﻰ‬،‫ﺟﺎﻓﺎ‬‫وھذا‬‫اﻻﺳم‬)‫ﻋﻠﻰ‬ ‫ﻏﯾر‬‫اﻟﻌﺎدة‬‫ﻓﻲ‬‫ﺗﺳﻣﯾﺔ‬‫ﻟﻐﺎت‬‫اﻟﺑرﻣﺟﺔ‬(‫ﻟﯾس‬‫اﻟﺣروف‬‫اﻷوﻟﻰ‬‫ﻣن‬‫ﻛﻠﻣﺎت‬‫ﺟﻣﻠﺔ‬‫ﻣﻌﯾﻧﺔ‬‫أو‬ ‫ﺗﻌﺑﯾرا‬‫ﺑﻣﻌﻧﻰ‬،‫ﻣﻌﯾن‬‫وﻟﻛﻧﮫ‬‫ﻣﺟرد‬‫اﺳم‬‫وﺿﻌﮫ‬‫روا‬ ّ‫ﻣطو‬‫ھذه‬‫اﻟﻠﻐﺔ‬‫ﻟﯾﻧﺎﻓس‬‫اﻷﺳﻣﺎء‬ ،‫اﻷﺧرى‬‫وھﻰ‬‫اﺣدى‬‫ﻟﻐﺎت‬،‫اﻟﺑرﻣﺟﺔ‬‫أي‬‫ﻣﺟﻣوﻋﺔ‬‫ﻣن‬‫اﻷواﻣر‬‫واﻟﺗﻌﻠﯾﻣﺎت‬‫اﻟﺗﻲ‬‫ﺗﻌطﻰ‬ ‫ﻟﻠﺣﺎﺳب‬‫ﻓﻲ‬‫ﺻورة‬‫ﺑرﻧﺎﻣﺞ‬‫ﻣﻛﺗوب‬‫ﺑﻠﻐﺔ‬‫ﺑرﻣﺟﺔ‬‫ﻣﻌﯾﻧﺔ‬‫ﺑواﺳطﺔ‬‫ﻣﻌﺎﻟﺞ‬،‫ﻧﺻوص‬ ‫وﯾﺗﻛون‬‫ﻣﺻدر‬‫اﻟﺑرﻧﺎﻣﺞ‬‫ﻣن‬‫ﻋدة‬‫ﺳطور‬‫وﻛل‬‫ﺳطر‬‫ﯾﻌﺗﺑر‬،‫ﺟﻣﻠﺔ‬‫وﯾﺗﻌﺎﻣل‬‫اﻟﺣﺎﺳب‬‫ﻣﻊ‬ ‫ﻛل‬‫ﺟﻣﻠﺔ‬‫ﺑﺗرﺗﯾب‬‫ﻣﻌﯾن‬‫ﻹﻧﺟﺎز‬‫اﻷﻣر‬‫اﻟذي‬‫ﺻﻣم‬‫اﻟﺑرﻧﺎﻣﺞ‬‫ﻟﺗﺣﻘﯾﻘﮫ‬. ‫س‬٢‫؟‬ ‫ﺟﺎﻓﺎ‬ ‫ﻟﻐﺔ‬ ‫ﻣﻣﯾزات‬ ‫ﻣﺎھﻲ‬ : ‫اﻟﺳﮭوﻟﺔ‬. ‫داﻋﻣﺔ‬‫و‬‫ﻣوﺟﮭﺔ‬‫ﻟﻠﻛﯾﺎﻧﺎت‬. ‫ﺳﮭوﻟﺔ‬‫اﻟﺣﺻول‬‫ﻋﻠﯾﮭﺎ‬. ‫آ‬‫ﻣﻧﺔ‬. ‫ﻗﺎﺑﻠﺔ‬‫ﻟﻠﻧﻘل‬‫و‬‫اﻟﺗﻧﻔﯾذ‬. ‫إﺿﺎﻓﺔ‬‫اﻟﺣرﻛﺔ‬‫واﻟﺻوت‬‫إﻟﻰ‬‫ﺻﻔﺣﺎت‬‫اﻟوﯾب‬. ‫ﻛﺗﺎﺑﺔ‬‫اﻷﻟﻌﺎب‬‫واﻟﺑراﻣﺞ‬‫اﻟﻣﺳﺎﻋدة‬. ‫إﻧﺷﺎء‬‫ﺑراﻣﺞ‬‫ذات‬‫واﺟﮭﺔ‬‫ﻣﺳﺗﺧدم‬‫رﺳوﻣﯾﺔ‬. ‫ﺗﺻﻣﯾم‬‫ﺑرﻣﺟﯾﺎت‬‫ﺗﺳﺗﻔﯾد‬‫ﻣن‬‫ﻛل‬‫ﻣﻣﯾزات‬‫اﻷﻧﺗرﻧت‬.‫ﺗوﻓر‬‫ﻟﻐﺔ‬‫اﻟﺟﺎﻓﺎ‬‫ﺑﯾﺋﺔ‬‫ﺗﻔﺎﻋﻠﯾﺔ‬ ‫ﻋﺑر‬‫اﻟﺷﺑﻛﺔ‬‫اﻟﻌﻧﻛﺑوﺗﯾﺔ‬‫وﺑﺎﻟﺗﺎﻟﻲ‬‫ﺗﺳﺗﻌﻣل‬‫ﻟﻛﺗﺎﺑﺔ‬‫ﺑراﻣﺞ‬‫ﺗﻌﻠﯾﻣﯾﺔ‬‫ﻟﻺﻧﺗرﻧت‬‫ﻋﺑر‬ ‫ﺑرﻣﺟﯾﺎت‬‫اﻟﻣﺣﺎﻛﺎة‬‫اﻟﺣﺎﺳوﺑﯾﺔ‬‫ﻟﻠﺗﺟﺎرب‬‫اﻟﻌﻠﻣﯾﺔ‬‫وﺑرﻣﺟﯾﺎت‬‫اﻟﻔﺻول‬‫اﻻﻓﺗراﺿﯾﺔ‬ ‫ﻟﻠﺗﻌﻠﯾم‬‫اﻹﻟﻛﺗروﻧﻲ‬‫واﻟﺗﻌﻠﯾم‬‫ﻋن‬‫ﺑﻌد‬.‫ﻻ‬‫ﺗﻧﺣﺻر‬‫ﻓﺎﻋﻠﯾﺔ‬‫اﻟﺟﺎﻓﺎ‬‫ﻓﻲ‬‫اﻟﺷﺑﻛﺔ‬
  9. 9. ٩ ‫اﻟﻌﻧﻛﺑوﺗﯾﺔ‬‫ﻓﻘط‬‫ﺑل‬‫ﺗﻣﻛﻧﻧﺎ‬‫ﻣن‬‫إﻧﺷﺎء‬‫ﺑراﻣﺞ‬‫ﻟﻼﺳﺗﻌﻣﺎل‬‫اﻟﺷﺧﺻﻲ‬،‫واﻟﻣﮭﻧﻲ‬‫ھذه‬ ‫اﻟﺑراﻣﺞ‬‫ﺗﻧﺟز‬‫ﻋﺑر‬‫ﺟﻣﻠﺔ‬‫ﻣن‬‫اﻟﺑراﻣﺞ‬‫اﻟﺗﻲ‬‫ﺗﺳﮭل‬‫ﻛﺗﺎﺑﺔ‬‫اﻷواﻣر‬‫ﻛﺑرﻧﺎﻣﺞ‬ NetBeans‫و‬Eclipse. ‫س‬٣‫؟‬ ‫اﻟﺟﺎﻓﺎ‬ ‫إﺻدارات‬ ‫ﻣﺎ‬ : Java SE ‫اﻹﺻدار‬‫اﻟﻘﯾﺎﺳﻲ‬‫ﻣن‬‫اﻟﺟﺎﻓﺎ‬‫ﺑﺎﻹﻧﺟﻠﯾزﯾﺔ‬)Java Standard Edition(‫ھو‬ ‫اﻟﺟزء‬‫اﻟﺧﺎص‬‫ﺑﺑرﻣﺟﺔ‬‫ﺑراﻣﺞ‬‫ﺳطﺢ‬‫اﻟﻣﻛﺗب‬)StandAlone applications.( Java EE ‫اﺻدار‬‫اﻹﻧﺗرﺑراﯾس‬‫ﺑﺎﻹﻧﺟﻠﯾزﯾﺔ‬)Java Enterprise Edition(‫ھو‬‫ﯾﺧﺗﻠف‬ ‫ﻋن‬‫اﻹﺻدار‬‫اﻟﻘﯾﺎﺳﻲ‬‫ﻓﻲ‬‫أﻧﮫ‬‫ﺧﺎص‬‫ﺑﺑرﻣﺟﺔ‬‫اﻟﺧوادم‬‫واﻟﺗطﺑﯾﻘﺎت‬‫اﻟﻣوزﻋﺔ‬ ‫وﺑرﻣﺟﺔ‬‫اﻟوﯾب‬. Java ME ‫اﺻدار‬‫اﻟﻣﺎﯾﻛرو‬‫ﺑﺎﻹﻧﺟﻠﯾزﯾﺔ‬)Java Micro Edition(‫وھو‬‫إﺻدار‬‫ﺧﺎص‬ ‫ﺑﺎﻟﺑرﻣﺟﺔ‬‫ﻋﻠﻰ‬‫اﻟﮭواﺗف‬‫اﻟﻣﺣﻣوﻟﺔ‬‫واﻷﺟﮭزة‬‫اﻟﻣﺣدودة‬‫ﻓﻲ‬‫اﻟﻣﺻﺎدر‬‫ﻋﻣوﻣﺎ‬ ‫وﺗﻌﺗﺑر‬‫اﻟﺧﯾﺎر‬‫اﻷول‬‫ﻟﻣﺑرﻣﺟﻲ‬‫أﻟﻌﺎب‬‫اﻟﮭواﺗف‬‫اﻟﻣﺣﻣوﻟﺔ‬. Java Fx ‫ّﺔ‬‫ﯾ‬‫ﺗﻘﻧ‬‫أﺧرى‬‫اﺻدرﺗﮭﺎ‬‫ﺻن‬‫ﻣﯾﻛروﺳﯾﺳﺗﻣز‬‫ﻟﺗطوﯾر‬‫ﺗطﺑﯾﻘﺎت‬‫ﻣن‬‫ﻧوع‬"RIA"‫أي‬ "Rich Internet Applications." ‫س‬٤‫؟‬ ‫ﻣﺣﺗرف‬ ‫ﺗﺻﺑﺢ‬ ‫ﺣﺗﻰ‬ ‫اﻟﺟﺎﻓﺎ‬ ‫وﺗﻌﻠم‬ ‫ﻣﻣﺎرﺳﺔ‬ ‫ﻣن‬ ‫اﻟوﻗت‬ ‫ﯾﺗطﻠب‬ ‫ﻛم‬ : ‫وﻟﻛﻲ‬ ‫وارادﺗﮫ‬ ‫اﻟﺷﺧص‬ ‫ھﻣﺔ‬ ‫ﺣﺳب‬ ‫ﺗﻛون‬ ‫اﻟﻣدة‬ ‫وطﺑﻌﺎ‬ ‫وﻛﺑﯾرة‬ ‫ھﺎﺋﻠﺔ‬ ‫ﻟﻐﺔ‬ ‫اﻟﺟﺎﻓﺎ‬ . ‫ﺳﻧﯾن‬ ‫ﺧﻣﺳﺔ‬ ‫إﻟﻰ‬ ‫ﺛﻼﺛﺔ‬ ‫ﻟك‬ ‫ﯾﺣﺗﺎج‬ ‫ﺗﻘرﯾﺑﻲ‬ ‫ﻛوﻗت‬ ‫اﻟﻠﻐﺔ‬ ‫ﻓﻲ‬ ‫ﻣﺣﺗرف‬ ‫ﺗﺻﺑﺢ‬
  10. 10. ١٠ ‫س‬٥:‫ھو‬ ‫ﻣﺎ‬‫ﻣدى‬‫اﻧﺗﺷﺎر‬‫اﻟﺟﺎﻓﺎ‬‫ﺧﺻوﺻﺎ‬‫ﻓﻲ‬‫اﻟوطن‬‫اﻟﻌرﺑﻲ؟‬ ‫ﻓﻲ‬‫اﻟﺣﻘﯾﻘﺔ‬‫اﻟﺟﺎﻓﺎ‬‫ﻣﻧﺗﺷرة‬‫ﻓﻲ‬‫اﻟدول‬‫اﻟﻣﺗﻘدﻣﺔ‬‫ﺑﺻورة‬‫ﻛﺑﯾرة‬‫ﺟدا‬‫و‬ً‫ﺧﺻوﺻﺎ‬‫ﻓﻲ‬ )‫اﻣرﯾﻛﺎ‬‫وﺑرﯾطﺎﻧﯾﺎ‬(‫و‬‫ﻟﻛن‬‫ﻣﻊ‬‫اﻻﺳف‬‫ﻓﮭﻲ‬‫ﻋﺎﻟﻣﻧﺎ‬‫اﻟﻌرﺑﻲ‬‫ﻗﻠﯾﻠﺔ‬‫اﻻﻧﺗﺷﺎر‬‫و‬‫أن‬ ‫ﻛﺎﻧت‬‫اﻟﺟﺎﻣﻌﺎت‬‫أدﺧﻠﺗﮭﺎ‬‫و‬‫ﻟﻛن‬‫ﻣﻧذ‬‫ﻣدة‬‫ﺑﺳﯾطﺔ‬ً‫ﻧﺳﺑﯾﺎ‬. ‫س‬٦‫اﻟﻣﺣﺟوزة‬ ‫اﻟﻛﻠﻣﺎت‬ ‫ﻣﺎھﻲ‬ :‫ﻓﻲ‬‫اﻟﻛﻠﻣﺎت‬ ‫اي‬ ‫ﺟﺎﻓﺎ‬ ‫ﻟﻐﺔ‬‫اﻟﺗﻲ‬‫ﻻ‬‫ﺑﺎﺳﺗﺧداﻣﮭﺎ‬ ‫ﯾﺳﻣﺢ‬‫إ‬‫ﻻ‬ ‫؟‬ ‫اﺟﻠﮫ‬ ‫ﻣن‬ ‫اﻧﺷﺄت‬ ‫اﻟذي‬ ‫ﻟﻠﻐرض‬
  11. 11. ١١ ‫س‬٧:‫ﺗﺳﻣﯾﺔ‬ ‫إﻋﺎدة‬ ‫ﯾﻣﻛن‬ ‫ﻛﯾف‬class‫ﻣﻌﯾن‬‫اﻟـ‬ ‫أﺣد‬ ‫ﻋﻠﻰ‬ ‫ﻣن‬IDE‫؟‬ ‫ﻋﻠﻰ‬ ‫اﻟﻘﺎﺋﻣﺔ‬ ‫ﻣن‬ ‫ﺗﺿﻐط‬ ‫ﺛم‬ ‫اﻷﯾﻣن‬ ‫ﺑﺎﻟزر‬ ‫اﻟﻛﻼس‬ ‫ﻋﻠﻰ‬ ‫ﺗﺿﻐط‬Refactor‫ﺗﺧﺗﺎر‬ ‫ﺛم‬ rename‫ﻣﻧك‬ ‫ﺗدﺧل‬ ‫دون‬ ‫ﺗﻠﻘﺎﺋﯾﺎ‬ ‫اﻟﻛود‬ ‫ﻓﻲ‬ ‫اﻻﺳم‬ ‫ﺗﺣدﯾث‬ ‫ﯾﺗم‬ ‫وﺳوف‬ ‫س‬٨‫ﻣﺎ‬ :‫ھو‬‫اﻟﻣﻘﺻود‬‫ﺑـ‬variable‫و‬value‫ﻓﻲ‬‫ﺟﺎﻓﺎ؟‬ Variable:‫ھو‬‫اﻟ‬‫ﻣﺗﻐﯾر‬. Value:‫ھو‬‫اﻋطﺎء‬‫او‬‫اﺳﻧﺎد‬‫ﻗﯾﻣﮫ‬‫ﻟذﻟك‬‫اﻟﻣﺗﻐﯾر‬. ‫؟‬ (Constructor) ‫س‬٩‫ھﻮ‬ ‫ﻣﺎ‬ :‫اﻟﻜﻮﻧﺴﺘﺮاﻛﺘﺮ‬ ‫ﯾﺴﺘﺨﺪم‬‫اﻟﻜﻮﻧﺴﺘﺮاﻛﺘﺮ‬‫ﻹ‬‫ﻋﻄﺎء‬‫اﻟﻘﯿﻢ‬‫اﻷوﻟﯿﺔ‬‫ﻟﻸ‬‫وﺑﺠﻜﺖ‬‫ﻓﻲ‬‫اﻟﻜﻼس‬‫وﯾﻜﻮن‬‫ﻟﮫ‬‫ﻧﻔﺲ‬‫إﺳﻢ‬ ‫اﻟﻜﻼس‬ً ‫ﺗﻤﺎﻣﺎ‬ ‫ھﻨﺎك‬‫اﺧﺘﻼف‬‫ﻣﺎ‬‫ﺑﯿﻦ‬‫اﻟﻜﻮﻧﺴﺘ‬‫ﺮا‬‫ﻛﺘﺮ‬‫واﻟﻤﯿﺜﻮد‬‫ﻓﻲ‬‫ا‬‫ﻵ‬‫ﺗﻲ‬: ‫اﻟﻜﻨﻮﺳﺘﺮاﻛﺘﺮ‬:‫ﯾﺴﺘﺨﺪم‬‫ﻹ‬‫ﻋﻄﺎء‬‫اﻟﻘﯿﻢ‬‫اﻻﺑﺘﺪاﺋﯿﺔ‬‫ﻟﻸ‬‫وﺑﺠﻜﺖ‬‫ﻋﻨﺪ‬‫ﺧﻠﻘﮫ‬. . ‫اﻟﻤﯿﺜﻮد‬:‫ﺗﻌﻄ‬‫ﻲ‬‫ﻗﯿﻢ‬‫ﻟﻸ‬‫وﺑﺠﻜﺖ‬‫وﻟﻜﻦ‬‫ﻋﻨﺪ‬‫اﺳﺘﺪﻋﺎﺋﮭﺎ‬‫ﻓﻘﻂ‬. . public ‫اﻟﻜﻮﻧﺴﺘﺮاﻛﺘﺮ‬‫ﻓﻲ‬‫اﻟﻜﻼس‬‫ﻻﯾﻮرث‬‫ﻟﻠﺴﺐ‬‫ﻛﻼس‬‫وﯾﻌﺮف‬‫ﻋﻠﻰ‬‫أﻧﮫ‬ ‫ﺣﺘﻰ‬‫ﺗﺴﮭﻞ‬‫ﻋﻤﻠ‬‫ﯿﺔ‬‫ﺧﻠﻖ‬‫اﻷ‬‫وﺑﺠﻜﺖ‬‫ﻣﻨﮫ‬‫ﺧﺎرج‬‫اﻟﻜﻼس‬‫ﻧﻔﺴ‬. ‫ﮫ‬ The KeyWord "THIS" ‫ﺗﺴﺘﺨﺪم‬‫ﺑﻐﺮض‬‫ا‬. ‫اﻷوﺑﺠﻜﺖ‬ ‫ﺳﺘﺪﻋﺎء‬ key word "SUPER" ‫ﺗﺴﺘﺨﺪم‬‫ﻓﻲ‬‫ﻛﻮﻧﺴﺘﺮاﻛﺘﺮ‬‫اﻟﺴﺐ‬‫ﻛﻼس‬‫ذﻟﻚ‬‫ﻟﺘﻘﻮم‬‫ﺑﻮراﺛﺔ‬‫ﺟﻤﯿﻊ‬‫اﻟﻤﺘﻐﯿﺮات‬‫واﻟﻘﯿﻢ‬‫اﻟﻤﻌﺮﻓﺔ‬ ‫ﻓﻲ‬‫اﻟﺴﻮﺑﺮ‬‫ﻛﻼس‬.
  12. 12. ١٢ ‫س‬١٠‫ﺑ‬ ‫اﻗﻮم‬ ‫ﻛﯿﻒ‬ :‫ﺈ‬‫ﺑ‬ ‫ﻛﻼس‬ ‫ﻣﻦ‬ ‫ﻛﺎﺋﻦ‬ ‫ﻧﺸﺎء‬‫ﺄ‬‫ادراج‬ ‫طﺮﯾﻖ‬ ‫ﻋﻦ‬ ‫)أي‬ ‫ﻣﺨﺘﻠﻔﺔ‬ ‫ﺷﻜﺎل‬ ‫؟‬ (‫ﻣﺨﺘﻠﻔﺔ‬ ‫ﺑﺎراﻣﺘﺮات‬ ‫اﻟﻜﻮﻧﺴﺘﺮ‬ ‫ﻣﻦ‬ ‫ﻋﺪد‬ ‫اﻧﺸﺎء‬ ‫طﺮﯾﻖ‬ ‫ﻋﻦ‬ ‫ھﺬا‬ ‫ﯾﻜﻮن‬‫ا‬‫ﻛﺘﺮ‬‫اﻟﺤﺎﺟﺔ‬ ‫ﺣﺴﺐ‬ ‫وذﻟﻚ‬ ‫اﻟﻜﻼس‬ ‫ﻟﻨﻔﺲ‬ ‫ﻟﮫ‬ ‫ﻣﺜﺎل‬: public constructor(){} ‫اﻟﻜﻮﻧﺴﺘﺮ‬ ‫اﻧﺸﺎء‬‫ا‬‫اﻻﻓﺘﺮاﺿﻲ‬ ‫ﻛﺘﺮ‬ public constructor(int a){} ‫اﻟﻜﻮﻧﺴﺘﺮ‬ ‫اﻧﺸﺎء‬‫ا‬‫واﺣﺪ‬ ‫ﺑﺒﺎراﻣﯿﺘﺮ‬ ‫اﻻول‬ ‫ﻛﺘﺮ‬ public constructor(int a,int b){} ‫اﻟﻜﻮﻧﺴﺘﺮ‬ ‫اﻧﺸﺎء‬‫ا‬... ‫ﺑﺒﺎراﻣﯿﺘﺮﯾﻦ‬ ‫اﻟﺜﺎﻧﻲ‬ ‫ﻛﺘﺮ‬ ‫اﻟﺦ‬. ‫س‬١١:‫ﻣﺎ‬‫ﻣﻌﻨﻰ‬‫اﻟﺒﺮﯾﻔﺎﯾﺖ‬)(private‫و‬‫اﻟﺒﺮوﺗﻜـﺘﺪ‬protected)(‫و‬‫اﻟﺒﺎﺑﻠﻚ‬ (public)‫ﺑﺎﻟﻨﺴﺒﺔ‬‫ﻟﻠﻤﺘﻐﯿﺮات‬‫؟؟‬ ‫ﻛﻞ‬‫ﻣﺘﻐﯿﺮ‬‫ﻓﻲ‬‫ﻟﻐﺔ‬‫ﺟﺎﻓﺎ‬‫وﯾﺘﻤﯿﺰ‬‫ﺑﺨﺎﺻﯿﺔ‬‫ﻣﻦ‬‫اﻟﺨﻮاص‬‫اﻟﺜﻼﺛﺔ‬‫اﻟﻤﺬﻛﻮرة‬‫اﻋﻼه‬‫واﻟﺘﻲ‬ )‫ﺑـ‬ ‫ﺗﺴﻤﻰ‬acces modefires(،‫وھﺬه‬‫اﻟﺨ‬‫ﻮاص‬‫ھﻲ‬‫اﻟﺘﻲ‬‫ﺗﺴﻤﺢ‬‫ﺑ‬‫ﺈ‬‫ﻣﻜﺎﻧﯿﺔ‬‫اﻟﻮﺻﻮل‬‫اﻟﻰ‬ ‫اﻟﻤﺘﻐﯿﺮ‬‫ﻣﻦ‬‫ﻋﺪﻣﮭﺎ‬. ‫ﺑﺮ‬‫ا‬‫ﯾﻔﺖ‬)private(:‫و‬‫ھﻲ‬‫ﺧﺎﺻﯿﺔ‬‫ﺗﺸﻔﯿﺮ‬‫ﻣﺘﻜﺎﻣﻞ‬‫ﻟﻠﻤﺘﻐﯿﺮ‬‫ﺣﯿﺚ‬‫ﯾﻤﻨﻊ‬‫ﻣﻨﻌﺎ‬‫ﺑﺎﺗﺎ‬‫اﻟﻮﺻﻮل‬ ‫اﻟﯿﮫ‬‫ﻣﻦ‬‫ﺧﺎرج‬‫اﻟﻜﻼس‬‫اﻟﻤﻌﺮف‬‫ﺑﺪاﺧﻠﮭﺎ‬‫ﻣﺒﺎﺷﺮة‬)‫أي‬‫ﻋﻦ‬‫طﺮﯾﻖ‬‫اﺳﻤﮫ‬. (
  13. 13. ١٣ ‫ﺑﺮوﺗﻜـﺘﺪ‬protected)(:‫وھﻲ‬‫ﺧﺎﺻﯿﺔ‬‫اﻗﻞ‬‫درﺟﺔ‬‫ﻣﻦ‬‫اﻟﺒﺮﯾﻔﺎﯾﺖ‬‫ﺣﯿﺚ‬‫ﺗﺴﻤﺢ‬‫ﻟﻠﻜﻼﺳﺎت‬ ‫اﻟﻮارﺛﺔ‬‫ﻣﻦ‬‫اﻟﻜﻼس‬‫اﻻﺻﻠﻲ‬‫اﻟﺬي‬‫ﻋﺮف‬‫اﻟﻤﺘﻐﯿﺮ‬‫ﺑﺪاﺧﻠﮫ‬‫ﻣﻦ‬‫اﻟﻮﺻﻮل‬‫اﻟﯿﮫ‬‫ﺑﺴﮭﻮﻟﺔ‬)‫أي‬ ‫ﻋﻦ‬‫طﺮﯾﻖ‬‫اﻻﺳﻢ‬،‫اﺳﻢ‬‫اﻟﻤﺘﻐﯿﺮ‬‫ﻣﺒﺎﺷﺮة‬. ( ‫ﺑﺎﺑﻠﯿﻚ‬(public):‫ھﻲ‬‫اﻟﺨﺎﺻﯿﺔ‬‫اﻟﺜﺎﻟﺜﺔ‬‫وھﻲ‬‫أﻟﯿﻦ‬‫اﻟﺨﻮاص‬،‫ﺣﯿﺚ‬‫ﺗﺴﻤﺢ‬‫ﻟﻚ‬‫ﺑﺎﻟﻮﺻﻮل‬ ‫ﻟﻠﻤﺘﻐﯿﺮ‬‫ﻣﻦ‬‫أي‬‫ﻣﻜﺎن‬‫ﺷﺌﺖ‬. ‫ﻣﻼﺣﻈﺔ‬:‫اذا‬‫ﻟﻢ‬‫ﻧﻘﻢ‬‫ﺑ‬‫ﺈ‬‫دراج‬‫أي‬‫ﺧﺎﺻﯿﺔ‬‫ﻣﻦ‬‫ھﺬه‬‫اﻟﺨﻮاص‬‫ﻟﻠﻤﺘﻐﯿﺮ‬‫ﻓﺎن‬‫ﻟﻐﺔ‬‫ﺟﺎﻓﺎ‬‫ﺗﻘﻮم‬ ‫ﺑﻤﻨﺤﮫ‬‫ﺧﺎﺻﯿﺔ‬Default Access Modifier‫اﻓﺘﺮاﺿﯿﺎ‬. ‫واﻟـ‬Default Access Modifier: ‫ﻧوع‬‫راﺑﻊ‬‫ﻟل‬Access Modifier‫ﻟﻛن‬‫ﻏﯾر‬‫ﻣﺷﮭوره‬‫ﺟدا‬ ‫اﻟﻣﺗﻐﯾر‬‫أو‬‫اﻟداﻟﺔ‬‫اﻟﺗﻲ‬‫ﻟﻣﺎ‬‫ﺗﺳﺑﻘﮭﺎ‬‫أي‬‫ﻛﻠﻣﺔ‬‫ﻣن‬‫اﻟﺛﻼث‬‫اﻟﺳﺎﺑﻘﺔ‬private‫أو‬ protected‫أو‬public‫ﻓﮭﻲ‬‫ﺗﻌﺗﺑر‬Default. ‫و‬‫اﻟﺗﻌﺎﻣل‬‫ﻣﻌﮭﺎ‬‫ﻣﺣﺻور‬‫داﺧل‬‫اﻟﻛﻼﺳﺎت‬‫اﻟﺗﻲ‬‫داﺧل‬‫اﻟ‬‫ـ‬pakage. ‫س‬١٢:‫أﺧزن‬ ‫ﻛﯾف‬‫ﻗﯾﻣﺔ‬‫؟‬ ‫ﻣﺗﻐﯾر‬ ‫ﻓﻲ‬ ‫ﻧﻘوم‬ ‫ﻋﻧدﻣﺎ‬ ‫ﻟﻠﻣﺗﻐﯾر‬ ‫أوﻟﯾﺔ‬ ‫ﻗﯾﻣﺔ‬ ‫ﺗﺣدﯾد‬ ‫ﯾﻣﻛن‬‫أي‬ ‫ﻓﻲ‬ ‫ﻟﻠﻣﺗﻐﯾر‬ ‫ﻗﯾﻣﺔ‬ ‫ﺗﺣدﯾد‬ ‫أﯾﺿﺎ‬ ‫وﻧﺳﺗطﯾﻊ‬ ‫ﺑﺈﻧﺷﺎﺋﮫ‬ ‫أن‬ ‫وﯾﻣﻛن‬ ‫إﻧﺷﺎﺋﮫ‬ ‫ﻋﻧد‬ ‫ﻟﻠﻣﺗﻐﯾر‬ ‫أوﻟﯾﺔ‬ ‫ﻗﯾﻣﺔ‬ ‫ﻟﺗﺣدﯾد‬ = ‫ﻋﻼﻣﺔ‬ ‫وﺗﺳﺗﻌﻣل‬ ‫اﻟﺑرﻧﺎﻣﺞ‬ ‫ﺿﻣن‬ ‫ﺗﺎﻟﻲ‬ ‫ﻣوﺿﻊ‬ ‫ﻣﺛﺎل‬ ‫ﻧﺄﺧذ‬ int i = 500; i ‫ﻣﺗﻐﯾرا‬ ‫أﻧﺷﺄﻧﺎ‬ ‫أﻧﻧﺎ‬ ‫ﻧﻼﺣظ‬ ‫اﻹﺑﺗداﺋﯾﺔ‬ ‫اﻟﻘﯾﻣﺔ‬ ‫ﻋﻠﻰ‬ ‫ﯾﺣﺗوي‬ ‫اﻟﻣﺗﻐﯾر‬ ‫ھذا‬٥٠٠،‫ﯾﻣﻛﻧﻧﺎ‬ ‫اﻟطرﯾﻘﺔ‬ ‫وﺑﻧﻔس‬ ‫وھﻛذا‬‫اﻟﻣﺗﻐﯾرات‬ ‫إﻋداد‬ ‫ﻟﻸﻋداد‬ ‫اﻟﻣﺧزﻧﺔ‬..
  14. 14. ١٤ ‫اﻟﻣﺧزﻧﺔ‬ ‫ﻟﻠﻣﺗﻐﯾرات‬ ‫ﺑﺎﻟﻧﺳﺑﺔ‬ ‫اﻷﻣر‬ ‫وﯾﺧﺗﻠف‬‫ﻟ‬‫ﺳﻠﺳﻠﺔ‬‫ﻧﺻﯾﺔ‬‫اﻗﺗﺑﺎس‬ ‫ﻋﻼﻣﺎت‬ ‫وﺿﻊ‬ ‫ﯾﺟب‬ ‫ﺣﯾث‬ ‫ﺗﺧزﯾﻧﮭﺎ‬ ‫اﻟﻣراد‬ ‫اﻟﻘﯾﻣﺔ‬ ‫ﺣول‬ String studentName = "Hamza "; ‫س‬١٣:‫؟‬ ‫اﻟﻧوع‬ ‫ﻧﻔس‬ ‫ﻣن‬ ‫آﺧر‬ ‫ﻣﺗﻐﯾر‬ ‫ﻗﯾﻣﺔ‬ ‫ﻟﯾﺳﺎوي‬ ‫اﻟﻣﺗﻐﯾرات‬ ‫أﺣد‬ ‫إﻋداد‬ ‫ﯾﻣﻛن‬ ‫ھل‬ ‫ﻧﻌم‬‫اﻟﺗﺎﻟﻲ‬ ‫اﻟﻣﺛﺎل‬ ‫ﻓﻲ‬ ‫ﻧرى‬ ‫ﻛﻣﺎ‬ ‫اﻟﻧوع‬ ‫ﻧﻔس‬ ‫ﻣن‬ ‫آﺧر‬ ‫ﻣﺗﻐﯾر‬ ‫ﻗﯾﻣﺔ‬ ‫ﻟﯾﺳﺎوي‬ ‫ﻣﺗﻐﯾر‬ ‫إﻋداد‬ ‫ﯾﻣﻛﻧﻧﺎ‬ int i = 500; int k= i ; ‫س‬١٤:‫ﻗﯾﻣﺔ‬ ‫أﺣدد‬ ‫ﻟم‬ ‫إذا‬ ‫ﯾﺣدث‬ ‫ﻣﺎذا‬ ‫ﻟﻛن‬‫ا‬‫ﻟﻠﻣﺗﻐﯾر‬ ‫ﺑﺗداﺋﯾﺔ‬‫؟‬ ‫ﻟﻠﻣﺗﻐﯾر‬ ‫أوﻟﯾﺔ‬ ‫ﻗﯾﻣﺔ‬ ‫ﺗﺣدﯾد‬ ‫ﯾﺟب‬ ‫وﻟذﻟك‬ ‫ﺧطﺄ‬ ‫رﺳﺎﻟﺔ‬ ‫اﻟﺟﺎﻓﺎ‬ ‫ﻣﺗرﺟم‬ ‫وﯾظﮭر‬ ‫ﺧطﺄ‬ ‫ﯾﺣدث‬ ‫ھﻧﺎ‬ ‫س‬١٥:‫؟‬ ‫اﻟﻣﺗﻐﯾرات‬ ‫ﻟﺗﺳﻣﯾﺔ‬ ‫ﻣﻌﯾﻧﺔ‬ ‫ﻗواﻋد‬ ‫ھﻧﺎك‬ ‫ھل‬ ‫ﺣﯾث‬ ‫اﻟﻣﺗﻐﯾرات‬ ‫ﺗﺳﻣﯾﺔ‬ ‫ﻋﻧد‬ ‫ﻣراﻋﺎﺗﮭﺎ‬ ‫ﯾﺟب‬ ‫ﻗواﻋد‬ ‫ھﻧﺎك‬ ‫ﻧﻌم‬‫ﺑﺣرف‬ ‫اﻟﻣﺗﻐﯾرات‬ ‫أﺳﻣﺎء‬ ‫ﺗﺑدأ‬ ‫إﻧﺟﻠﯾزي‬) ‫اﻟﺗﺳطﯾر‬ ‫ﻋﻼﻣﺔ‬ ‫أو‬ $ ‫اﻟدوﻻر‬ ‫ﻋﻼﻣﺔ‬ ‫أو‬-‫اﻹ‬ ‫ﺑﺎﻗﻲ‬ ‫وﯾﻛون‬ (‫وﺑﺷرط‬ ‫ﻋدد‬ ‫أو‬ ‫ﺣرف‬ ‫ﺳم‬ ‫اﻟﺗر‬ ‫ﻋﻼﻣﺎت‬ ‫أﯾﺿﺎ‬ ‫إﺳﺗﻌﻣﺎل‬ ‫ﯾﻣﻛﻧﻧﺎ‬ ‫وﻻ‬ ‫ﻓﺎرﻏﺔ‬ ‫ﻣﺳﺎﻓﺎت‬ ‫وﺿﻊ‬ ‫ﻋدم‬‫اﻟﺟﺎﻓﺎ‬ ‫ﻣﺗرﺟم‬ ‫ﯾظﮭر‬ ‫ﺣﯾث‬ ‫ﻗﯾم‬ ‫ﻛﺎن‬ ‫إذا‬ ‫ﺧطﺄ‬ ‫رﺳﺎﻟﺔ‬‫ﻓﻲ‬‫ﻋﻼﻣﺎت‬ ‫أو‬ ‫ﻓﺎرﻏﺔ‬ ‫ﻣﺳﺎﻓﺎت‬ ‫اﻟﻣﺗﻐﯾر‬ ‫إﺳم‬‫ﺗرﻗﯾم‬‫ﻛﺑﯾرا‬ ‫ﺣرﻓﺎ‬ ‫اﺳﺗﻌﻣﻠت‬ ‫واذا‬ ‫اﻟﻣﺛﺎل‬ ‫ﺳﺑﯾل‬ ‫ﻋﻠﻰ‬ ‫اﻟﺑرﻧﺎﻣﺞ‬ ‫ﻛل‬ ‫ﻓﻲ‬ ‫اﻟطرﯾﻘﺔ‬ ‫ﺑﻧﻔس‬ ‫اﺳﺗﻌﻣﺎﻟﮫ‬ ‫ﯾﺟب‬ ‫ﻓﺎﻧﮫ‬ ‫ﻣﺗﻐﯾر‬ ‫اﺳم‬ ‫ﻓﻲ‬: studentName ‫ھذا‬ ‫ﻧﻔس‬ ‫ﯾﻛون‬ ‫ﻟن‬ ‫ﻟﻣﺗﻐﯾر‬ ‫اﺳم‬ ‫ھذا‬ StudentName ‫ﺗﻐﯾﯾر‬‫اﻟﻣﺗﻐﯾر‬ ‫ﻻﺳم‬ ‫اﻟﺑرﻧﺎﻣﺞ‬ ‫ﻧﻔس‬ ‫ﻓﻲ‬ ‫ﻛﺑﯾر‬ ‫اﻟﻰ‬ ‫ﺻﻐﯾر‬ ‫ﻣن‬ ‫اﻷول‬ ‫اﻟﺣرف‬ ‫اﻟﺗرﺟﻣﺔ‬ ‫ﻋﻧد‬ ‫ﺧطﺄ‬ ‫اﻟﻰ‬ ‫ﯾؤدي‬ ‫ﻣن‬ ‫اﻷول‬ ‫واﻟﺣرف‬ ‫اﻟﻣﺗﻐﯾر‬ ‫ھذا‬ ‫اﺳﺗﻌﻣﺎل‬ ‫ﻣن‬ ‫اﻟﻐرض‬ ‫ﻋﻠﻰ‬ ‫داﻻ‬ ‫اﻟﻣﺗﻐﯾر‬ ‫اﺳم‬ ‫ﯾﻛون‬ ‫أن‬ ‫ﯾﺟب‬ ‫وﻟذﻟك‬ ‫اﻷول‬ ‫اﻟﺣرف‬ ‫ﯾﻛون‬ ‫ﻛﻠﻣﺔ‬ ‫ﻣن‬ ‫أﻛﺛر‬ ‫ﻣن‬ ‫اﻟﻣﺗﻐﯾر‬ ‫اﺳم‬ ‫ﺗﻛون‬ ‫ﺣﺎﻟﺔ‬ ‫وﻓﻲ‬ ‫ﺻﻐﯾرا‬ ‫ﯾﻛون‬ ‫أن‬ ‫ﯾﺟب‬ ‫اﺳﻣﮫ‬ ‫اﻟﻛ‬ ‫ﻣن‬‫ﺗرﻗﯾم‬ ‫ﻋﻼﻣﺎت‬ ‫أو‬ ‫ﻓواﺻل‬ ‫وﺑدون‬ ‫ﻛﺑﯾرة‬ ‫ﺑﺣروف‬ ‫ﺗﺑدأ‬ ‫اﻟﻛﻠﻣﺎت‬ ‫وﺑﺎﻗﻲ‬ ‫ﺻﻐﯾرا‬ ‫اﻷوﻟﻰ‬ ‫ﻠﻣﺔ‬
  15. 15. ١٥ ‫س‬١٦:‫؟‬ ‫اﻟﻣﺗﻐﯾرات‬ ‫ﻋﻠﻰ‬ ‫اﻟرﯾﺎﺿﯾﺔ‬ ‫اﻟﻌﻣﻠﯾﺎت‬ ‫ﻋن‬ ‫ﻣﺎذا‬ ‫وﻋﻠﻰ‬ ‫اﻟﻣﺑرﻣﺞ‬ ‫ﻓﻲ‬ ‫رﯾﺎﺿﻲ‬ ‫وﻓﻛر‬ ‫ﻣﻌﯾﻧﺔ‬ ‫رﯾﺎﺿﯾﺔ‬ ‫ﻗدرات‬ ‫ﻋﻣوﻣﺎ‬ ‫اﻟﺑرﻣﺟﺔ‬ ‫ﺗطﻠب‬ ‫ﺳﺎﺑﻘﺎ‬ ‫ﻗﻠﻧﺎ‬ ‫ﻛﻣﺎ‬ ‫أﻧﮫ‬ ‫اﻻ‬ ‫اﻟرﯾﺎﺿﯾﺔ‬ ‫اﻟﻌﻣﻠﯾﺎت‬ ‫ﺑﻛل‬ ‫اﻟﺣﺎﺳب‬ ‫ﻗﯾﺎم‬ ‫ﻣن‬ ‫اﻟرﻏم‬‫ﺣﺗﻰ‬ ‫اﻟﻣﺑرﻣﺞ‬ ‫ﻣن‬ ‫وأواﻣر‬ ‫ﺗﻌﻠﯾﻣﺎت‬ ‫ﯾرﯾد‬ ‫رﯾﺎﺿﯾﺔ‬ ‫ﻋﻣﻠﯾﺎت‬ ‫اﻟﻰ‬ ‫ﺗﺣﺗﺎج‬ ‫واﻟﺗﻲ‬ ‫ﻟﻠﺣﺎﺳب‬ ‫ﺗﻌطﯾﮭﺎ‬ ‫اﻟﺗﻲ‬ ‫اﻷواﻣر‬ ‫وﺗﺳﻣﻰ‬ ‫ﻋﻣﻠﯾﺎت‬ ‫ﺑﮭﻛذا‬ ‫ﯾﻘوم‬ ‫وﯾﻣﻛﻧﻧﺎ‬ ‫ﺗﻌﺎﺑﯾر‬ ‫اﻟﺑرﻧﺎﻣﺞ‬ ‫ﻓﻲ‬ ‫اﻟﻣﻌﺎدﻻت‬ ‫واﺳﺗﻌﻣﺎل‬ ‫ﻣﺗﻐﯾر‬ ‫ﻗﯾﻣﺔ‬ ‫ﺗﻐﯾﯾر‬ ‫ﻣﻧﮭﺎ‬ ‫ﻣﮭﺎم‬ ‫ﺑﻌدة‬ ‫ﻟﻠﻘﯾﺎم‬ ‫اﻟﺗﻌﺎﺑﯾر‬ ‫ھذه‬ ‫اﺳﺗﺧدام‬ ‫ا‬ ‫ﻓﻲ‬ ‫ﻣﺎ‬ ‫ﻋﻣل‬ ‫ﺣدوث‬ ‫ﻣرات‬ ‫ﻋدد‬ ‫وﺗﺳﺟﯾل‬‫واﻟﺿرب‬ ‫واﻟطرح‬ ‫اﻟﺟﻣﻊ‬ ‫اﻟﺗﻌﺎﺑﯾر‬ ‫ھذه‬ ‫وﺗﺳﺗﻌﻣل‬ ‫ﻟﺑرﻧﺎﻣﺞ‬ ‫اﻟﻘﺳﻣﺔ‬ ‫وﺑﺎﻗﻲ‬ ‫واﻟﻘﺳﻣﺔ‬ ‫ﻛذﻟك‬ ‫اﻟﯾس‬ ‫اﻟﺣﺳﺎب‬ ‫ﻣدرس‬ ‫واﻟﻰ‬ ‫اﻻﺑﺗداﺋﯾﺔ‬ ‫اﻟﻣرﺣﻠﺔ‬ ‫اﻟﻰ‬ ‫رﺟﻌﻧﺎ‬ ‫أﻧﻧﺎ‬ ‫ھذا‬ ‫ﯾﻌﻧﻲ‬ ‫واﻷﺣﻼم‬ ‫اﻟﺑراءة‬ ‫ﺣﯾث‬ ‫اﻟﺧواﻟﻲ‬ ‫اﻷﯾﺎم‬ ‫وﺗﻠك‬ ‫اﻷوﻟﻰ‬ ‫واﻟﻣرﺣﻠﺔ‬ ‫اﻟطﻔوﻟﺔ‬ ‫ذﻛرﯾﺎت‬ ‫اﻟﻰ‬ ‫اﻟﻌودة‬ ‫أﺟﻣل‬ ‫ﻣﺎ‬ ‫ﻧرﺟ‬ ‫ـ‬ ‫ﻋﻠﯾﻧﺎ‬ ‫ﻣﺎ‬ ‫ـ‬ ‫اﻟوردﯾﺔ‬‫وﻧﺳﺗرﺟﻊ‬ ‫اﻹﻋدادﯾﺔ‬ ‫اﻟﻣرﺣﻠﺔ‬ ‫ﻓﻲ‬ ‫اﻟرﯾﺎﺿﯾﺎت‬ ‫ﻣدرس‬ ‫أﯾﺎم‬ ‫اﻟﻰ‬ ‫ﺑﺎﻟذاﻛرة‬ ‫ﻊ‬ ‫اﻷرﺑﻊ‬ ‫وﻋﻼﻣﺎﺗﮭﺎ‬ ‫واﻟﻘﺳﻣﺔ‬ ‫واﻟﺿرب‬ ‫واﻟطرح‬ ‫اﻟﺟﻣﻊ‬ ‫اﻟﺣﺳﺎب‬ ‫ﻓﻲ‬ ‫اﻟﺷﮭﯾرة‬ ‫اﻷرﺑﻊ‬ ‫اﻟﻌﻣﻠﯾﺎت‬ ‫اﻟﻣﻌروﻓﺔ‬ + ‫و‬-‫ﻹﺟراء‬ ‫اﻟﺟﺎﻓﺎ‬ ‫ﺑراﻣﺞ‬ ‫ﻓﻲ‬ ‫اﻟﻣؤﺛرات‬ ‫ھذه‬ ‫وﺗﺳﺗﻌﻣل‬ ‫ﻣؤﺛرات‬ ‫ﺗﺳﻣﻰ‬ ‫اﻟرﻣوز‬ ‫ھذه‬ / ‫و‬ * ‫و‬ ‫اﻟرﯾﺎﺿ‬ ‫اﻟﻌﻣﻠﯾﺎت‬‫و‬ * ‫ﺑﯾن‬ ‫اﻹﺧﺗﻼف‬ ‫ﻋن‬ ‫ﺗﺳﺎؤل‬ ‫ﯾراودك‬ ‫طﺑﻌﺎ‬ ‫اﻷرﻗﺎم‬ ‫ﻋﻠﻰ‬ ‫ﯾﺔ‬×‫و‬ / ‫وﺑﯾن‬÷ ‫ﻋﻠﻰ‬ ‫ﻧﻣﺷﻲ‬ ‫اﻟذي‬ ‫اﻟدﺳﺗور‬ ‫ﺑﻣﺛﺎﺑﺔ‬ ‫وھذا‬ ‫اﻷﻣور‬ ‫ﯾﺳﮭل‬ ‫اﻟﺑداﯾﺔ‬ ‫ﻣن‬ ‫ﻗواﻋد‬ ‫ﻋﻠﻰ‬ ‫ﻓﯾﮫ‬ ‫ﻧﺗﻔﻖ‬ ‫أﻣر‬ ‫ﻛل‬ ‫وﻟﻛن‬ ‫ﻣﻧﮭﺎﺟﮫ‬ operators ( ‫)ﻣؤﺛرات‬ ‫ﻣﻌﺎﻣﻼت‬ ‫اﻟﺟﻣﻊ‬ ‫ﻋﻣﻠﯾﺔ‬ ‫ﻹﺟراء‬ + ‫اﻟﻌﻼﻣﺔ‬ ‫ﻧﺳﺗﻌﻣل‬ ‫اﻟﻌﻼﻣﺔ‬ ‫ﻧﺳﺗﻌﻣل‬-‫اﻟطرح‬ ‫ﻟﺗﻌﺑﯾر‬ ‫اﻟﺟﺎﻓﺎ‬ ‫ﺑراﻣﺞ‬ ‫ﻓﻲ‬ * ‫اﻟﻌﻼﻣﺔ‬ ‫اﻟﺿرب‬ ‫ﺗﻌﺑﯾر‬ ‫ﯾﺳﺗﻌﻣل‬ ‫اﻟﺟﺎﻓﺎ‬ ‫ﺑراﻣﺞ‬ ‫ﻓﻲ‬ / ‫اﻟﻌﻼﻣﺔ‬ ‫اﻟﻘﺳﻣﺔ‬ ‫ﺗﻌﺑﯾر‬ ‫ﯾﺳﺗﻌﻣل‬ ‫اﻟﻘﺳﻣﺔ‬ ‫ﺑﺎﻗﻲ‬ ‫ﻟﺗﺣدﯾد‬ % ‫اﻟﻣؤﺛر‬ ‫ﻧﺳﺗﻌﻣل‬ ‫واﺣد‬ ‫ﺑﻣﻘدار‬ ‫اﻟﻣﺗﻐﯾر‬ ‫ﻓﻲ‬ ‫اﻟﻣﺧزﻧﺔ‬ ‫اﻟﻘﯾﻣﺔ‬ ‫ﻟزﯾﺎدة‬ ++ ‫اﻟﻣؤﺛر‬ ‫ﻧﺳﺗﻌﻣل‬ ‫اﻟﻣﻌﺎﻣل‬ ‫ﯾﺳﺗﺧدم‬--‫وا‬ ‫ﺑﻣﻘدار‬ ‫اﻟﻣﺗﻐﯾر‬ ‫ﻗﯾﻣﺔ‬ ‫ﻹﻧﻘﺎص‬‫ﺣد‬
  16. 16. ١٦ ‫س‬١٧:‫أ‬‫ﻓﻲ‬ ‫ﺣﺳﺎﺑﯾﺔ‬ ‫ﻋﻣﻠﯾﺔ‬ ‫ﻣن‬ ‫أﻛﺛر‬ ‫ھﻧﺎك‬ ‫ﻛﺎن‬ ‫إذا‬ ‫ﯾﻌﻧﻲ‬ ‫اﻟﺗﻌﻘﯾد‬ ‫ﻓﻲ‬ ‫ﺑدأت‬ ‫ﻗد‬ ‫اﻷﻣور‬ ‫أن‬ ‫ﺗرى‬ ‫ﻻ‬ ‫اﻟﺗر‬ ‫أﻋرف‬ ‫أن‬ ‫ﯾﻧﺑﻐﻲ‬ ‫اﻻ‬ ‫اﻟﺑرﻧﺎﻣﺞ‬‫ﺗ‬‫ﯾﻣﻛﻧﻧﻲ‬ ‫ﺣﺗﻰ‬ ‫اﻟﻌﻣﻠﯾﺎت‬ ‫ھذه‬ ‫ﻹﻧﺟﺎز‬ ‫اﻟﺣﺎﺳب‬ ‫ﯾﺗﺑﻌﮫ‬ ‫اﻟذي‬ ‫ﯾب‬ ‫؟‬ ‫اﻟﻣﺗﻐﯾر‬ ‫ﻗﯾﻣﺔ‬ ‫ﺿﺑط‬ ‫اﻟﺛﺎﻧوﯾﺔ‬ ‫اﻟﻣرﺣﻠﺔ‬ ‫ﻓﻲ‬ ‫اﻟدراﺳﺔ‬ ‫ﻣن‬ ‫وﻧﺳﺗرﺟﻊ‬ ‫ﺟدا‬ ‫ھﺎم‬ ‫ﻣوﺿوع‬ ‫ھذا‬ ‫أﺣﺳﻧت‬‫ﻣدرس‬ ‫ﻛﺎن‬ ‫ﻛﯾف‬ ‫اﻟﻌﻣﻠﯾﺎت‬ ‫ھذه‬ ‫ﻓﻲ‬ ‫ﻣن‬ ‫ﯾﺳﺑﻖ‬ ‫وﻣن‬ ‫اﻵﺧر‬ ‫ﻋﻠﻰ‬ ‫ﯾﺗوزع‬ ‫وﻣن‬ ‫اﻷﻣر‬ ‫ھذا‬ ‫ﻋﻠﻰ‬ ‫ﯾرﻛز‬ ‫اﻟرﯾﺎﺿﯾﺎت‬ ‫اﻟﺗﺎﻟﻲ‬ ‫اﻟﺗرﺗﯾب‬ ‫ﺣﺳب‬ ‫اﻟﻌﻣﻠﯾﺎت‬ ‫ھذه‬ ‫ﺗﺗم‬ ‫اﻟﺣﺎﺳب‬ ‫ﺑراﻣﺞ‬ ‫وﻓﻲ‬ ‫اﻟرﯾﺎﺿﯾﺔ‬ ‫واﺣد‬ ‫ﺑﻣﻘدار‬ ‫واﻟﻧﻘص‬ ‫اﻟزﯾﺎدة‬ ‫أوﻻ‬ ‫ﯾﺗم‬ ‫اﻟﻘﺳﻣﺔ‬ ‫وﺑﺎﻗﻲ‬ ‫واﻟﻘﺳﻣﺔ‬ ‫اﻟﺿرب‬ ‫ذﻟك‬ ‫ﯾﻠﻲ‬ ‫واﻟطرح‬ ‫اﻟﺟﻣﻊ‬ ‫ذﻟك‬ ‫ﺑﻌد‬ ‫ﯾﺄﺗﻲ‬ ‫ﺛم‬‫اﻟﻣﻘﺎرﻧﺔ‬ ‫اﻟﻣﺗﻐﯾر‬ ‫ﻗﯾﻣﺔ‬ ‫ﻟﺿﺑط‬ = ‫اﻟﻌﻼﻣﺔ‬ ‫وﺗﺳﺗﺧدم‬ ‫س‬١٨:‫ھل‬‫ﯾ‬‫؟‬ ‫،ﺧطﺄ‬ ‫ﺻواب‬ ‫ـ‬ ‫ھﻣﺎ‬ ‫ﻓﻘط‬ ‫ﻗﯾﻣﺗﯾن‬ ‫ﻟﺗﺧزﯾن‬ ‫ﯾﺳﺗﻌﻣل‬ ‫اﻟذي‬ ‫ﺑوﻟﯾﺎن‬ ‫اﻟﻣﺗﻐﯾر‬ ‫رﺟﻊ‬ ‫وﻻ‬ ‫اﻟﺧطﺄ‬ ‫أو‬ ‫اﻟﺻواب‬ ‫ﺣﯾث‬ ‫ﻣن‬ ‫اﻟﺷرط‬ ‫ﺗﺧﺗﺑر‬ ‫ﺣﯾث‬ ‫اﻟﻣﺑدأ‬ ‫ﺑﻧﻔس‬ ‫ﺗﻌﻣل‬ ‫اذا‬ ‫اﻟﺟﻣﻠﺔ‬ ‫ﺻدﯾﻖ‬ ‫ﯾﺎ‬ ‫ﻧﻌم‬ ‫ﺻﺣﯾﺣﺎ‬ ‫اﻟﺷرط‬ ‫ﻛﺎن‬ ‫إذا‬ ‫إﻻ‬ ‫ﺑﺎﻟﻌﻣل‬ ‫ﺗﻘوم‬ ‫ﺑﺳﯾط‬ ‫ﻣﺛﺎل‬‫؟‬ ‫ﺳﻣﺣت‬ ‫ﻟو‬ ‫اﻷﻣور‬ ‫ﯾوﺿﺢ‬ if (hour < 12) System.out.println("Good morning."); ‫ﯾﺣدث‬ ‫ﻟن‬ ‫ﻓﺎﻧﮫ‬ ‫اﻟﺷرط‬ ‫ﯾﺗﺣﻘﻖ‬ ‫ﻟم‬ ‫اذا‬ ‫أﻧﮫ‬ ‫ﺑﻣﻌﻧﻰ‬ ‫اﻟﺷرط‬ ‫ﺑﻔﻌل‬ ‫ﯾرﺗﺑط‬ ‫اﻟﺷرط‬ ‫ﺟواب‬ ‫أن‬ ‫ھﻧﺎ‬ ‫وﻧﻼﺣظ‬ ‫ﺷﻲء‬ ‫؟‬ ‫أﻓﻌل‬ ‫ﻓﻣﺎذا‬ ‫ﻗﯾﻣﺗﯾن‬ ‫ﺑﯾن‬ ‫أﻗﺎرن‬ ‫أن‬ ‫أرﯾد‬ ‫اﻟﺣﺎﻻت‬ ‫ﺑﻌض‬ ‫ﻓﻲ‬ ‫وﻟﻛن‬ ‫ﻣن‬ ‫أﺻﻐر‬ ‫اﻟﻣؤﺛر‬ ‫اﺳﺗﺧدام‬ ‫ﯾﻣﻛﻧك‬ ‫ﻣﻧﮭﺎ‬ ‫أﻗل‬ ‫أو‬ ‫أﺧرى‬ ‫ﺗﺳﺎوي‬ ‫ﻣﻌﯾﻧﺔ‬ ‫ﻗﯾﻣﺔ‬ ‫ھل‬ ‫ﺗﺧﺗﺑر‬ ‫أن‬ ‫أردت‬ ‫اذا‬
  17. 17. ١٧ ‫ﯾﺳﺎوي‬ ‫أو‬ >= <= ‫ﯾﺳﺎوي‬ ‫أو‬ ‫ﻣن‬ ‫أﻛﺑر‬ ‫ﻻﺧﺗﺑﺎر‬ ‫ﯾﺳﺗﺧدم‬ <= & >= ‫؟‬ ‫ﻓﻘط‬ ‫اﻟﻣﺳﺎوة‬ ‫إﺧﺗﺑﺎر‬ ‫ﯾﻣﻛﻧﻧﻲ‬ ‫ھل‬ ‫ﯾﺳﺎوي‬ ‫ﻣﺎ‬ ‫ﻣﺗﻐﯾر‬ ‫وھل‬ ‫ﻻ‬ ‫أو‬ ‫ﻣﻌﯾﻧﺔ‬ ‫ﻗﯾﻣﺔ‬ ‫ﯾﺳﺎوي‬ ‫ﻣﺎ‬ ‫ﻣﺗﻐﯾر‬ ‫ﻛﺎن‬ ‫اذا‬ ‫ﻣﺎ‬ ‫اﺧﺗﺑﺎر‬ ‫ﯾﻣﻛﻧك‬ ‫ﻧﻌم‬‫آﺧر‬ ‫ﻣﺗﻐﯾر‬ ‫ﻋﻼﻣﺗﻲ‬ ‫ﺗﺳﺗﻌﻣل‬ ‫ﻻ‬ ‫أﻧﮫ‬ ‫ﻋﻠﻰ‬ ‫وﻧؤﻛد‬ ‫ﯾﺳﺎوي‬ ‫ﻋﻼﻣﺗﻲ‬ ‫ﻣن‬ ‫ﯾﺗﻛون‬ ‫أﻧﮫ‬ ‫وﻧﻼﺣظ‬ == ‫اﻟﻣؤﺛر‬ ‫ﺑﺎﺳﺗﻌﻣﺎل‬ ‫اﻟﺷرطﯾﺔ‬ ‫اﻟﺟﻣل‬ ‫ﻓﻲ‬ ‫اﻻ‬ ‫اﻟﺗﺳﺎوي‬ ‫؟‬ ‫ﯾﻛون‬ ‫ﻛﯾف‬ ‫اﻟﻣﺳﺎوة‬ ‫ﻋدم‬ ‫واﺧﺗﺑﺎر‬ ‫طﯾب‬ ‫اﻟﻣﺳﺎوة‬ ‫ﻋدم‬ ‫ﻻﺧﺗﺑﺎر‬ != ‫اﻟﻣؤﺛر‬ ‫ﻧﺳﺗﻌﻣل‬ ‫؟‬ ‫اﻟﻣﺗﻐﯾرات‬ ‫أﻧواع‬ ‫ﻟﻛل‬ ‫اﻟﺳﺎﺑﻘﯾن‬ ‫اﻟﻣؤﺛرﯾن‬ ‫ﻧﺳﺗﺧدم‬ ‫وھل‬ ‫ﻧﺳﺗﺧدم‬‫ﺑﺳﻠﺳﻠﺔ‬ ‫اﻟﺧﺎص‬ ‫اﺳﺗرﯾﻧﺞ‬ ‫اﻟﻣﺗﻐﯾر‬ ‫ﻋدا‬ ‫ﻣﺎ‬ ‫اﻟﻣﺗﻐﯾرات‬ ‫أﻧواع‬ ‫ﻟﻛل‬ != & == ‫اﻟﻣؤﺛرﯾن‬ ‫اﻟﻧﮭﺞ‬ ‫اﺳﺗﻌﻣﺎل‬ ‫اﻟﻰ‬ ‫ﺣﯾﻧﮫ‬ ‫ﻓﻲ‬ ‫وأﺷرﻧﺎ‬ ‫اﻟﻣوﺿوع‬ ‫ھذا‬ ‫ﻋن‬ ‫اﻟﺳﺎدس‬ ‫اﻟدرس‬ ‫ﻓﻲ‬ ‫ﺗﻛﻠﻣﻧﺎ‬ ‫وﻗد‬ ‫اﻟﺣروف‬ ‫ﺣروف‬ ‫ﺳﻠﺳﻠﺗﻲ‬ ‫ﺗﺳﺎوي‬ ‫ﻻﺧﺗﺑﺎر‬ ‫اﯾﻛوال‬ ‫اﻟﻧﮭﺞ‬ ‫وھو‬ ‫واﺣدا‬ ‫أﻣرا‬ ‫اﻟﺷرط‬ ‫ﺟواب‬ ‫ﺗﺟﻌل‬ ‫اﻟﺳﺎﺑﻘﺔ‬ ‫اﻷﻣﺛﻠﺔ‬ ‫ﺟﻣﯾﻊ‬ ‫ﻓﻲ‬ println ( ) ‫؟‬ ‫ﻧﻔﻌل‬ ‫ﻓﻣﺎذا‬ ‫اﻟﺷرط‬ ‫ﻟﻔﻌل‬ ‫ﻛﻧﺗﯾﺟﺔ‬ ‫ﻣﮭﻣﺔ‬ ‫ﻣن‬ ‫أﻛﺛر‬ ‫اﻧﺟﺎز‬ ‫ﻓﻲ‬ ‫ﻧرﻏب‬ ‫ﻗد‬ ‫اﻟﺣﺎﻻت‬ ‫ﻣن‬ ‫ﻋدﯾد‬ ‫ﻓﻲ‬ ‫وﻟﻛﻧﻧﺎ‬ ‫اﻟﺑرﻣﺟﺔ‬ ‫ﻓﻲ‬ ‫اﻟﺻﺣﯾﺢ‬ ‫اﻟﻧﮭﺞ‬ ‫ﺗﻧﺗﮭﺞ‬ ‫ﺑدأت‬ ‫ﻗد‬ ‫اﻵن‬ ‫أﻧك‬ ‫وأﺑﺷرك‬ ‫ﺣﻖ‬ ‫ﻣﻌك‬ ‫ﯾﺎﺻدﯾﻘﻲ‬ ‫ﺻﺣﯾﺢ‬ ‫ﻛﻼﻣك‬ ‫ﺻدﻓﺎﺗﮫ‬ ‫ﻓﻲ‬ ‫اﻟدر‬ ‫ﻋن‬ ‫ﻟﻧﺑﺣث‬ ‫اﻟﺑرﻣﺟﺔ‬ ‫ﺑﺣر‬ ‫ﻓﻲ‬ ‫اﻟﻐوص‬ ‫اﻟﻰ‬ ‫ﺗﺄﺧذﻧﺎ‬ ‫اﻟﻣﻠﺣوظﺔ‬ ‫وھذه‬ ‫ﻟﻛﻲ‬‫ﻛﻧ‬ ‫ﻣﮭﻣﺔ‬ ‫ﻣن‬ ‫أﻛﺛر‬ ‫ﺗﻧﺟز‬‫ﺗ‬‫اﻟﺣﺎﺻرﺗﯾن‬ { } ‫ﺑواﺳطﺔ‬ ‫ﻛﺗﻠﯾﺔ‬ ‫ﺟﻣل‬ ‫ﺗﻧﺷﺄ‬ ‫أن‬ ‫ﻋﻠﯾك‬ ‫اﻟﺷرط‬ ‫ﻟﺗﺣﻘﻖ‬ ‫ﯾﺟﺔ‬
  18. 18. ١٨ ‫ﻣﺟﻣوﻋﺔ‬ ‫اطﺎر‬ ‫ﻓﻲ‬ ‫ﻣرﺗﺑﺔ‬ ‫ﺟﻣل‬ ‫ھﻲ‬ ‫اﻟﻛﺗﻠﯾﺔ‬ ‫اﻟﺟﻣل‬ ‫ﺑﺎﻟﻣﻧﺎﺳﺑﺔ‬ main( ) ‫ﻓﻌل‬ ‫ﻣﻊ‬ ‫اﻟﻛﺗﻠﯾﺔ‬ ‫اﻟﺟﻣل‬ ‫ﻧﺳﺗﻌﻣل‬ ً‫اذا‬ { ‫اﻟﻐﻠﻖ‬ ‫ﺑﺣﺎﺻرة‬ ‫وﺗﻧﺗﮭﻲ‬ } ‫اﻟﻔﺗﺢ‬ ‫ﺑﺣﺎﺻرة‬ ‫ﺗﺑدأ‬ ‫اﻟﻛﺗﻠﺔ‬ ‫وھذه‬ ‫اﻟﺣﺎﺳب‬ ‫ﻧﺟﻌل‬ ‫ﻟﻛﻲ‬ ‫اﻟﺷرط‬‫ﻛﻧ‬ ‫ﻣﮭﺎم‬ ‫ﻋدة‬ ‫ﺑﺈداء‬ ‫ﯾﻘوم‬‫ﺗ‬‫اﻟﺷرطﯾﺔ‬ ‫اﻟﺟﻣﻠﺔ‬ ‫ﻟﺗﺣﻘﻖ‬ ‫ﯾﺟﺔ‬ if (minute != 0) { System.out.print(" " + minute + " "); System.out.print( (minute != 1) ? "minutes" : "minute"); System.out.print(" past"); } ‫س‬١٩:‫اﻟﺷرط‬ ‫ﻛﺎن‬ ‫اذا‬ ‫ﻣﺎ‬ ‫ﻋﻣل‬ ‫اﻧﺟﺎز‬ ‫اﻟﺣﺎﺳب‬ ‫ﻣن‬ ‫ﻧرﯾد‬ ‫اﻷﺣﯾﺎن‬ ‫ﺑﻌض‬ ‫ﻓﻲ‬‫ﺑﻌﻣل‬ ‫واﻟﻘﯾﺎم‬ ‫ﺻﺣﯾﺣﺎ‬ ‫اﻟﻣ‬ ‫ھذه‬ ‫ﻓﻲ‬ ‫اﻟﻌزﯾز‬ ‫أﺳﺗﺎذي‬ ‫ﻧﻔﻌل‬ ‫ﻓﻣﺎذا‬ ‫ﺻﺣﯾﺢ‬ ‫ﻏﯾر‬ ‫اﻟﺷرط‬ ‫ھذا‬ ‫ﻛﺎن‬ ‫اذا‬ ‫آﺧر‬‫ﺷﻛﻠﺔ‬‫؟‬ ‫اﻟﺟﻣﻠﺔ‬ ‫اﺳﺗﻌﻣل‬ ‫ﻋﻠﯾك‬ ‫ذﻟك‬ ‫ﺗﻔﻌل‬ ‫ﻟﻛﻲ‬ else ‫اﻟﺟﻣﻠﺔ‬ ‫ﻣﻊ‬ if if (hour < 12) System.out.println("Good morning.n"); else if (hour < 17) System.out.println("Good afternoon.n"); else System.out.println("Good evening.n"); _____________________________________________________ _________________ if ( grade = = 'A') System.out.println(" ‫ﺑﺎﻣﺗﯾﺎز‬ ‫ﻧﺎﺟﺢ‬ ");
  19. 19. ١٩ else if ( grade = = 'B') System.out.println(" ‫ﺟدا‬ ‫ﺟﯾد‬ ‫ﺑﺗﻘدﯾر‬ ‫ﻧﺎﺟﺢ‬ "); else if ( grade = = 'C') System.out.println("‫ﺟﯾد‬ ‫ﺑﺗﻘدﯾر‬ ‫ﻧﺎﺟﺢ‬ "); else if ( grade = = 'D') System.out.println("‫ﻣﻘﺑول‬ ‫ﺑﺗﻘدﯾر‬ ‫ﻧﺎﺟﺢ‬ "); else System.out.println(" ‫ﻟﻼﻋﺎدة‬ ‫وﺑﺎق‬ ‫راﺳب‬ "); ‫س‬٢٠:‫ﯾ‬ ‫اﻻ‬ ‫أﻋﻼه‬ ‫اﻟﻣﺛﺎل‬ ‫ﺑﺎﺳﺗﺛﻧﺎء‬ ‫ﻓﻘط‬ ‫ﺷرطﺎن‬ ‫ﻓﯾﮭﺎ‬ ‫اﻟﺳﺎﺑﻘﺔ‬ ‫اﻟﺣﺎﻻت‬‫ﻟﻠﺗﻌﺎﻣل‬ ‫أﺧرى‬ ‫طرﯾﻘﺔ‬ ‫وﺟد‬ ‫ﻣﺗﻧوﻋﺔ‬ ‫ﻣﺧﺗﻠﻔﺔ‬ ‫ﺷروط‬ ‫ﻣﻊ‬ ‫ھذه‬ ‫ﻣﻧﻔردا‬ ‫ﻣﻧﮭﺎ‬ ‫ﻟﻛل‬ ‫واﻻﺳﺗﺟﺎﺑﺔ‬ ‫اﻟﺷروط‬ ‫ﻣن‬ ‫ﻣﺗﻧوﻋﺔ‬ ‫ﻣﺟﻣوﻋﺔ‬ ‫ﻻﺧﺗﺑﺎر‬ ‫أﺧرى‬ ‫طرﯾﻘﺔ‬ ‫ﯾوﺟد‬ ‫اﻟﺟﻣﻠﺔ‬ ‫اﺳﺗﻌﻣﺎل‬ ‫ھﻲ‬ ‫اﻟطرﯾﻘﺔ‬ switch ---------------------------------------------------------- switch (month) { case (1): System.out.print("January"); break; case (2): System.out.print("February"); break; case (3): System.out.print("March");
  20. 20. ٢٠ break; case (4): System.out.print("April"); break; case (5): System.out.print("May"); break; case (6): System.out.print("June"); break; case (7): System.out.print("July"); break; case (8): System.out.print("August"); break; case (9): System.out.print("September"); break; case (10): System.out.print("October"); break; case (11): System.out.print("November");
  21. 21. ٢١ break; case (12): System.out.print("December"); } ‫ﻧﺗﺳﺗﻌﻣل‬ ‫ﺛم‬ ‫اﻟﺷﮭر‬ ‫ﻣﺗﻐﯾر‬ ‫ھﻧﺎ‬ ‫وھو‬ ‫اﺧﺗﺑﺎره‬ ‫اﻟﻣراد‬ ‫اﻟﻣﺗﻐﯾر‬ ‫ﺳوﯾﺗش‬ ‫اﻟﺟﻣﻠﺔ‬ ‫ﻣن‬ ‫اﻷول‬ ‫اﻟﺳطر‬ ‫ﯾﺣدد‬ ‫ﻛﺗﻠﯾﺔ‬ ‫ﺟﻣﻠﺔ‬ ‫ﻟﺗﻛوﯾن‬ ‫اﻟﺣﺎﺻرﺗﯾن‬ ‫ذﻟك‬ ‫ﺑﻌد‬ case ‫اﻟﺟﻣﻠﺔ‬ ‫ﻣﻌﯾﻧﺔ‬ ‫ﺑﻘﯾﻣﺔ‬ ‫ﻣﻘﺎرﻧﺔ‬ ‫ﺳوﯾﺗش‬ ‫اﻟﺟﻣﻠﺔ‬ ‫ﻓﻲ‬ ‫اﻟﻣﺣدد‬ ‫اﻻﺧﺗﺑﺎر‬ ‫ﻣﺗﻐﯾر‬ ‫ﻗﯾﻣﺔ‬ ‫اﻟﺟﻣﻠﺔ‬ ‫ھذه‬ ‫ﺗﺧﺗﺑر‬ ‫س‬٢١‫أﻧواع‬ ‫ھﻲ‬ ‫ﻣﺎ‬ :‫ال‬Methods‫؟‬ ‫اﻟﺟﺎﻓﺎ‬ ‫ﻓﻲ‬ (‫)اﻟدوال‬ ‫ھﻧﺎك‬‫ﻧوﻋﺎن‬‫ﻣن‬‫اﻟﻣﯾﺛود‬‫ز‬: Getter:‫وﺗﺳﻣ‬‫ﻰ‬accessors methods‫وﻻ‬‫ﺗﻐﯾر‬‫ﺷﯾﺋﺎ‬‫ﻣن‬‫ﺣﺎﻟﺔ‬‫اﻷ‬‫وﺑﺟﻛت‬‫وﺗﻛون‬ ‫ﻣﻌﮭﺎ‬‫ﻛﻠﻣﺔ‬return‫ﻣﻼزﻣﺔ‬‫ﻟﮭﺎ‬. ‫ﻣﺛﺎل‬:frog.getPostion()‫ﻻﺗرﺟﻊ‬‫أي‬‫ﻗﯾم‬. Setter:‫وﺗﺳﻣﻲ‬Mutater methods‫ﺗﻐﯾر‬‫ﻣن‬‫ﺣﺎﻟﺔ‬‫اﻻوﺑﺟﻛت‬‫وﻻﺗوﺟد‬‫ﻣﻌﮭﺎ‬ ‫ﻛﻠﻣﺔ‬return‫ﻣﺛﺎل‬:frog.setColour(RED(‫ﻏﯾرت‬‫اﻻوﺑﺟﻛت‬‫ﻓروغ‬‫ﻟﻠون‬ ‫اﻻﺣﻣر‬.
  22. 22. ٢٢ ‫س‬٢٢‫اﻟـ‬ ‫ھﻲ‬ ‫ﻣﺎ‬ :packages‫؟‬ ‫ھﻲ‬‫ﻣﺟﻣوﻋﺔ‬‫ﻣن‬‫اﻟﻛﻼﺳﺎت‬‫ﯾﺗم‬‫اﺳﺗدﻋﺎﺋﮭﺎ‬‫ﻋﻧد‬‫اﻟﺣﺎﺟﺔ‬‫إﻟﯾﮭﺎ‬.‫وﺗﺳﺗﺧدم‬‫ﻛﻠﻣﺔ‬import ‫ﻻﺳﺗدﻋﺎﺋﮭﺎ‬،‫وﺗﻘوم‬‫ﺑ‬‫ﺎ‬‫ﺳﺗدﻋﺎء‬‫ﺟﻣﯾﻊ‬‫اﻟﻛﻼﺳﺎت‬‫ذات‬‫اﻟﻌﻼﻗﺔ‬‫ﻓﻲ‬‫اﻟﺑﺎﻛﺞ‬‫ﻋﻼﻣﺔ‬ ‫وﺿﻊ‬ ‫ﻋﻧد‬ (*) ‫اﻟﻧﺟﻣﺔ‬. ‫ھﻧﺎك‬‫ﻧوﻋﯾن‬‫ﻣن‬‫اﻟﺑﺎﻛﺞ‬‫ﻓﻲ‬‫اﻟﺟﺎﻓﺎ‬: ١-standered java backages-------<‫ﻛﻼﺳﺎت‬‫ﺟﺎھزة‬‫ﻟﻼﺳﺗﺧدام‬. ٢-developer java packages-------<‫ﺗﻛﺗب‬‫او‬‫ﺗطور‬‫ﺑواﺳطﺔ‬‫اﻟﻣﺑرﻣﺞ‬‫ﻧﻔﺳﮫ‬. ‫س‬٢٣‫اﻟﻔرق‬ ‫ھو‬ ‫ﻣﺎ‬ :‫ال‬ ‫ﺑﯾن‬overriding & overloading‫؟‬ overriding:‫ﺗﻌﻧﻲ‬‫أ‬‫ن‬‫ﻧﻔس‬‫اﻟﻣﯾﺛود‬‫ﺑﻧﻔس‬‫اﻷ‬‫ﺳم‬‫ﻓﻲ‬‫اﻟﺳوﺑر‬‫ﻛﻼس‬‫واﻟﺳب‬‫ﻛﻼس‬ ‫ﺗﻌدﯾﻠﮫ‬ ‫أو‬ ‫ﺗﻐﯾﯾره‬ ‫اﻟﻣراد‬ ‫اﻷﻣر‬ ‫ﺣﺳب‬ ‫ﻛﻼس‬ ‫اﻟﺳب‬ ‫ﻓﻲ‬ ‫ﻋﻠﯾﮭﺎ‬ ‫ﻧﻌدل‬ ‫ﻟﻛﻧﻧﺎ‬. overloading:‫ﻧﻔس‬‫اﻟﻣﯾﺛود‬‫ﻓﻲ‬‫ﻧﻔس‬‫اﻟﻛﻼس‬‫ﻟﻛﻧﮭﺎ‬‫ﺗﺧﺗﻠف‬‫ﻓﻲ‬. ‫اﻟﺑﺎراﻣﯾرات‬ ‫ﻋدد‬ ‫س‬٢٤‫؟‬ ‫اﻟﺟﺎﻓﺎ‬ ‫ﻓﻲ‬ ‫اﻟﻣﺗﻐﯾرات‬ ‫أﻧواع‬ ‫ھﻲ‬ ‫ﻣﺎ‬ : primitive data type<<‫ﻣﺟﻣوﻋﺔ‬‫ﻣن‬‫اﻟﻘﯾم‬‫وﺗﻧﻘﺳم‬‫اﻟﻲ‬‫اﻧواﻋﻧﺎ‬‫اﻟﻣﻌروﻓﺔ‬: ‫ﻣﺛل‬ ، int, double, byte, etc refrenace type<<‫ﺗﺷﯾر‬‫إ‬‫ﻟ‬‫ﻰ‬‫اوﺑﺟﻛت‬: ‫ﻣﺛل‬String , Array. ‫س‬٢٥‫ﻣﺻطﻠﺢ‬ ‫ھو‬ ‫ﻣﺎ‬ :‫اﻟـ‬escape sequence‫؟‬ ‫ھو‬‫ﻣﺻطﻠﺢ‬‫ﯾﻌﻧﻲ‬‫اﺳﺗﺧدام‬‫ﻋﻼﻣﺔ‬‫اﻟﺑﺎك‬‫ﺳﻼش‬)(‫ﻟﯾﻐﯾر‬‫ﻣﻔﻌول‬‫ﻣﺎ‬‫ﺑﻌد‬‫اﻟﺣروف‬‫ﻓﻲ‬ ‫ﻟﻐﺔ‬‫اﻟﺟﺎﻓﺎ‬‫ﻓﻣﺛﻼ‬: 'n'‫ﺗﻌﻧﻲ‬‫ﺳطر‬‫ﺟدﯾد‬.
  23. 23. ٢٣ ‫س‬٢٦‫اﺳﺗﺧدام‬ ‫ﻣﻌﻧﻰ‬ ‫ﻣﺎ‬ :static‫اﻟـ‬ ‫ﻓﻲ‬methods & variables‫؟‬ ‫ﻋﻧدﻣﺎ‬‫ﯾﺣﺗوي‬‫اﻟﻛﻼس‬‫ﻋﻠﻲ‬‫أ‬‫ي‬‫ﻣن‬static methods OR variables‫ﺗﻌﻧﻲ‬‫اﻧﮭﺎ‬ ‫ﺗﺣﺗوي‬‫ﻋﻠﻰ‬‫ﻧﺳﺧﺔ‬‫واﺣدة‬‫ﻓﻘط‬‫ﻓﻲ‬‫اﻟﻛﻼس‬‫ﻟﻛل‬‫اﻻوﺑﺟﻛﺗز‬. ‫ﯾﺗم‬‫ا‬‫ﺳﺗﺧدام‬static variables‫ﻣﻊ‬‫اﻟﺛواﺑت‬‫او‬‫ﻋﻧد‬‫ﺗﻌرﯾف‬variable‫واﺣد‬‫ﻓﻲ‬‫ﻛل‬ ‫اﻟﻛﻼﺳﺎت‬. ‫س‬٢٧* ‫ﺑﺎﻛﺞ‬ ‫ھﻲ‬ ‫ﻣﺎ‬ :java.lang.‫؟‬ ‫ھذ‬‫ه‬‫اﻟﺑﺎﻛﺞ‬‫ﯾﺗم‬‫اﺳﺗﺧداﻣﮭﺎ‬‫ﻓﻲ‬‫ﺟﻣﯾﻊ‬‫ﻛﻼﺳﺎت‬‫اﻟﺟﺎﻓﺎ‬‫ﻟذﻟك‬‫ﻟﯾس‬‫ھﻧﺎك‬‫داﻋﻲ‬‫ﻟﻺ‬‫ﺳﺗدﻋﺎﺋﮭﺎ‬ ‫ﻓﻲ‬‫ﻛل‬‫ﺑرﻧﺎﻣﺞ‬،،‫ﻷ‬‫ﻧﮫ‬‫ﯾﺗم‬‫اﺳﺗدﻋﺎﺋﮭﺎ‬‫اﺗوﻣﺎﺗﯾﻛﯾ‬‫ﺎ‬. ‫س‬٢٨:‫ﻣﺎ‬‫ھو‬‫اﻟﻔرق‬‫ﺑﯾن‬(&)‫و‬(&&)‫ﻓﻲ‬‫ﺟﻣل‬‫اﻟﻣﻘﺎرﻧﺔ‬‫؟‬ ‫اﻟﻔرق‬‫ﺑﯾﻧﮭﻣﺎ‬: ‫اﻟﺣﺎﻟﺔ‬‫اﻷوﻟﻰ‬: (&) ‫ﻓﻲ‬‫ھذه‬‫اﻟﺣﺎﻟﺔ‬‫ﯾﻘوم‬‫اﻟﻣﺗرﺟم‬)‫اﻟﻛوﻣﺑﯾﻠر‬(‫ﺑﺎﻟﻧظر‬‫إﻟﻰ‬‫اﻟﻣدﺧل‬‫اﻷول‬‫ﻓﺈذا‬‫ﻛﺎن‬‫ﺧﺎطﺋﺎ‬‫ﻓﺈﻧﮫ‬ ‫ﻻ‬‫ﯾﻔﺣص‬‫اﻟﻣدﺧل‬‫اﻟﺛﺎﻧﻲ‬. ‫ﻣﺛﺎﻟﮫ‬: public void and() { int a = 10 ; int b = 5 ; if ((a == 22) & (++b == 5)) System.out.println("case one"); System.out.println (b); }
  24. 24. ٢٤ ‫ﺑﺎﻟطﺑﻊ‬‫ﻟن‬‫ﯾﻘوم‬‫اﻟﻣﺗرﺟم‬‫ﺑطﺑﺎﻋﺔ‬")case one("‫ﻷن‬‫أﺣد‬‫اﻟﺷرطﯾن‬‫ﻟم‬‫ﯾﺗﺣﻘﻖ‬‫وﻟﻛن‬ ‫ﻋﻧدﻣﺎ‬‫ﯾطﺑﻊ‬b‫ﻓﺈﻧﮫ‬‫ﺳﯾطﺑﻌﮭﺎ‬‫ﻛﻣﺎ‬‫ھﻲ‬‫دون‬‫أن‬‫ﯾزﯾد‬‫ﻋﻠﯾﮭﺎ‬‫ﻷﻧﮫ‬‫ﻟم‬‫ﯾﻔﺣص‬‫اﻟﻣدﺧل‬‫اﻟﺛﺎﻧﻲ‬ .. ‫ﻟذا‬‫ﺳﯾطﺑﻊ‬‫ﻟﻧﺎ‬٥.. ‫اﻟﺣﺎﻟﺔ‬‫اﻟﺛﺎﻧﯾﺔ‬: (&&) ‫أﻣﺎ‬‫ﻓﻲ‬‫ھذه‬‫اﻟﺣﺎﻟﺔ‬‫ﻓﺈن‬‫اﻟﻣﺗرﺟم‬‫ﯾﻧظر‬‫إﻟﻰ‬‫اﻟﻣدﺧل‬‫اﻷول‬‫واﻟﺛﺎﻧﻲ‬‫ﻣﻌﺎ‬‫ﺣﺗﻰ‬‫ﻟو‬‫ﻛﺎن‬ ‫اﻟﻣدﺧل‬‫اﻷول‬ً‫ﺧﺎطﺋﺎ‬.. public void and_and () { int a = 10 ; int b = 5 ; if ((a == 22) && (++b == 5)) System.out.println("case two"); System.out.println (b); } ‫أﯾﺿﺎ‬‫ھﻧﺎ‬‫ﻟن‬‫ﯾﻘوم‬‫اﻟﻣﺗرﺟم‬‫ﺑطﺑﺎﻋﺔ‬")case two("‫ﻷن‬‫أﺣد‬‫اﻟﺷرطﯾن‬‫ﻟم‬‫ﯾﺗﺣﻘﻖ‬‫وﻟﻛن‬ ‫ﻋﻧدﻣﺎ‬‫ﯾطﺑﻊ‬b‫ﻓﺈﻧﮫ‬‫ﺳﯾزﯾد‬‫ﻋﻠﯾﮭﺎ‬‫ﻷﻧﮫ‬‫ﻗﺎم‬‫ﺑﻔﺣص‬‫اﻟﻣدﺧل‬‫اﻟﺛﺎﻧﻲ‬.. ‫ﻟذا‬‫ﺳﯾطﺑﻊ‬‫ﻟﻧﺎ‬٦.. ‫س‬٢٩‫ﻣﺎ‬ :‫ﻓﺎﺋدة‬‫اﻟطرﯾﻘﺔ‬toString()‫؟‬ ‫ھذه‬‫اﻟطرﯾﻘﺔ‬‫ﻣوﺟودة‬‫ﻓﻲ‬‫اﻟﻔﺋﺔ‬Object‫وﺑﺎﻟﺗﺎﻟﻲ‬‫ﻓﮭﻲ‬‫ﻣوﺟودة‬‫ﻓﻲ‬‫ﺟﻣﯾﻊ‬،‫اﻟﻔﺋﺎت‬‫ﻷن‬‫ﻛل‬‫اﻟﻔﺋﺎت‬ ‫ﺗرث‬‫ﻣن‬‫اﻟﻔﺋﺔ‬Object.
  25. 25. ٢٥ ‫ھذه‬‫اﻟطرﯾﻘﺔ‬‫ﺗﻧﺗﺞ‬‫ﺻورة‬‫ﻧﺻﯾﺔ‬‫ﻟﻠﻛﺎﺋن‬‫ﻋﻠﻰ‬‫ﺷﻛل‬‫ﻛﺎﺋن‬String ‫ھذا‬‫ﺗﻌرﯾف‬Sun‫ﻟطرﯾﻘﺔ‬toString ()toStringpublic String a string that "textuallygeneral, the toString method returnsof the object. Instring representationReturns a that is easy for a personconcise but informative representation. The result should be arepresents" this object to read. It is recommended that all subclasses override this method. ‫ﻟﻧﻔﺗرض‬‫ﻟدﯾﻧﺎ‬‫اﻟﻔﺋﺔ‬(‫)اﻟﻛﻼس‬‫اﻟﺗﺎﻟﯾﺔ‬ public class Person { String firstName, lastName; int age; public Person(String firstName, String lastName, int age) { this.firstName = firstName; this.lastName = lastName; this.age = age; } } ‫إذا‬‫ﻧﻔذﻧﺎ‬‫اﻟﻛود‬‫اﻟﺗﺎﻟﻲ‬ Person p = new Person("Ahmed", "Ali", 40); System.out.println(p); ‫ﺳﻧﺣﺻل‬‫ﻋﻠﻰ‬‫اﻟﻧﺗﯾﺟﺔ‬‫اﻟﺗﺎﻟﯾﺔ‬ Person@3e25a5
  26. 26. ٢٦ ‫ﺣﺻﻠﻧﺎ‬‫ﻋﻠﻰ‬‫ھذه‬‫اﻟﻧﺗﯾﺟﺔ‬‫ﻹ‬‫ﻧﻧﺎ‬‫ﻟم‬‫ﻧﻌﻣل‬override‫ل‬toString‫اﻟﻣوروﺛﺔ‬‫ﻣن‬Object. ‫ﻟﻛن‬‫إذا‬‫ﻏﯾرﻧﺎ‬‫اﻟﻛود‬‫اﻟﺳﺎﺑﻖ‬‫إﻟﻰ‬‫اﻟﺗﺎﻟﻲ‬ public class Person { String firstName, lastName; int age; public Person(String firstName, String lastName, int age) { this.firstName = firstName; this.lastName = lastName; this.age = age; } @Override public String toString() { return firstName + " " + lastName + " is " + age + " years old."; } } ‫ﺳﻧﺣﺻل‬‫ﻋﻠﻰ‬‫اﻟﻧﺗﯾﺟﺔ‬‫اﻟﺗﺎﻟﯾﺔ‬ Ahmed Ali is 40 years old.
  27. 27. ٢٧ ‫س‬٣٠:‫ﻛﯾف‬‫أﻋﻣل‬Compile‫ﻟﻣﻠف‬java‫ﺑﺎﺳﺗﻌﻣﺎل‬‫ﺳطر‬‫اﻷواﻣر؟‬ ‫ﻧﻛﺗب‬‫اﻷﻣر‬javac‫ﻣﺗﺑوﻋﺎ‬‫ﺑﺎﺳم‬‫اﻟﻣﻠف‬ ‫ﻣﺛﻼ‬ javac arabteam.java ‫س‬٣١:‫ﻛﯾف‬‫أﺷﻐل‬‫ﺑرﻧﺎﻣﺞ‬‫ﺟﺎﻓﺎ‬‫ﺑﻌد‬‫ﻋﻣﻠﯾﺔ‬compile‫ﺑﺎﺳﺗﻌﻣﺎل‬‫ﺳطر‬‫اﻷواﻣر؟‬ ‫ﺑﻌد‬‫ﻋﻣﻠﯾﺔ‬‫اﻟـ‬compile‫ﯾﻧﺗﺞ‬‫ﻣﻠف‬‫ﯾﺣﻣل‬‫ﻧﻔس‬‫اﺳم‬‫ﻣﻠف‬.java‫و‬‫ﻟﻛن‬‫ذو‬‫اﻣﺗداد‬.class ‫ﻟﺗﺷﻐﯾل‬‫ھذا‬‫اﻟﻣﻠف‬‫ﻧﻛﺗب‬‫اﻷﻣر‬java‫ﻣﺗﺑوﻋﺎ‬‫ﺑﺎﺳم‬‫اﻟﻣﻠف‬)‫ﻣن‬‫دون‬‫اﻟﻧﻘطﺔ‬‫و‬‫اﻻﻣﺗداد‬( ‫ﻣﺛﺎل‬: ‫ﻟدﯾﻧﺎ‬‫ﻣﻠف‬arabteam.class ‫ﻧﻛﺗب‬ java arabteam ‫س‬٣٢‫ﻣﺻطﻠﺢ‬ ‫ھو‬ ‫ﻣﺎ‬ :‫اﻟـ‬Casting‫؟‬ ‫ھو‬‫ﯾﻌﻧﻲ‬‫اﻟﺗﺣوﯾل‬‫ﻣن‬‫ﻧوع‬‫ﻟﻧوع‬‫آﺧر‬‫وذﻟك‬‫ﺑﻛﺗﺎﺑﺔ‬‫اﻟﻧوع‬‫اﻟﻣطﻠوب‬‫اﻟﺗﺣوﯾل‬‫اﻟﯾﮫ‬‫ﺑﯾن‬ ‫ﻗوﺳﯾن‬()‫اﻣﺎم‬‫اﻻﻛﺳﺑرﯾﺷﯾن‬‫اﻟﻣراد‬: ‫ﻣﺛل‬ ، ‫ﺗﺣوﯾﻠﮫ‬ ;12=c,24=b,35=aint ;cchar );c+b+a()char(=c
  28. 28. ٢٨ ‫س‬٣٣‫اﻟﺛواﺑت‬ ‫ﻟﺗﻌرﯾف‬ ‫اﻟطرﯾﻘﺔ‬ ‫ھﻲ‬ ‫ﻣﺎ‬ :Constants)‫؟‬ ( ‫ﯾﺳﺗﺧدم‬‫ﻣﻊ‬‫اﻟﺛواﺑت‬‫ﻛﻠﻣﺔ‬final‫ﻟﻠدﻻﻟﺔ‬‫ﻋﻠﻰ‬‫اﻧﮭﺎ‬‫ﻗﯾﻣﺔ‬‫ﻧﮭﺎﺋﯾﺔ‬‫ﻏﯾر‬‫ﻗﺎﺑﻠﺔ‬‫ﻟﻠﺗﻐﯾﯾر‬. ‫ﻣﺛل‬:;final int s = 2 ‫س‬٣٤‫ﻣﺎ‬ :‫ھو‬‫اﻟﻔرق‬‫ﺑﯾن‬‫ھ‬‫ذ‬‫ه‬‫اﻟﻣﺗﻐﯾرات‬‫ﻓﻲ‬‫؟‬ ‫اﻟﺟﺎﻓﺎ‬ global local static dynamic global‫ﻣﻌﻧﺎھﺎ‬‫اﻧﮫ‬‫أ‬ ‫أي‬‫ﺣد‬‫ﯾﻘدر‬‫ﯾﺷوف‬‫ھذا‬‫اﻟﻣﺗﻐﯾر‬.. ‫أﻣﺎ‬local]‫ﯾﺻﺑﺢ‬‫ﻋﻠﻰ‬‫ﻣﺳﺗوى‬‫اﻟﺑﻠوك‬‫او‬‫اﻟﻔﺎﻧﻛﺷن‬‫اﻟﻠ‬‫ﻲ‬‫ﻣﺗﻌرف‬‫داﺧﻠﮭﺎ‬ ‫ﻓﻲ‬‫اﻟﻔﺎرﯾﺑل‬‫او‬ ‫ﻋﻠﻰ‬‫ﻣﺳﺗوى‬‫اﻟﻛﻼس‬‫اﻟذي‬‫داﺧﻠﮫ‬ ‫ﻓﻲ‬‫اﻟﻔراﯾﺑل‬.. ‫اﻣﺎ‬‫ال‬Static‫ﻓ‬‫ﮭذا‬‫ﻣﺗﻐﯾر‬‫ﯾﺑﻘﻰ‬‫ﺛﺎﺑت‬‫ﻣﻌﺎك‬‫ﻋ‬‫ﻠﻰ‬‫طول‬‫ﺑﻧﻔس‬‫اﻟﻘﯾﻣﺔ‬‫ﺣﺗﻰ‬‫اﻻﻧﺗﮭﺎء‬‫ﻣن‬ ‫اﻟﺑرﻧﺎﻣﺞ‬ dynamic‫ھذا‬‫ﻣﺗﻐﯾر‬‫ﺗﺗﻐﯾر‬‫ﻗﯾﻣﺗﮫ‬‫اﺛﻧﺎء‬‫ال‬run -time‫ﻟﻠ‬‫ﺑرﻧﺎﻣﺞ‬..
  29. 29. ٢٩ ‫س‬٣٥‫ﻣﺎ‬ :‫ھو‬‫اﻟﻔرق‬‫ﺑﯾن‬String and Stringbuffer‫؟‬ String:‫ﯾﻌﺗﺑر‬‫ﻛﻧوع‬‫ﻟﺗﻌر‬‫ﯾ‬‫ف‬‫ﻣﺗﻐﯾر‬‫ﻧﺻﻲ‬‫وﻻ‬‫ﯾﺣﺗﺎج‬‫إ‬‫ﻟﻰ‬new‫ﻋﻠﯾﮫ‬ ‫اﻟﺗﻌدﯾل‬ ‫ﯾﻣﻛن‬ ‫وﻻ‬ ‫اﻟﺑرﻧﺎﻣﺞ‬ ‫ﺗﺷﻐﯾل‬ ‫اﺛﻧﺎء‬RunTime. Stringbuffer:‫إﻟﻰ‬ ‫ﯾﺣﺗﺎج‬ ‫وﻟﻛﻧﮫ‬ ‫اﯾﺿﺎ‬ ‫ﻧﺻﻲ‬ ‫ﻣﺗﻐﯾر‬ ‫ﻟﺗﻌرﯾف‬new‫اﻟﺗﻌدﯾل‬ ‫وﯾﻣﻛن‬ ‫أﺛﻧﺎء‬ ‫ﻓﻲ‬ ‫ﻋﻠﯾﮫ‬RunTime. ‫س‬٣٦:‫ھ‬ ‫ﻣﻌﻧﻰ‬ ‫ﻣﺎ‬‫ذا‬‫اﻟ‬‫ﻛﻼس‬‫اﻟﺧ‬ ‫ﻓﻲ‬‫ط‬‫اﻻﺣﻣر‬‫؟‬ import java.util.GregorianCalendar ‫ھ‬‫و‬‫ﻟﻐ‬ ‫ﻓﻲ‬ ‫ﻣﺣﺟوز‬ ‫ﻛﻼس‬‫ﺔ‬‫وﺗﻐﯾر‬ ‫واﻟﺗﺎرﯾﺦ‬ ‫ﻟﻠوﻗت‬ ‫دوال‬ ‫ﻋده‬ ‫داﺧﻠﮭﺎ‬ ‫ﻓﻲ‬ ‫وﯾوﺟد‬ ‫ﺟﺎﻓﺎ‬ ‫ﺣﺳب‬ ‫اﻟوﻗت‬. ‫اﻟﻣوﻗﻊ‬ ) ‫اﻟوراﺛﺔ‬(Inheritance ‫س‬٣٧:‫ﻣﺎ‬‫ﻣﻌﻧﻰ‬‫اﻟوراﺛﺔ‬)(inheritance‫؟؟‬ ‫ھﻲ‬‫ﺑﻣﻔﮭوﻣﮭﺎ‬‫اﻟﺷﺎﺋﻊ‬‫ان‬‫ﯾرث‬‫اﻻﺑن‬‫ﻣن‬‫اﺑﯾﮫ‬‫ﺑﻌض‬‫او‬‫ﻛل‬‫ﺻﻔﺎﺗﮫ‬‫و‬‫ﺧﺎﺻﯾﺎﺗﮫ‬،‫ﻓﻠﻐﺔ‬ ‫ﺟﺎﻓﺎ‬‫ﺗوﻓر‬‫ﻟك‬‫ھذه‬‫اﻟﺧﺎﺻﯾﺔ‬‫ﻣن‬‫ﺧﻼل‬‫اﻣﻛﺎﻧﯾﺔ‬‫وراﺛﺔ‬‫ﻛﻼس‬‫ﻣن‬‫ﻛﻼس‬‫اﺧر‬‫ﺣﯾث‬‫ﯾﺻﺑﺢ‬
  30. 30. ٣٠ ‫اﻟﻛﻼس‬‫اﻟﺟدﯾد‬‫ﯾﻣﺗﻠك‬‫ﻛل‬‫ﺧواص‬‫اﻟﻛﻼس‬‫اﻻول‬)‫ﻣﺗﻐﯾرات‬،‫دوال‬...‫اﻟﺦ‬(‫وﯾﺳﻣﻰ‬ ‫اﻟﻛﻼس‬‫اﻟﺟدﯾد‬‫ﺑـ‬‫ﺳﺎب‬‫ﻛﻼس‬)(SubClass. ‫س‬٣٨:‫ھل‬‫ﻧﺳﺗطﯾﻊ‬‫اﻟوﺻول‬‫اﻟﻰ‬‫ﻛل‬‫ﻣﺗﻐﯾرات‬‫اﻟﻛﻼس‬‫اﻻﺻﻠﻲ‬‫ﻣن‬‫اﻟﻛﻼس‬‫اﻟﺳﺎب‬ ‫ﻛﻼس‬)(SubClass‫ﻣﺑﺎﺷرة‬ ‫اﻟﻣﺗﻐﯾر‬ ‫اﺳم‬ ‫طرﯾﻖ‬ ‫ﻋن‬ ‫ا‬‫ذا‬‫ﻛﺎﻧت‬‫ﺑر‬‫ا‬‫ﯾﻔت‬‫؟؟‬ ‫اﻟﺟواب‬:،‫ﻻ‬‫ﻻ‬‫ﯾﻣﻛﻧك‬‫اﻟوﺻول‬‫اﻟﻰ‬‫اﻟﻣﺗﻐﯾرات‬‫ﺑﺻﯾﻐﺔ‬‫ﺑر‬‫اﯾﻔ‬‫ت‬‫ﻋن‬‫طرﯾﻖ‬‫اﺳم‬ ‫اﻟﻣﺗﻐﯾر‬‫ﻣﺑﺎﺷرة‬‫ﺑل‬‫ﻋن‬‫طرﯾﻖ‬‫اﻟﺳﯾت‬set)(‫و‬‫اﻟﺟﯾت‬)get(‫اﻟﺧﺎﺻﺔ‬‫ﺑﺎﻟﻣﺗﻐﯾر‬. ‫ﻣﻼﺣظﺔ‬:‫ﻣن‬‫اﻟ‬‫ﻣﺳﺗﺣﺳن‬‫ﺟﻌل‬‫اﻟﻣﺗﻐﯾر‬‫ﺑﺻﯾﻐﺔ‬‫ﺑروﺗﻛ‬‫ﺗ‬‫د‬‫ﻓﻲ‬‫اﻟﻛﻼس‬‫اﻻﺻﻠﻲ‬‫ﻟﯾﺳﮭل‬ ‫ﻋﻠﯾك‬‫اﻟوﺻول‬‫اﻟﯾﮫ‬‫ﻣن‬‫ﺧﻼل‬‫اﻟﻛﻼﺳﺎت‬‫اﻟوارﺛﺔ‬‫ﻣن‬‫ھذا‬‫اﻟﻛﻼس‬. ‫اﻹﺳﺗﺛﻧﺎءات‬Exceptions)( ‫س‬٣٩‫اﻹ‬ ‫ھﻲ‬ ‫ﻣﺎ‬ :‫ﺳﺗﺛﻧﺎءات‬‫؟‬ ‫ھو‬‫ﺣدث‬‫ﯾظﮭر‬‫اﺛﻧﺎء‬‫ﺗﻧﻔﯾذ‬‫اﻟﺑرﻧﺎﻣﺞ‬‫وﯾﻌرﻗل‬‫ﺧط‬‫ﺳﯾر‬‫اﻟﺑرﻧﺎﻣﺞ‬‫اﻟطﺑﯾﻌﻲ‬‫وﯾﺗم‬‫ﺣﻣل‬‫ھذه‬ ‫اﻻﺳﺗﺛﻧﺎءات‬‫ﻟﻠﺗﻌﺎﻣل‬‫ﻣﻊ‬‫اﻻﺧطﺎء‬‫اﻟﻣﺗوﻗﻌﺔ‬‫واﻟﻐﯾر‬‫ﻣﺗوﻗﻌﺔ‬. ‫اﻣﺛﻠﺔ‬‫ﻋﻠﻰ‬‫ﺑﻌض‬‫اﻻﺧطﺎء‬‫اﻟﻣﺗوﻗﻌﺔ‬: ‫ﺑرﻧﺎﻣﺞ‬‫ﯾﺣﺎول‬‫ﻗراءة‬‫ﻟﯾﻧك‬‫ﻏﯾر‬‫ﻣوﺟود‬ ‫ﺑرﻧﺎﻣﺞ‬‫ﻣﺻﻣم‬‫ﻟﻘراءة‬‫ارﻗﺎم‬‫اﻧﺗﺟر‬‫ﻣن‬‫ﻣﻠف‬‫ﻓﯾﺟدھﺎ‬‫ﻣن‬‫ﻧوع‬‫ﺳﺗرﯾﻧﺞ‬.
  31. 31. ٣١ ‫س‬٤٠‫ﺣﻣل‬ ‫ﻋﻣﻠﯾﺔ‬ ‫ھﻲ‬ ‫ﻣﺎ‬ :) ‫اﻻﺳﺗﺛﻧﺎءات‬(Exception handle‫؟‬ ١-‫ﻋﻧدﻣﺎ‬‫ﯾﺟد‬‫اﻟﺳﺳﺗم‬‫ﺧطﺄ‬‫ﯾﺗم‬‫إﯾﻘﺎف‬‫ﺗدﻓﻖ‬‫ﺗﻧﻔﯾذ‬‫اﻟﺑﯾﺎﻧﺎت‬‫ﻓﻲ‬‫اﻟﺑرﻧﺎﻣﺞ‬‫وﺗﺳﻣﻰ‬‫ﺑﻌﻣﻠﯾﺔ‬ ‫ﻗذف‬‫اﻻﺳﺗﺛﻧﺎء‬throw the exception. ٢-‫ﯾﺗم‬‫ﺧﻠﻖ‬‫اوﺑﺟﻛت‬‫ﻣن‬‫ﻧوع‬‫ﺧﺎص‬‫ﯾﺳﻣﻲ‬exception‫وﯾﺣﻣل‬‫ﻣﻌﻠوﻣﺎت‬‫ﻋن‬‫اﻟﺧطﺄ‬ ‫اﻟذي‬. ‫ﺣدث‬ ٣-‫ﺑﻌد‬‫ذﻟك‬‫ﯾﺗم‬‫اﻟﺗﻌﺎﻣل‬‫ﻣﻊ‬‫اﻟﺧطﺄ‬‫واﻟﺗﻘﺎطﮫ‬‫واﯾﺟﺎد‬‫ﺣل‬‫ﻣﻧﺎﺳب‬‫وﺗﺳﻣﻰ‬‫ﺑﻌﻣﻠﯾﺔ‬ catch the exception. ‫س‬٤١‫؟‬ ‫اﻹﺳﺗﺛﻧﺎءات‬ ‫أﻧواع‬ ‫ھﻲ‬ ‫ﻣﺎ‬ : ١-Errors class and its subclasses ‫ﻟﻼﺧطﺎء‬‫اﻟداﺧﻠﯾﺔ‬‫ﻓﻲ‬‫اﻟﺑرﻧﺎﻣﺞ‬:‫ﻣﺛل‬‫اﻧﺗﮭﺎء‬‫اﻟذاﻛرة‬ ٢-Exception class and its subclasses ‫اﺧطﺎء‬‫ﻣﺣﺗﻣﻠﺔ‬‫وﻣﺗوﻗﻊ‬‫ﺣدوﺛﮭﺎ‬‫وﺗﺳﻣﻰ‬Checked exceptions‫وﻻﺑد‬‫ﻣن‬‫اﻟﺗﻘﺎطﮭﺎ‬ ‫واﻻ‬‫ﺗﺳﺑب‬‫ﺧطﺄ‬‫ﻓﻲ‬‫اﻟﺑرﻧﺎﻣﺞ‬ ٣-Runtime exceptions and its subclasses ‫أﺧطﺎء‬‫ﯾﺳﻣﺢ‬‫اﻟﻣﺗرﺟم‬compiler‫ﺑﺗﺟﺎھﻠﮭﺎ‬‫وﺗﺳﻣﻰ‬Uncheck Exception *-‫ﺑﺎﻟﻧﺳﺑﺔ‬‫ﻟﻠ‬‫ـ‬Checked exceptions‫ﯾﺗم‬‫اﻟﺗﻘﺎط‬‫اﻟﺧطﺄ‬‫ﺑطرﯾﻘﺗﯾن‬: ١-Try.. catch blocks ‫وطرﯾﻘﺗﮫ‬: try‫اﻟﻛود‬‫اﻟﻣﺷﻛوك‬‫ﺑﺣدوث‬‫ﺧطﺄ‬‫ﻓﯾﮫ‬ catch‫اﻟﻛود‬‫اﻟذي‬‫ﯾﺟب‬‫ان‬‫ﯾﻧﻔذ‬‫إذا‬‫ﺣﺻل‬‫وﺣدث‬‫اﻻﺳﺗﺛﻧﺎء‬
  32. 32. ٣٢ ‫ﯾﺗم‬‫اﺳﺗﺧدام‬finally block‫داﺋﻣﺎ‬‫ﯾﺗم‬‫ﺗﻧﻔﯾذه‬‫ﺑﻌد‬‫ال‬try‫ﺑﻠوك‬‫وﯾﺳﺗﺧدم‬‫ﻟوﺿﻊ‬‫ﻛود‬ ‫ﻧظﯾف‬‫ﺧﺎﻟﻲ‬‫ﻣن‬‫اﻻﺳﺗﺛﻧﺎءات‬. ٢-‫ﺗﻌرﯾف‬‫اﻻﺳﺗﺛﻧﺎء‬exception‫ﻓﻲ‬‫راس‬‫اﻟﻣﯾﺛود‬in the method header: ‫ﯾﺗم‬‫ﺗﻌرﯾف‬‫اﻻﺳﺗﺛﻧﺎء‬‫ﻓﻲ‬‫راس‬‫اﻟﻣﯾﺛود‬‫ﺑﺎﺳﺗﺧدام‬‫ﻛﻠﻣﺔ‬Throws‫ﯾﻠﯾﮭﺎ‬‫ﻧوع‬‫اﻻﺳﺗﺛﻧﺎء‬.. public Boolean check format (String fileName) throws EO Exception ‫ﻋﺎم‬ ‫س‬٤٢:System.out.print ('1'+1); ‫طﺑﻊ‬ ‫ﺑوت‬ ‫اﻵوت‬ ‫ﻟﻣﺎذا‬٥٠!‫؟‬ ‫ﻻن‬character 1 ‫ﻗﯾﻣﺗﮫ‬‫ب‬‫اﻻﺳﻛﻲ‬‫ﻛود‬٤٩ ‫زي‬‫ﻣﺛﻼ‬‫ﺣرف‬'a' ‫ﻗﯾﻣﺗﮫ‬٩٧ ‫ﻓﻠﻣﺎ‬‫ﺗﺳوي‬ 'a' +1 ‫ﯾطﺑﻊ‬‫ﻟك‬٩٨
  33. 33. ٣٣ ‫ﻓﯾﮫ‬ ‫ﯾوﺟد‬ ‫آﺳﻛﻲ‬ ‫ﺟدول‬ ‫وھذا‬‫ﻛل‬char‫وﻗﯾﻣﺗﮫ‬‫ب‬‫اﻟ‬‫ـ‬Decemal http://www.unfiction.com/dev/tutorial/ascii.html ‫س‬٤٣‫اﻟـ‬ ‫ﻣﺻطﻠﺢ‬ ‫ﻣﻌﻧﻰ‬ ‫ھو‬ ‫ﻣﺎ‬ :Deprecated‫؟‬ ‫ﻟﻧﻔﺗرض‬‫أﻧك‬‫ﻛﺗﺑت‬،‫ﻣﻛﺗﺑﺔ‬‫واﻟﻧﺳﺧﺔ‬‫اﻷوﻟﻰ‬‫اﻟﻣﻛﺗﺑﺔ‬‫ﺗﺣﺗوي‬‫ﻋﻠﻰ‬‫اﻟﻔﺋﺔ‬Class1. ‫ﻓﻲ‬‫اﻟﻧﺳﺧﺔ‬‫اﻟﺛﺎﻧﯾﺔ‬‫ﻣن‬،‫اﻟﻣﻛﺗﺑﺔ‬‫وﺟدت‬‫أن‬‫اﻟﻔﺋﺔ‬Class1‫ﯾﻧﻘﺻﮭﺎ‬‫اﻟﻛﺛﯾر‬‫ﻣن‬،‫اﻟﻣﯾزات‬ ‫ﻓﻘررت‬‫أن‬‫ﺗﻛﺗب‬‫ﻓﺋﺔ‬‫ﺟدﯾدة‬Class2‫اﻟﺗﻲ‬‫ﺗﻘوم‬‫ﺑﻧﻔس‬‫ﻋﻣل‬Class1‫ﺑﺎﻹﺿﺎﻓﺔ‬‫ﻷﺷﯾﺎء‬ ‫أﺧرى‬. ‫طﺑﻌﺎ‬‫ﻟن‬‫ﺗﻘوم‬‫ﺑﻣﺳﺢ‬Class1،‫ﻣﺑﺎﺷرة‬‫ﺑل‬‫أوﻻ‬‫ﺳﺗﻘوم‬‫ﺑوﺻﻔﮭﺎ‬‫ﺑﺄﻧﮭﺎ‬deprecated، ‫أي‬‫أﻧﮭﺎ‬‫ﻣﺗﻘﺎدﻣﺔ‬(‫ﻣﮭﻣﻠﮫ‬ ‫أو‬ ‫)ﻗدﯾﻣﺔ‬،‫ﺣﺗﻰ‬‫ﯾﻌرف‬‫اﻟﻣﺳﺗﻌﻣﻠون‬‫أن‬‫ھذه‬‫اﻟﻔﺋﺔ‬‫ﻣﺗﻘﺎدﻣﺔ‬‫وﯾﺟب‬ ‫اﺳﺗﻌﻣﺎل‬Class2.‫ﺑﻌد‬،‫ذﻟك‬‫ﻓﻲ‬‫اﻟﻧﺳﺦ‬،‫اﻟﻘﺎدﻣﺔ‬‫ﯾﻣﻛﻧك‬‫ﺣذﻓﮭﺎ‬. ‫ﻓﻲ‬‫أﻛﺛر‬‫اﻷﺣﯾﺎن‬‫ﺗﺳﺗﺧدم‬‫اﻟـ‬Deprecated‫ﻟوﺻف‬‫اﻟطراﺋﻖ‬Methods‫اﻟﻣﺗﻘﺎدﻣﺔ‬ ‫واﻟﺗﻲ‬‫ﯾﻧﺻﺢ‬‫ﺑﻌدم‬‫اﺳﺗﺧداﻣﮭﺎ‬ ‫ﻣﺛﺎل‬:‫ﻓﻲ‬JFrame‫اﻟطرﯾﻘﺔ‬Show‫ھﻲ‬Deprecated‫ﺣﯾث‬‫ﺗم‬‫اﺳﺗﺑداﻟﮭﺎ‬‫ﺑﺎﻟطرﯾﻘﺔ‬ setVisible ‫س‬٤٤‫اﻟـ‬ ‫ھو‬ ‫ﻣﺎ‬ :Generic class‫؟‬ ‫ھو‬‫ﻛﻼس‬‫ﯾﺗﻌﺎﻣل‬‫ﺑﺷﻛل‬‫ﻋﺎم‬‫وﯾﺣﺗوي‬‫ﻋﻠﻰ‬‫اﻷﻗل‬‫ﻋﻠﻰ‬‫ﻋﻧﺻر‬‫واﺣد‬‫ﻏﯾر‬‫ﻣﺣدد‬‫اﻟﻧوع‬، ‫اﻷوﺑﺟﻛت‬ ‫إﻧﺷﺎء‬ ‫أﺛﻧﺎء‬ ‫ﻓﻲ‬ ‫ﺗﺣدﯾده‬ ‫ﯾﺗم‬.
  34. 34. ٣٤ ‫و‬‫ھو‬‫ﺑﺎﺧﺗﺻﺎر‬‫اﻟﻘدرة‬‫ﻋﻠﻰ‬‫أﻧﻲ‬‫ارﺳل‬‫أو‬‫أﺑﻌث‬Type‫ﻛﺑراﻣﯾﺗر‬،‫وال‬Generic‫اﻗدر‬ ‫اﺳﺗﺧدﻣﮫ‬‫ﻣﻊ‬‫اﻟﻛﻼس‬‫أو‬‫اﻟﻣﯾﺛود‬،‫ﯾﻌﻧﻲ‬‫ﻛﺄﻧﻲ‬‫اﻗوﻟﮫ‬‫أن‬‫اﻟﻣﯾﺛود‬‫اﻟﻠﻲ‬‫اﺳﺗﺧدﻣت‬‫ﻣﻌﮭﺎ‬‫ال‬ Generic‫أﻧﮭﺎ‬‫راح‬‫ﺗﺎﺧذ‬Type‫ﻏﯾر‬‫ﻣﺣدده‬‫ﻓﻲ‬‫وﻗت‬‫إﻧﺷﺎﺋﻲ‬‫ﻟﻠﻛﻼس‬‫أو‬‫اﻟﻣﯾﺛود‬، ‫طﯾب‬‫ﯾﻌﻧﻲ‬‫ﻣﺗﻰ‬‫ﺗﺣدد‬‫ﻟﮫ‬‫اﻟﻘﯾﻣﺔ‬‫؟‬‫راح‬‫ﺗﺣدده‬‫ﻟﮫ‬‫أﻧت‬‫أو‬‫اﻟﻣﺳﺗﺧدم‬‫وھو‬‫ﯾﺳﺗﺧدم‬‫اﻟﻛﻼس‬ ‫أو‬‫اﻟﻣﯾﺛود‬،‫ﻓﻌﺷﺎن‬‫ﻛذا‬‫ھذا‬‫ﯾﻌﺗﺑر‬‫أﻣر‬‫ﻟل‬Compiler‫أﻧﮫ‬‫ّك‬‫ﯾ‬‫ﯾﺷ‬‫ﻋﻠﻰ‬Compiler Time‫ﻋﻠﻰ‬‫اﻟﻘﯾﻣﺔ‬‫أو‬‫ال‬Type‫اﻟﻠﻲ‬‫ﻣرﺳﻠﮫ‬‫ﻟﮫ‬،‫وطﺑﻌﺎ‬‫ھو‬‫ﻗﺳم‬‫ﻛﺑﯾر‬‫ﺟدا‬‫ﺑس‬‫ھذا‬ ‫ﺷرح‬‫ﺑﺳﯾ‬‫ط‬. ‫ﻟﮫ‬ ‫س‬٤٥:‫اﻟـ‬ ‫ھو‬ ‫ﻣﺎ‬Interface‫؟‬ ‫ھو‬‫ﻋﺑﺎرة‬‫ﻋن‬‫ﺷﻲء‬‫ﺷﺑﯾﮫ‬‫ﺑﺎﻟﻛﻼس‬‫اﻟﻌﺎدي‬‫إﻻ‬‫اﻧﮫ‬‫ﻻﯾﺣﺗوي‬‫ﺳوى‬‫ﻋﻠﻰ‬‫ﻣﺗﻐﯾرات‬‫ﺛﺎﺑﺗﺔ‬‫و‬ ‫ﻣﯾﺛودات‬‫ﻣن‬‫ﻧوع‬Abstract‫أي‬‫ﻣﯾﺛود‬‫ھﯾدر‬‫ﻓﻘط‬. *‫اﻻﻧﺗرﻓﯾس‬:‫ﻛﻲ‬‫ﯾﺗم‬‫اﺳﺗﺧداﻣﮫ‬‫ﻻﺑد‬‫ان‬‫ﻧﻌﻣل‬implements‫ﻟﻛﻼس‬‫آﺧر‬. *‫ﻻﯾﻣﻛن‬‫ﺧﻠﻖ‬‫اوﺑﺟﻛت‬‫ﻣن‬‫اﻻﻧﺗرﻓﯾس‬‫ﺑﺎﺳﺗﺧدام‬‫ﻛﻠﻣﺔ‬new. *‫ﯾﺳﺗطﯾﻊ‬‫اﻻﻧﺗرﻓﯾس‬‫ان‬‫ﯾرث‬‫ﻣن‬‫اﻛﺛر‬‫ﻣن‬‫اﻧﺗرﻓﯾس‬‫ﺑﺎﺳﺗﺧدام‬‫ﻛﻠﻣﺔ‬extends. *‫اﻟﻛﻼس‬‫اﻟﻌﺎدي‬‫ﻏﯾر‬‫ﻣﺳﻣوح‬‫ﻟﮫ‬‫ﺑﺎﻟوراﺛﺔ‬‫ﻣن‬‫اﻛﺗر‬‫ﻣن‬‫ﺳوﺑر‬‫ﻛﻼس‬،‫ﻟﻛﻧﮫ‬‫ﯾﻣﻛن‬‫ﻟﮫ‬ implements‫اﻛﺗر‬‫ﻣن‬‫اﻧﺗرﻓﯾس‬. GUI ‫س‬٤٦‫ﻣﺎ‬ :‫ھﻲ‬GUI)‫واﺟﮭﺔ‬‫اﻟﻣﺳﺗﺧدم‬‫اﻟرﺳوﻣﯾﺔ‬(‫ﻓﻲ‬‫اﻟ‬‫ﺟﺎﻓﺎ؟‬ •‫اﻟـ‬ ‫ﻋﻧﺻر‬GUI‫ھو‬‫ﻛﺎﺋن‬‫ﯾﺗﻔﺎﻋل‬‫ﻣﻌﮭﺎ‬‫اﻟﻣﺳﺗﺧدم‬‫ﻋن‬‫طرﯾﻖ‬‫ﻣﺎوس‬‫أو‬‫ﻟوﺣﺔ‬،‫اﻟﻣﻔﺎﺗﯾﺢ‬ ‫أو‬‫أي‬‫ﻧوع‬‫آﺧر‬‫ﻣن‬‫اﻟﻣدﺧﻼت‬.
  35. 35. ٣٥ •‫وﻣن‬‫اﻷﻣﺛﻠﺔ‬‫اﻟﻔﻌﻠﯾﺔ‬‫ﺗﻌﺎﻣﻠﻧﺎ‬ ‫إذا‬‫ﻣﻊ‬‫ﻛﻼس‬JOptionPaneً‫ﻣﺛﻼ‬‫ﻧﺳﺗﺧدم‬ ،‫اﻟ‬‫ﻣﯾﺛود‬ ()showInputDialog‫ﻟﻠﺣﺻول‬‫ﻋﻠﻰ‬‫ﻣدﺧﻼت‬‫ﻣن‬‫اﻟﻣﺳﺗﺧدم‬. ‫س‬٤٧‫ﻣﺎ‬ :‫ھو‬‫ﻋﻣل‬‫اﻟﻣﻛون‬(‫)اﻟﻌﻧﺻر‬JFrame‫؟‬ •JFrame‫ﻣﻛون‬‫ﯾ‬‫وﻓر‬‫اﻟﺑﻧﯾﺔ‬‫اﻟﺗﺣﺗﯾﺔ‬‫ﻟواﺟﮭﺔ‬‫اﻟﻣﺳﺗﺧدم‬‫اﻟرﺳوﻣﯾﺔ‬)GUI. ( •‫ﯾوﻓر‬JFrame‫ﺳﻠوك‬ ‫أو‬ ‫ﺷﻛل‬‫اﻟ‬،‫ﻧﺎﻓذة‬‫ﻓ‬‫ﮭو‬‫ﯾﺣﺗوي‬‫ﻋﻠﻰ‬‫ﺷرﯾط‬‫اﻟ‬،‫ﻌﻧوان‬‫و‬‫أزرار‬ ،‫ﻹﻏﻼق‬‫و‬‫اﻟﺗﻛﺑﯾر‬،‫واﻟﺗﻘﻠﯾل‬‫إﻟﻰ‬‫أدﻧﻰ‬‫ﺣد‬‫ﻣن‬‫اﻟﻧﺎﻓذة‬. ‫س‬٤٨‫ﻣﺎ‬ :‫ھﻲ‬‫طرق‬‫اﻟـ‬ ‫اﺳﺗﺧدام‬JFrame‫؟‬ •‫إﻧﺷﺎء‬object)(‫ﻛﺎﺋن‬‫ﻣن‬‫ﻧوع‬JFrame. •‫اﻟوراﺛﺔ‬extends)(‫ﻣن‬(‫)ﻓﺋﺔ‬ ‫ﻛﻼس‬Jframe. ‫س‬٤٩:‫واﺟﮭﺎت‬ ‫ﻋﻣل‬ ‫ﻛﯾﻔﯾﺔ‬‫اﻟﻛود‬ ‫ﺑﺎﺳﺗﺧدام‬ ‫ﺑﺎﻟﺟﺎﻓﺎ‬ ‫ﻣرﺋﯾﺔ‬‫؟‬ ‫ﻋﻣل‬ ‫ﻛﯾﻔﯾﺔ‬Frame: ‫اﻟرﺋﯾﺳﯾﺔ‬ ‫اﻟداﻟﺔ‬ ‫ﻓﻲ‬ ‫اﻟﻛود‬ ‫طرﯾﻖ‬ ‫ﻋن‬ ‫ﻣﻛﺗﺑﺔ‬ ‫ﻓﻲ‬ ‫ﻣوﺟودة‬ ‫اﻟﻛﺎﺋﻧﺎت‬ ‫ھذه‬ ‫ﻣﻼﺣظﺔ‬swing import javax.swing.*; . ‫اﻟﻣﻛﺗﺑﺔ‬ ‫ﻓﻲ‬ ‫اﻟﻣوﺟودة‬ ‫اﻟﻛﺎﺋﻧﺎت‬ ‫ﻛل‬ ‫ﻹدراج‬ * ‫واﻟـ‬ JFrame Frame2 = new JFrame(); Frame2.setLayout(new FlowLayout()); Frame2.setTitle("‫اﻟﻔﺮﯾﻢ‬ ‫;)"ﻋﻨﻮان‬ Frame2.setSize(300,300); // ‫اﻟﻔﺮﯾﻢ‬ ‫ﺣﺠﻢ‬
  36. 36. ٣٦ Frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Frame2.pack(); Frame2.setVisible(true); // ‫اﻟﻔﺮﯾﻢ‬ ‫إﻇﮭﺎر‬ Frame2.setLocation(200,60); // ‫ﻇﮭﻮر‬ ‫ﻣﻜﺎن‬ ‫ﻟﺘﺤﺪﯾﺪ‬ ‫اﻟﻨﺎﻓﺬة‬ Frame2.setResizable(false); // ‫ﺣﺠﻢ‬ ‫ﺗﻐﯿﯿﺮ‬ ‫ﻟﻤﻨﻊ‬ ‫اﻟﻨﺎﻓﺬة‬ Frame2.setBackground(Color.BLUE); vcvcvcvcvv } : ‫اﻟوارﺛﺔ‬ ‫طرﯾﻖ‬ ‫ﻋن‬ ‫أو‬ public class MainClass extends JFrame { public static void main(String[] args) { new MainClass().setVisible(true); } : ‫ﻟﻠﻧﺎﻓذة‬ ‫ﻟون‬ ‫ﺧﻠﻔﯾﺔ‬ ‫ﻟﻌﻣل‬ Container C = Arabic.getContentPane(); C.setBackground(Color.red); ‫اﻟﺷﺎﺷﺔ‬ ‫ﺣﺟم‬ ‫ﻣﻌرﻓﺔ‬ ‫ﻻﺑد‬ ‫أوﻻ‬ : ‫اﻟﺷﺎﺷﺔ‬ ‫ﻣﻧﺗﺻف‬ ‫ﻓﻲ‬ ‫اﻟﻧﺎﻓذة‬ ‫ﺟﻌل‬ ‫ﻛﯾﻔﯾﺔ‬ // import the libraries import java.awt.Dimension; import java.awt.Toolkit; // Get the size of the screen Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); // Determine the new location of the window int w = Frame2.getSize().width; int h = Frame2.getSize().height; int x = (dim.width-w)/2; int y = (dim.height-h)/2; // Move the window
  37. 37. ٣٧ Frame2.setLocation(x, y); ‫اﻟداﻟﺔ‬ ‫ﻋﻣل‬Pack ()‫ﺑدﻻ‬ ‫اﻟﻔرﯾم‬ ‫ﻋﻠﻰ‬ ‫اﻟﻣوﺟودة‬ ‫اﻟﻣﻛوﻧﺎت‬ ‫ﺣﺟم‬ ‫ﻋﻠﻰ‬ ‫ﺑﻧﺎء‬ ‫ﺗﻠﻘﺎﺋﯾﺎ‬ ‫اﻟﻔرﯾم‬ ‫ﺗﺣﺟﯾم‬ ‫ﺑـ‬ ‫ﺗﻘوم‬ : ‫اﻟداﻟﺔ‬ ‫اﺳﺗﺧدام‬ ‫ﻣن‬ Frame2.setSize(width, height); ‫داﻟﺔ‬ ‫أو‬ ‫اﻟداﻟﺔ‬ ‫ھذه‬ ‫ﻧﺳﺗﺧدم‬ ‫ﻟم‬ ‫إذا‬ ‫ﻷﻧﮫ‬setSize: ‫اﻟﺻورة‬ ‫ﻓﻲ‬ ‫ﻛﻣﺎ‬ ‫اﻟﻔرﯾم‬ ‫ﻋﻧوان‬ ‫ﯾظﮭر‬ ‫ﺳوف‬ ‫ﻓﻘط‬ Example : import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Pack extends JFrame { private Button button1 = new Button("Button 1"); private Button button2 = new Button("Button 2"); private Button button3 = new Button("Button 3"); private Button button4 = new Button("Button 4"); private Button button5 = new Button("Button 5"); public Pack() { super("pack() vs. setSize() method Example"); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Container contentPane = this.getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(button1); contentPane.add(button2);
  38. 38. ٣٨ contentPane.add(button3); contentPane.add(button4); contentPane.add(button5); //this.setSize(450, 90); this.pack(); } public static void main(String[] args) { Pack mainFrame = new Pack(); mainFrame.setVisible(true); } } ‫ﻋﻧوان‬ ‫إﺿﺎﻓﺔ‬JLabel‫ﻟﻠﻔرﯾم‬ JLabel t1 = new JLabel("Any text here"); JLabel t2 = new JLabel(message);// message is a String variable o‫اﻟـ‬ ‫ﻋﻠﻰ‬ ‫اﻟظﺎھر‬ ‫اﻟﻌﻧوان‬ ‫ﺗﻐﯾﯾر‬ ‫ﯾﻣﻛن‬Label‫اﻟداﻟﺔ‬ ‫ﺑﺎﺳﺗﺧدام‬setText() method t1.setText("New Text"); // You can also use variables here o‫اﻟﻌﻧوان‬ ‫ﻓﻲ‬ ‫اﻟﻣوﺟود‬ ‫اﻟﻧص‬ ‫ﻋﻠﻰ‬ ‫اﻟﺣﺻول‬Label: ‫اﻟداﻟﺔ‬ ‫ﺑﺎﺳﺗﺧدام‬ String str = t1.getText(); ‫اﻟـ‬ ‫إﻟﻰ‬ ‫زر‬ ‫إﺿﺎﻓﺔ‬Frame‫اﻟـ‬ ‫ﻣﻊ‬ ‫ﻧﺗﻌﺎﻣل‬Button‫ﻛـ‬Object‫ﻟﮭﺎ‬ ‫إرﺳﺎل‬ ‫ﻣﻊ‬ ‫اﻟﺑﻧﺎء‬ ‫داﻟﺔ‬ ‫واﺳﺗدﻋﺎء‬ ‫اﻟزر‬ ‫ﻋﻠﻰ‬ ‫ﯾظﮭر‬ ‫ﺳوف‬ ‫اﻟذي‬ ‫اﻟﻌﻧوان‬ JButton button = new JButton("Title of Button");
  39. 39. ٣٩ o‫اﻟداﻟﺔ‬ ‫ﻓﻲ‬ ‫اﻟﻌﻧوان‬ ‫إرﺳﺎل‬ ‫أو‬setText(String) button.setText("Title of Button "); o‫اﻟﻌﻧوان‬ ‫ﻓﻲ‬ ‫اﻟﻣوﺟود‬ ‫اﻟﻧص‬ ‫ﻋﻠﻰ‬ ‫اﻟﺣﺻول‬JButton‫ﺑﺎﺳﺗﺧدام‬: ‫اﻟداﻟﺔ‬ String txt = button.getText(); o:‫اﻟداﻟﺔ‬ ‫ﺧﻼل‬ ‫ﻣن‬ ‫ﻟﻠزر‬ ‫ﺗﻠﻣﯾﺢ‬ ‫إﺿﺎﻓﺔ‬ ‫داﻟﺔ‬ b.setToolTipText("click me"); o‫اﻟداﻟﺔ‬ ‫ﺧﻼل‬ ‫ﻣن‬ ‫اﻟﻔرﯾم‬ ‫ﻋرض‬ ‫ﯾﺗم‬ ‫ﻣﺎ‬ ‫ﻗﺑل‬ ‫اﻟﻔرﯾم‬ ‫إﻟﻰ‬ ‫اﻟﻛﺎﺋن‬ ‫ھذا‬ ‫إﺿﺎﻓﺗﮫ‬ ‫ﯾﺗم‬ ‫ﺛم‬ setVisible() Frame2.add(b); ‫ﻧﺻﻲ‬ ‫ﺣﻘل‬ ‫إﺿﺎﻓﺔ‬JTextField‫ﯾﺳﻣﺢ‬‫اﻟﻧص‬ ‫ﻣن‬ ‫واﺣد‬ ‫ﺳطر‬ ‫ﻣن‬ ‫ﻟﻠﺗﺣرﯾر‬ JTextField tf = new JTextField(); // The default constructor JTextField tf2 = new JTextField(25); // Constructs the JTextField of size JTextField tf3 = new JTextField("Hello World", 25); // With size and default text o‫ﯾﻣﻛﻧك‬‫اﺳﺗرﺟﺎﻋﮭﺎ‬ ‫أو‬ ‫ﻧص‬ ‫ﺗﻌﯾﯾن‬‫اﻟداﻟﺔ‬ ‫ﺧﻼل‬ ‫ﻣن‬setText () tf.setText("New Text"); /* or */ tf.setText(txt); o‫إﻟﻰ‬ ‫إﺿﺎﻓﺗﮫ‬ ‫وﯾﻣﻛن‬JFrame frame.add(new JTextField("Hello World", 25)); // or // frame.add(tf); o‫اﻟداﻟﺔ‬ ‫ﺧﻼل‬ ‫ﻣن‬ ‫اﻟﻧﺻﻲ‬ ‫اﻟﺣﻘل‬ ‫ﻓﻲ‬ ‫اﻟﻣوﺟود‬ ‫اﻟﻧص‬ ‫ﻋﻠﻰ‬ ‫ﻟﻠﺣﺻول‬getText ()
  40. 40. ٤٠ String Stext = JTextField1.getText(); ‫ﻗﺎﺋﻣﺔ‬ ‫إﺿﺎﻓﺔ‬combbox‫ﻟﻠﻔرﯾم‬‫ﻋﻧﺎﺻر‬ ‫ﻣﺻﻔوﻓﺔ‬ ‫طرﯾﻖ‬ ‫ﻋن‬ : JComboBox com = new JComboBox(); s = new String []{"sasa","sasfg","dd","aa"}; com.setModel(new javax.swing.DefaultComboBoxModel(s)); Frame2.add(com); o‫ﻧﺻﻲ‬ ‫ﺣﻘل‬ ‫ﻣن‬ ‫ﻟﻠﻘﺎﺋﻣﺔ‬ ‫ﻋﻧﺻر‬ ‫إﺿﺎﻓﺔ‬JTextField‫اﻟداﻟﺔ‬ ‫ﺧﻼل‬ ‫ﻣن‬ JComboBox.addItem(Object item ): tf3 = new JTextField("Hello World", 25); // With size and default text Frame2.add(tf3); com = new JComboBox<Object>(); Frame2.add(com); com.addItem(tf3.getText()); // add to CombBox from JTextField o‫ﻧوع‬ ‫ﻣن‬ ‫ﻣﺗﻐﯾر‬ ‫ﻻن‬ : ‫ﻧﺻﻲ‬ ‫ﻣﺗﻐﯾر‬ ‫ﻣن‬ ‫ﻟﻠﻘﺎﺋﻣﺔ‬ ‫ﻋﻧﺻر‬ ‫إﺿﺎﻓﺔ‬String‫ﯾﻌﺗﺑر‬Object‫ﻣﺎ‬ ‫ﻛل‬ ‫ﻻن‬ ‫ﻋن‬ ‫ﻋﺑﺎرة‬ ‫ھﻲ‬ ‫اﻟﺟﺎﻓﺎ‬ ‫ﻓﻲ‬Objects String comtxt="Add in Combobox"; com.addItem(comtxt); o‫اﻟﻘﺎﺋﻣﺔ‬ ‫ﻟﺟﻌل‬CombBox‫اﻟداﻟﺔ‬ ‫ﺧﻼل‬ ‫ﻣن‬ ‫ﻟﻠﺗﻌدﯾل‬ ‫ﻗﺎﺑﻠﺔ‬setEditable com.setEditable(true); ‫ﻗﺎﺋﻣﺔ‬ ‫إﺿﺎﻓﺔ‬list‫ﻟﻠﻔرﯾم‬ list = new JList(data); //data has type Object[] ‫ﻣﺻﻔوﻓﺔ‬ ‫ﻣن‬ ‫ﻟﮭﺎ‬ ‫ﻗﯾم‬ ‫إﺿﺎﻓﺔ‬ ‫ﻣﻊ‬ String[] ar = {"one", "two", "three"}; JList list = new JList(ar); Frame2.add(list);
  41. 41. ٤١ o‫ﻟﻠـ‬ ‫ﻋﻧﺎﺻر‬ ‫إﺿﺎﻓﺔ‬ ‫ﯾﻣﻛن‬list‫اﻟﻛﻼس‬ ‫ﺧﻼل‬ ‫ﻣن‬ListModel class‫اﻟـ‬ ‫ﺗﻌرﯾف‬ ‫اوﻻ‬ ‫ﻻﺑد‬ DefaultListModel DefaultListModel listModel = new DefaultListModel(); listModel.addElement("item 1"); listModel.addElement("item 2"); o‫اﻟـ‬ ‫اﺳﺗﺧدام‬ ‫وﯾﻣﻛن‬DefaultListModel‫ﻟﻠـ‬ ‫اﻟﺑﻧﺎء‬ ‫داﻟﺔ‬ ‫ﻓﻲ‬list JList list = new JList(listModel); o‫ﺗﻧﻔﯾذ‬ ‫أﺛﻧﺎء‬ ‫وﻗت‬ ‫أي‬ ‫ﻓﻲ‬ ‫إﺿﺎﻓﯾﺔ‬ ‫ﻋﻧﺎﺻر‬ ‫ﻹﺿﺎﻓﺔ‬ ‫اﻵن‬‫ﺑﺎﺳﺗﺧدام‬addElement() method listModel.addElement("new item"); o‫ﻣوﻗﻌﮭﺎ‬ ‫ﺑﺗﺣدﯾد‬ ‫اﻟﻘﺎﺋﻣﺔ‬ ‫ﻓﻲ‬ ‫ﻋﻧﺻر‬ ‫إﺿﺎﻓﺔ‬ ‫ﯾﻣﻛن‬ int index=3; listModel.add(index, object); o‫اﻟـ‬object‫ﻏﯾرة‬ ‫أو‬ ‫ﻧﺻﻲ‬ ‫ﺣﻘل‬ ‫ﻣن‬ ‫ﻗﯾﻣﺔ‬ ‫أو‬ ‫ﻧﺻﻲ‬ ‫ﻣﺗﻐﯾر‬ ‫ﺳواء‬ o‫اﻟـ‬ ‫ﻣن‬ ‫ﻣﻌﯾن‬ ‫ﻋﻧﺻر‬ ‫ﻟﺣذف‬list‫اﻟـ‬ ‫ﺣﯾث‬index‫ﺣذﻓﮫ‬ ‫اﻟﻣراد‬ ‫اﻟﻌﻧﺻر‬ ‫ﻋﻧوان‬ listModel.remove(index); o:‫اﻟﻌﻨﺎﺻﺮ‬ ‫ﻛﻞ‬ ‫ﻟﺤﺬف‬ listModel.clear(); o‫اﻟـ‬ ‫ﻓﻲ‬ ‫اﻟﻣﺣدد‬ ‫اﻟﻌﻧﺻر‬list list.setSelectedItem(n); o‫ﻓﻲ‬ ‫ﺣﺎﻟﯾﺎ‬ ‫اﻟﻣﺣدد‬ ‫ﺳﻠﺳﻠﺔ‬ ‫ﻹرﺟﺎع‬JList‫اﺳﺗﺧدم‬ ، s = (String) list.getSelectedValue(); ‫اﻷﺳﻠوب‬ ‫ھذا‬ ‫وﯾﻌرف‬‫ﯾﻌﯾد‬‫ﻛﺎﺋن‬object‫ﻷن‬JList‫أﻧواع‬ ‫ﻋﻠﻰ‬ ‫ﺗﺣﺗوي‬ ‫أن‬ ‫ﯾﻣﻛن‬ ‫اﻟواﻗﻊ‬ ‫ﻓﻲ‬ ‫اﻟرﻣوز‬ ‫ﺑﺎﺳم‬ ‫ﺗﻌرف‬ ‫اﻟﺻﻐﯾرة‬ ‫اﻟﺻور‬ ،‫اﻟﻣﺛﺎل‬ ‫ﺳﺑﯾل‬ ‫)ﻋﻠﻰ‬ ‫ﺳﻼﺳل‬ ‫ﻣن‬ ‫اﻷﺧرى‬ ‫اﻟﻛﺎﺋﻧﺎت‬ o‫اﻟـ‬ ‫ﻓﻲ‬ ‫اﻟﻣﺗﻌدد‬ ‫ﻟﻠﺗﺣدﯾد‬JList JList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERV AL_SELECTION);
  42. 42. ٤٢ ‫اﻟﺧﺎﺻﯾﺔ‬ ‫ﺣﯾث‬ListSelectionModel: ‫ﻗﯾﻣﺔ‬ ‫ﻣن‬ ‫أﻛﺛر‬ ‫ﻟﮭﺎ‬ - MULTIPLE_INTERVAL_SELECTION //(default select) ‫ﻣﺗﻌدد‬ ‫ﺗﺣدﯾد‬ ‫ﻟﻠﻌﻧﺎﺻر‬ - SINGLE_INTERVAL_SELECTION // ‫ﻓﻘط‬ ‫واﺣد‬ ‫ﺗﺣدﯾد‬ - SINGLE_SELECTION // Create a list that allows adds and removes DefaultListModel model = new DefaultListModel(); JList list = new JList(model); // Initialize the list with items String[] items = {"A", "B", "C", "D"}; for (int i=0; i<items.length; i++) { listModel.add(i, items[i]); } // Append an item int pos = list.getModel().getSize(); listModel.add(pos, "E"); // Insert an item at the beginning pos = 0; listModel.add(pos, "a"); o‫اﻟﻣﺣدد‬ ‫اﻟﻣوﻗﻊ‬ ‫ﻣﺣﺗوى‬ ‫ﻟﺗﻐﯾر‬ pos = 1; // index of item to replace it listModel.set(pos, "b"); o‫اﻟـ‬ ‫ﺣﺳب‬ ‫ﻣﺣدد‬ ‫اﻟﻌﻧﺎﺻر‬ ‫ﻟﺣذف‬index
  43. 43. ٤٣ // Remove the first item pos = 0; // any index of item listModel.remove(pos); o‫اﻟﻘﺎﺋﻣﺔ‬ ‫ﻓﻲ‬ ‫ﻋﻧﺻر‬ ‫أﺧر‬ ‫ﻟﺣذف‬ // Remove the last item pos = listModel.getSize()-1; if (pos >= 0) { listModel.remove(pos); } o‫اﻟـ‬ ‫ﻓﻲ‬ ‫اﻟﻌﻧﺎﺻر‬ ‫ﻛل‬ ‫ﻟﺣذف‬list: // Remove all items listModel.clear(); ‫س‬٥٠‫ﻣﺎ‬ :‫ھﻲ‬‫اﻟـ‬Swing‫؟؟‬ ‫ھﻲ‬‫ﻣﻛﺗﺑﺔ‬‫ﻷدوات‬‫اﻟو‬‫ا‬‫ﺟﮭ‬‫ﺔ‬‫اﻟرﺳوﻣﯾ‬‫ﺔ‬)‫ﻣﺛل‬:‫اﻷزرار‬،‫ﻣرﺑﻌﺎت‬‫اﻟﻧص‬( …‫ﺗﺧﺗﺻر‬ ‫إﻟﻰ‬GUI‫و‬‫ھﻲ‬‫ﻣن‬‫إﻧﺗﺎج‬Sun Microsystems،‫ﺗﻛون‬‫ﻣﺿﻣﻧﮫ‬‫ﻣﻊ‬‫اﻟـ‬Java‫ﺑ‬‫ﺎ‬‫ﺳم‬ Swing. ‫ﺗﺗﻣﯾز‬‫ﺑﺄﻧﮭﺎ‬: .‫ﻣﺗﻌدد‬‫ة‬‫اﻟﻣﻧﺻﺎت‬،‫أي‬‫ﺗﻌﻣل‬‫ﻋﻠﻰ‬‫أي‬‫ﺑﯾﺋﺔ‬‫ﺗﺷﻐﯾل‬ ‫ﻗﺎﺑﻠﮫ‬‫ﻟﻠﺗﻌدﯾل‬ ‫ﻗﺎﺑﻠﯾﮫ‬‫ﻟﻠﺗﺟدﯾد‬ ‫ﺧﻔﯾﻔﺔ‬
  44. 44. ٤٤ ‫س‬٥١:‫ﻣﺎ‬‫ھﻲ‬‫ﻣﻛﺗﺑﺔ‬SWT‫؟‬ ‫ھﻲ‬‫ﻣﻛﺗﺑﮫ‬‫ﻟﻠـ‬GUI‫ﻓﻲ‬‫ﻟﻐﺔ‬‫اﻟـ‬Java،‫وﺗﺳﻣﻰ‬SWT.‫ﺗم‬‫ﺑرﻣﺟﺗﮭﺎ‬‫ﻓﻲ‬‫ﺷرﻛﺔ‬IBM‫و‬ ‫اﻷن‬‫ھﻲ‬‫ﻣﺷروع‬‫ﻣﻔﺗوح‬‫اﻟﻣﺻدر‬،‫ﻣدﻋﻣﮫ‬‫ﻣن‬IBM،‫ﺗﻌﺗﺑر‬‫اﻟـ‬SWT‫ﻣﺛﺎل‬‫ﻟﻸدوات‬ ‫اﻟﺛﻘﯾﻠ‬‫ﺔ‬)Heavyweight، (‫وﺗﺳﻣﺢ‬‫ﺑ‬‫ﺎ‬‫ﺳﺗﻐﻼل‬‫أﺳﺎس‬‫ﻧظﺎم‬‫اﻟﺗﺷﻐﯾل‬‫ﻟﻌﻣل‬‫وﺟﮭﮫ‬ ‫رﺳوﻣﯾﮫ‬GUI،‫وﺗﻘوم‬‫ﺑﺈﻧﺷﺎﺋﮭﺎ‬‫ﺑ‬‫ﺎ‬‫ﺳﺗﺧدام‬‫اﻟو‬‫اﺟﮭﺔ‬‫اﻷﺻﻠﯾ‬‫ﺔ‬‫ﻟﻠـ‬Java،‫ﻣن‬‫ﯾزاﺗﮭﺎ‬َ‫ﻣُﻣ‬ ‫اﻟﺳرﻋ‬‫ﺔ‬‫و‬‫اﻟﺗﺄﺛﯾرات‬‫اﻟﺟﻣﯾﻠ‬‫ﺔ‬‫اﻟﺗﻲ‬‫ُطﻠﻖ‬‫ﯾ‬‫ﻋﻠﯾﮭﺎ‬‫أﺳم‬‫اﻟـ‬Look and Feel،‫و‬‫ﻣن‬ ‫ﺳﻠﺑﯾﺎﺗﮭﺎ‬‫ﻛﺛرة‬‫ا‬‫ﺣﺗﻣﺎﻻت‬‫اﻷﺧطﺎء‬‫ﺑﮭﺎ‬‫و‬‫أﻗل‬‫ﻛﻔﺎءه‬‫ﻣن‬‫اﻟـ‬Swing،‫و‬‫اﻟـ‬SWTً‫ﺗﻣﺎﻣﺎ‬ ‫ﻣﺛل‬‫ﻣﻛﺗﺑﺔ‬Windows Centric. ‫س‬٥٢‫ﻟﻣﺎذا‬ :‫داﺋﻣﺎ‬‫ﯾﻔﺿل‬‫أن‬‫ﺗﻛون‬‫اﻟـ‬method‫داﺧل‬‫اﻟـ‬class‫ﺗﻛون‬static‫؟‬ ‫ﻟﻛ‬‫ﻲ‬‫اﺳﺗطﯾﻊ‬‫ان‬‫اﺳﺗﺧدﻣﮭﺎ‬‫ﺧﺎرج‬‫اﻟﻛﻼس‬‫ﻣن‬‫ﻏﯾر‬‫ان‬‫اﻧﺷﺄ‬‫أ‬‫وﺑﺟﻛت‬‫ﻣن‬‫اﻟﻛﻼس‬‫ﻓﻘط‬ ‫ﺑواﺳطﺔ‬‫اﺳم‬‫اﻟﻛﻼس‬‫واﺳم‬‫اﻟﻔﻧﻛﺷن‬‫ﻣﺛﻼ‬className.method. ‫س‬٥٣:‫ﻟﺪ‬ ‫ﻟﻠﻮاﺟﮭﺎت‬ ‫ﻣﻜﺘﺒﺔ‬ ‫ﻛﻢ‬‫ى‬‫؟‬ ‫اﻟﺠﺎﻓﺎ‬ ‫اﻟﺠﺎﻓﺎ‬ ‫ﻟﺪى‬ ‫ﺣﺎﻟﯿﺎ‬ ‫اﻟﻤﻌﺘﻤﺪ‬ ‫اﻟﻤﻜﺘﺒﺔ‬ swing .1 http://docs.oracle.com/javase/tutorial/uiswing/ swing ‫ھﻲ‬‫اﻧﺘﮭ‬ ‫ﻗﺪﯾﻤﺔ‬ ‫ﻣﻜﺘﺒﺔ‬‫ﻰ‬‫دﻋﻤﮭﺎ‬‫ﻗﺒﻞ‬ ‫ﻣﻦ‬‫ا‬‫ﻟﺠﺎﻓﺎ‬ awt .2 http://docs.oracle.com/javase/6/docs/technotes/guides/awt/ IBM ‫اﻧﺘﺠﺘﮭﺎ‬ ‫اﻟﺘﻲ‬ ‫اﻟﻤﻜﺘﺒﺔ‬ swt .3 http://www.eclipse.org/swt/ ‫اﻟﻮﯾ‬ ‫ﺗﻄﺒﯿﻘﺎت‬ ‫ﻟﺒﻨﺎء‬‫ﺐ‬ googl‫ﺑـ‬ ‫ﺻﺔ‬ ‫ا‬‫ﻟ‬‫اﻟﺨﺎ‬ ‫ﻤﻜﺘﺒﺔ‬ gwt .4 http://www.gwtproject.org/overview.html
  45. 45. ٤٥ . RIA ‫ﻧﻮع‬ ‫ﻣﻦ‬ ‫ﺗﻄﺒﯿﻘﺎت‬ ‫ﻟﺘﻄﻮﯾﺮ‬ ‫ﻣﺎﯾﻜﺮوﺳﯿﺴﺘﻤﺰ‬ ‫ﺻﻦ‬ ‫أﺻﺪرﺗﮭﺎ‬ ‫أﺧﺮى‬ ‫ﺗﻘﻨﯿﺔ‬ javafx UI .5 http://docs.oracle.com/javafx/ qt-jambi ‫وﺗﺴﻤﻲ‬ QT .6 http://qt-jambi.org/ GTK.7 http://java-gnome.sourceforge.net/ ‫س‬٥٤‫ھو‬ ‫ﻣﺎ‬ :‫اﻟﻔرق‬‫ﺑﯾن‬ ‫ﻣﺎ‬orange 1 , orange 2‫؟‬ ‫؟؟؟‬
  46. 46. ٤٦ ‫ﻟو‬‫ﺗﻼﺣظ‬‫ون‬‫ﻓﻲ‬‫اﻟﺻور‬‫ة‬‫أن‬‫داﺧل‬‫ﻛﻼ‬‫اﻟﺛﺎﺑﺗﯾن‬‫ﻓﻲ‬‫ﻛﻼس‬Color‫ﻣﺎ‬‫ﻓﯾﮫ‬‫ﺑﯾﻧﮭم‬‫ﻓرق‬‫إﻻ‬ ‫ﻓﻲ‬‫ﺣﺎﻟﺔ‬‫اﻷﺣرف‬،‫وﻛﺎن‬‫ﻓﻲ‬‫اﻟﺳﺎﺑﻖ‬‫ﻻ‬‫ﯾوﺟد‬‫إﻻ‬‫اﻟﺛﺎﺑت‬lowercase)orange( ‫وﻟﻛن‬‫ﺑﻌد‬JDK 1.4‫ﺗﻣت‬‫اﺿﺎﻓﺔ‬uppercase)ORANGE(،‫ﻟﻛﻲ‬‫ﯾﻧﻔذوا‬‫ﻣﺻطﻠﺢ‬‫أن‬ ‫اﻟﺛواﺑت‬‫داﺋﻣﺎ‬‫ﺗﻛون‬Upper_Case)‫اﺗﻔﺎﻗﯾﺔ‬‫ﺗرﻣﯾز‬‫اﻟﺛواﺑت‬(. ‫س‬٥٥‫ﻛﯾف‬ :‫ﯾﻣﻛن‬‫اﻟﻣﻧﺎداة‬‫ﻋﻠﻰ‬‫اﻟﻣﺗﺻﻔﺢ‬‫اﻹﻓﺗراﺿﻲ‬‫ﻓﺗﺢ‬ ‫و‬‫ﺻﻔﺣﺔ‬‫وﯾب‬‫ﻣﻌﯾﻧﺔ؟‬ ‫اﻟﺟﺎﻓﺎ‬‫وﻣﻧذ‬‫ﻧﺳﺧﺗﮭﺎ‬،‫اﻟﺳﺎدﺳﺔ‬‫ﺗﺗﯾﺢ‬‫إﻣﻛﺎﻧﯾﺔ‬‫اﻟﻣﻧﺎداة‬‫ﻋﻠﻰ‬‫اﻟﻣﺗﺻﻔﺢ‬،‫اﻹﻓﺗراﺿﻲ‬‫وذﻟك‬ ‫ﻋن‬‫طرﯾﻖ‬‫اﻟﻔﺋﺔ‬)class(Desktop‫اﻟﺗﻲ‬‫ﺗوﻓر‬‫ﻟﻧﺎ‬‫اﻟـ‬Method(‫)اﻟطرﯾﻘﺔ‬browse //get a Desktop object Desktop desktop = Desktop.getDesktop();
  47. 47. ٤٧ try { //open the default browser using the method browse which take an URI object representing the web page desktop.browse(new URI("http://arabteam2000-forum.com/")); } catch (URISyntaxException ex) { ex.printStackTrace(); } ‫س‬٥٦‫ﻛﯾف‬ :‫أﺟﻌل‬‫واﺟﮭﺔ‬‫ﺑرﻧﺎﻣﺟﻲ‬‫ﻣﺗﻌددة‬‫اﻟﻠﻐﺎت؟‬ ‫ﻣﺎ‬‫ﻧرﯾده‬‫ھو‬‫إظﮭﺎر‬‫ﻛل‬‫رﺳﺎﺋل‬‫وﻧﺻوص‬‫اﻟواﺟﮭﺔ‬‫ﺣﺳب‬‫اﻟﻠﻐﺔ‬‫اﻟﺗﻲ‬‫ﯾﺗم‬‫اﺧﺗﯾﺎرھﺎ‬.‫إذن‬‫ﻟو‬‫ﻛﻧﺎ‬ ‫ﺳﻧﺟﻌل‬‫ﺛﻼث‬‫ﻟﻐﺎت‬‫ﻣﺗوﻓرة‬‫ﻓﻲ‬،‫اﻟﺑرﻧﺎﻣﺞ‬‫ﻓﺳﯾﻠزﻣﻧﺎ‬‫ﺛﻼث‬‫ﻧﺳﺦ‬‫ﻣن‬‫ﻛل‬‫ﻧص‬،‫ورﺳﺎﻟﺔ‬‫ﻛل‬‫ﻧﺳﺧﺔ‬ ‫ﺑﻠﻐﺔ‬‫ﻣﺧﺗﻠﻔﺔ‬.‫ﺳﻧﺿﻊ‬‫ﻛل‬‫ﻧﺳﺧﺔ‬‫ﻣن‬‫اﻟﻧﺻوص‬‫ﻓﻲ‬‫ﻣﻠف‬properties،‫ﻣﺳﺗﻘل‬‫ﻣﺎ‬‫ﯾﻌﻧﻲ‬‫أن‬ ‫اﻟﺑرﻧﺎﻣﺞ‬‫ﻟن‬‫ﯾﺣﺗوي‬‫ﻋﻠﻰ‬‫أي‬،‫ﻧص‬‫ﺑل‬‫ﻛل‬‫ﺷﻲء‬‫ﺳﯾﻛون‬‫ﻓﻲ‬‫اﻟﻣﻠﻔﺎت‬properties. ‫س‬٥٧‫اﻟﻣﻠﻔﺎت‬ ‫ھﻲ‬ ‫ﻣﺎ‬ :properties‫؟‬ ‫ﻋﻧد‬‫ﻛﺗﺎﺑﺔ‬‫ھذه‬،‫اﻟﻣﻠﻔﺎت‬‫ﯾﺟب‬‫اﺣﺗرام‬‫ﻧﻣوذج‬‫ﻣﺣدد‬:‫أوﻻ‬‫إﺳم‬،‫اﻟﻣﻠف‬‫ﻣﺛﻼ‬"labels"،‫ﻣﺗﺑوﻋﺎ‬ ‫ﺑﺎﻟرﻣز‬"_"،‫ﻣﺗﺑوﻋﺎ‬‫ﺑﺎﻟرﻣز‬‫اﻟﺧﺎص‬،‫ﺑﺎﻟﻠﻐﺔ‬‫ﻣﺛﻼ‬‫رﻣز‬‫اﻟﻌرﺑﯾﺔ‬‫ھو‬"ar"،‫رﻣز‬‫اﻟﻔرﻧﺳﯾﺔ‬"fr" ‫ورﻣز‬‫اﻹﻧﺟﻠﯾزﯾﺔ‬‫ھو‬"en."‫إذن‬‫ﺣﺳب‬‫اﻟﻧﻣوذج‬‫ﻓﺈن‬‫إﺳم‬‫ﻣﻠف‬‫اﻟﻠﻐﺔ‬‫اﻟﻌرﺑﯾﺔ‬‫ﯾﺟب‬‫أن‬‫ﯾﻛون‬ ‫ﻛﺎﻟﺗﺎﻟﻲ‬labels_ar.properties ‫ﻣﺣﺗوى‬‫ھذه‬‫اﻟﻣﻠﻔﺎت‬‫ﯾﻛون‬‫ﻋﻠﻰ‬‫ﺷﻛل‬ key=value key=value
  48. 48. ٤٨ .... ‫ﺑﺣﯾث‬‫أﻧﻧﺎ‬‫ﻧﺳﺗرﺟﻊ‬‫اﻟﻧص‬‫اﻟذي‬‫ﻧرﯾده‬‫ﺑواﺳطﺔ‬key. ‫ﻛﻣﺎ‬‫أﻧﮫ‬‫ﺗﺟدر‬‫اﻹﺷﺎرة‬‫إﻟﻰ‬‫أن‬‫اﻟﻣﻠﻔﺎت‬properties‫ﺗﻘﺑل‬‫ﻓﻘط‬‫اﻟﺗرﻣﯾز‬ISO-8859-1،‫أي‬ ‫اﻟﺣروف‬‫اﻟﻼﺗﯾﻧﯾﺔ‬،‫ﻓﻘط‬‫إذا‬‫أردﻧﺎ‬‫إﺿﺎﻓﺔ‬‫ﺣروف‬،‫ﻋرﺑﯾﺔ‬‫ﯾﺟب‬‫أن‬‫ﻧﻛﺗب‬‫اﻟرﻣز‬unicode ‫اﻟﻣرادف‬‫ﻟﻛل‬‫ﺣرف‬. ‫س‬٥٨‫ﻓﺋﺔ‬ ‫ھﻲ‬ ‫ﻣﺎ‬ :‫اﻟـ‬java.util.Locale‫؟‬ ‫ھذه‬‫اﻟﻔﺋﺔ‬‫ﺗﻣﻛﻧﻧﺎ‬‫ﻣن‬‫ﺗﺣدﯾد‬‫اﻟﻣﻧطﻘﺔ‬‫اﻟﺟﻐراﻓﯾﺔ‬‫أو‬‫اﻟﺛﻘﺎﻓﯾﺔ‬‫اﻟﺗﻲ‬‫ﻧرﯾد‬.‫ﻓﺑﻣﺎ‬‫أﻧﻧﺎ‬‫ﻧرﯾد‬‫أن‬‫ﻧﻐﯾر‬‫ﻟﻐﺔ‬ ‫واﺟﮭﺔ‬،‫ﺑرﻧﺎﻣﺟﻧﺎ‬‫ﻓﯾﻠزﻣﻧﺎ‬‫وﺳﯾﻠﺔ‬‫ﻟﺗﺣدﯾد‬‫ھذه‬،‫اﻟﻠﻐﺔ‬‫وھﻧﺎ‬‫ﺗظﮭر‬‫ﻓﺎﺋدة‬‫اﻟﻔﺋﺔ‬Locale.‫ﻣﺛﻼ‬‫إذا‬‫أردﻧﺎ‬ ‫إﻧﺷﺎء‬Locale‫ﺧﺎص‬،‫ﺑﺎﻟﻌرﺑﯾﺔ‬‫ﻓﺈﻧﻧﺎ‬‫ﻧﻣرر‬‫رﻣز‬‫اﻟﻠﻐﺔ‬‫اﻟﻌرﺑﯾﺔ‬‫ﻟل‬constructor. Locale arLocale = new Locale("ar"); ‫ﻟﻐﺔ‬ ‫ﺑﻜﻞ‬ ‫اﻟﺨﺎص‬ ‫اﻟﺮﻣﺰ‬ ‫ﻟﻤﻌﺮﻓﺔ‬2/php/code_list.php-h p://www.loc.gov/standards/iso639>-- ‫س‬٥٩‫ﻓﺋﺔ‬ ‫ھﻲ‬ ‫ﻣﺎ‬ :‫اﻟـ‬java.util.ResourceBundle‫؟‬ ‫ھذه‬‫اﻟﻔﺋﺔ‬‫ھﻲ‬‫اﻟﺗﻲ‬‫ﺗﻘوم‬‫ﺑﺗﺣﻣﯾل‬‫ﻣﻠف‬‫ال‬properties‫اﻟﺧﺎص‬‫ﺑﺎﻟﻠﻐﺔ‬‫اﻟﺗﻲ‬،‫ﻧﺣددھﺎ‬‫وﺑﺎﻟطﺑﻊ‬‫ﺗﺣدﯾد‬ ‫اﻟﻠﻐﺔ‬‫ﯾﻌﻧﻲ‬‫إﻧﺷﺎء‬‫ﻛﺎﺋن‬Locale‫ﺧﺎص‬‫ﺑﮭﺎﺗﮫ‬‫اﻟﻠﻐﺔ‬.‫ﺑﻌد‬‫ﺗﺣﻣﯾل‬‫اﻟﻣﻠف‬‫ﻓﺈﻧﻧﺎ‬‫ﻧﺳﺗطﯾﻊ‬‫اﻟوﺻول‬‫ﻟﻠﻘﯾم‬ ‫اﻟﻣوﺟودة‬‫ﺑداﺧﻠﮫ‬‫ﻋن‬‫طرﯾﻖ‬getString‫اﻟﺗﻲ‬‫ﻧﻣرر‬‫ﻟﮭﺎ‬‫ﻗﯾﻣﺔ‬‫ال‬key. ‫ﻟﻠﺣﺻول‬‫ﻋﻠﻰ‬‫ﻛﺎﺋن‬ResourceBundle‫ﻓﺈﻧﻧﺎ‬‫ﻧﻧﺎدي‬‫ﻋﻠﻰ‬‫اﻟطرﯾﻘﺔ‬getBundle،‫وﻧﻣرر‬‫ﻟﮭﺎ‬ ‫إﺳم‬‫اﻟﻣﻠف‬properties،‫ﻟﻛن‬‫ﻟﯾس‬‫ﻛل‬،‫اﻹﺳم‬‫ﻟﻛن‬‫ﻓﻘط‬‫اﻟﺟزء‬‫اﻟﻣوﺟود‬‫ﻗﺑل‬،‫اﻟﻠﻐﺔ‬‫ﻣﺛﻼ‬‫إذا‬‫ﻛﺎن‬ ‫ﻟدﯾﻧﺎ‬‫اﻟﻣﻠف‬labels_en.properties،‫ﻓﺈﻧﻧﺎ‬‫ﻧﻣرر‬"labels"‫ﻓﻘط‬‫ﻟﻠطرﯾﻘﺔ‬getBundle.‫ھذه‬ ‫اﻟطرﯾﻘﺔ‬‫ﺗﻧﺗظر‬‫ﻣﻌطﻰ‬،‫آﺧر‬‫وھو‬‫ﻛﺎﺋن‬Locale‫ﯾﻣﺛل‬‫اﻟﻠﻐﺔ‬‫اﻟﺗﻲ‬‫ﻧرﯾد‬‫اﺳﺗﻌﻣﺎﻟﮭﺎ‬.
  49. 49. ٤٩ Locale currentLocale = new Locale("ar"); ResourceBundle myResources = ResourceBundle.getBundle("labels", currentLocale); String someValue = myResources.getString("someKey"); Java I/O ‫س‬٦٠:‫ﻛﯾف‬‫أﻗرأ‬‫ﻣﺣﺗوى‬‫ﻣﻠف‬‫ﻧﺻﻲ‬‫ﺳطرا‬‫ﺑﺳطر‬‫؟‬ ‫ﻟﻘراءة‬‫ﻣﻠف‬‫ﻧﺻﻲ‬‫ﺳطرا‬،‫ﺑﺳطر‬‫ﯾﻣﻛﻧﻧﺎ‬‫اﺳﺗﻌﻣﺎل‬‫اﻟﻔﺋﺔ‬BufferedReader‫أو‬‫اﻟﻔﺋﺔ‬ Scanner: ‫ﺑﺎﺳﺗﻌﻣﺎل‬‫اﻟﻔﺋﺔ‬BufferedReader‫واﻟطرﯾﻘﺔ‬readLine: ‫أوﻻ‬‫ﻧﻧﺷﺊ‬‫ﻛﺎﺋن‬BufferedReader‫وﻧﻣرر‬‫ﻟل‬constructor‫ﻛﺎﺋن‬‫ﻣن‬‫ﻓﺋﺔ‬FileReader‫اﻟذي‬ ‫ﻧﻣرر‬‫ﻟﮫ‬‫ﺑدوره‬‫ﻣﺳﺎر‬‫اﻟﻣﻠف‬‫اﻟذي‬‫ﻧرﯾد‬‫ﻗراءﺗﮫ‬ BufferedReader reader = null; //... reader = new BufferedReader(new FileReader("myfile.txt"));
  50. 50. ٥٠ ‫ﺛم‬‫ﻧﻘوم‬‫داﺧل‬loop‫ﺑﻘراءة‬‫ﺳطر‬‫ﻣن‬‫اﻟﻣﻠف‬‫وﺗﺧزﯾﻧﮫ‬‫ﻓﻲ‬‫ﻣﺗﻐﯾر‬‫ﻣن‬‫ﻓﺋﺔ‬String،‫وﻧﻘوم‬‫ﺑﻌد‬‫ذﻟك‬ ‫ﺑطﺑﺎﻋﺔ‬‫ﻗﯾﻣﺔ‬‫ھذا‬‫اﻟﻣﺗﻐﯾر‬. ‫ال‬loop‫ﺗﺗوﻗف‬‫ﻋﻧدﻣﺎ‬‫ﺗﻌﯾد‬‫اﻟطرﯾﻘﺔ‬readLine()‫اﻟﻘﯾﻣﺔ‬null،‫ﻣﻣﺎ‬‫ﯾﻌﻧﻲ‬‫أﻧﻧﺎ‬‫وﺻﻠﻧﺎ‬‫إﻟﻰ‬‫ﻧﮭﺎﯾﺔ‬ ‫اﻟﻣﻠف‬. String line; while ((line = reader.readLine()) != null) { System.out.println(line); } :‫ﻛﺎﻣﻼ‬ ‫اﻟﻜﻮد‬ BufferedReader reader = null; try { reader = new BufferedReader(new FileReader("myfile.txt")); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (reader != null) { reader.close();
  51. 51. ٥١ } } catch (IOException ex) { System.out.println("Closing stream failed."); } } ‫س‬٦١‫ﻣﺎذا‬ :‫وﺿﻌﻧﺎ‬‫أﻣر‬‫إﻗﻔﺎل‬reader‫داﺧل‬finally‫؟‬‫ﻣﺎذا‬‫ﺳﯾﺣﺻل‬‫ﻟو‬‫وﺿﻌﻧﺎ‬‫أﻣر‬ ‫اﻹﻏﻼق‬‫داﺧل‬‫ال‬try block،‫ﺑﻌد‬‫اﻹﻧﺗﮭﺎء‬‫ﻣن‬‫ال‬loop،‫ﻛﻣﺎ‬‫اﻟﻛود‬‫اﻟﺗﺎﻟﻲ؟‬ //... String line; while ((line = reader.readLine()) != null) { System.out.println(line); } reader.close() //... ‫ﻟﻧﻔﺗرض‬‫ﻣﺛﻼ‬‫أن‬‫اﻟﺑرﻧﺎﻣﺞ‬‫ﻋﻧد‬‫ﺗﻧﻔﯾذ‬‫اﻷﻣر‬readLine‫واﺟﮫ‬‫ﻣﺷﻛﻠﺔ‬‫ﻓﻲ‬‫ﻗراءة‬،‫اﻟﻣﻠف‬‫ﻣﻣﺎ‬‫ﺟﻌﻠﮫ‬ ‫ﯾرﻓﻊ‬IOException،‫ھذا‬‫ﯾﻌﻧﻲ‬‫أﻧﮫ‬‫ﺳﯾﺗﺟﺎھل‬‫ﻛل‬‫اﻟﻛود‬‫اﻟﻣوﺟود‬‫ﺑﻌد‬‫اﻟﺳطر‬‫اﻟذي‬‫رﻓﻊ‬‫اﻹﺳﺗﺛﻧﺎء‬ ‫وﺳﯾﻧﻔذ‬‫ﻣﺑﺎﺷرة‬‫اﻟﻛود‬‫اﻟﻣوﺟود‬‫ﻓﻲ‬catch bloc،‫وﺑﺎﻟﺗﺎﻟﻲ‬‫ﻟن‬‫ﯾﻧﻔذ‬‫أﻣر‬،‫اﻹﻏﻼق‬‫وﺳﯾﺑﻘﻰ‬ ‫ال‬reader،‫ﻣﻔﺗوﺣﺎ‬‫وﺑﺎﻟﺗﺎﻟﻲ‬‫ﻟن‬‫ﯾﺗم‬‫ﺗﺣرﯾر‬‫اﻟذاﻛرة‬‫اﻟﺗﻲ‬‫ﯾﺳﺗﻌﻣﻠﮭﺎ‬. ‫اﻟﺣل‬‫إذن‬‫ھو‬‫وﺿﻊ‬‫إﻣر‬‫اﻹﻏﻼق‬‫داﺧل‬finally bloc،‫ﻷن‬‫اﻟﻛود‬‫اﻟﻣوﺟود‬‫داﺧﻠﮫ‬‫ﯾﺗم‬‫ﺗﻧﻔﯾذه‬،‫داﺋﻣﺎ‬ ‫ﺳواء‬‫ﺗم‬‫رﻓﻊ‬exception‫أو‬‫ﻻ‬.
  52. 52. ٥٢ ‫س‬٦٢‫اﻟﻣﻠف‬ ‫ﻧﻘرأ‬ ‫ﻛﯾف‬ :‫ﺑﺎﺳﺗﻌﻣﺎل‬‫اﻟﻔﺋﺔ‬Scanner‫؟‬ ‫أوﻻ‬‫ﻧﻧﺷﺊ‬‫ﻛﺎﺋن‬Scanner‫وﻧﻣرر‬‫ﻟﮫ‬‫اﻟﻣﻠف‬‫اﻟذي‬‫ﺳﻧﻘرأه‬ Scanner scanner = new Scanner(new File("myfile.txt")); ‫ﺛم‬‫ﻧﻘوم‬‫داﺧل‬loop‫ﺑﻘراءة‬‫اﻟﻣﻠف‬‫ﺳطرا‬‫ﺳطرا‬‫ﺑواﺳطﺔ‬‫اﻟطرﯾﻘﺔ‬nexLine()،‫ﻟﻛن‬‫أوﻻ‬‫ﯾﺟب‬‫أن‬ ‫ﻧﺗﺣﻘﻖ‬‫أﻧﻧﺎ‬‫ﻟم‬‫ﻧﺻل‬‫إﻟﻰ‬‫ﻧﮭﺎﯾﺔ‬‫اﻟﻣﻠف‬. while (scanner.hasNextLine()) { String line = scanner.nextLine(); System.out.println(line); } ‫ﺛم‬‫ﻧﻘﻔل‬‫ال‬scanner scanner.close(); : ‫ﻛﺎﻣﻼ‬ ‫اﻟﻛود‬ Scanner scanner = new Scanner(new File("myfile.txt")); while (scanner.hasNextLine()) { String line = scanner.nextLine(); System.out.println(line); } scanner.close();

×