المتغيرات وأنواع البيانات
في هذه الصفحة 8 موضوعات
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
نظرة عامة
الموضوعات
- الأنواع الأولية (Primitives)
- الأنواع المرجعية
- المتغيرات
- القيم الحرفية (literals)
- الثوابت
- اصطلاحات التسمية
- تحويل الأنواع
تعلّم أولًا
83 دقيقة قراءة · 4 ساعة تدريب (تقدير)
مخرجات التعلم
- Declare and initialize variables of each primitive type and of
String, choosing an appropriate type for given data. - Explain the difference between primitive and reference types at a conceptual level.
- Apply Java naming conventions and use
finalfor constants. - Perform widening and narrowing conversions and predict data loss, including integer overflow.
- Use
varfor local variables where the type is obvious.
الدروس
- 01المتغيرات كصناديق عليها ملصقات12 د قراءة
- 02الأنواع الأولية الثمانية12 د قراءة
- 03النصوص (Strings) والأنواع المرجعية12 د قراءة
- 04القيم الحرفية والثوابت والتسمية11 د قراءة
- 05تحويل الأنواع والتحويل القسري (casting)12 د قراءة
- 06استنتاج النوع المحلي باستخدام var12 د قراءة
- 07عرض عملي: محوّل وحدات وتجاوز سعة العدد الصحيح12 د قراءة
المختبر والتمارين
Lab
BEG-009-LAB1 · Unit converter (fixed values)
Outcomes: 1–5 · Time: ~2 h Convert hard-coded temperatures, distances, and currencies and print the results with the correct types. Include one deliberate overflow and explain it in a comment. Acceptance: correct output; the overflow is explained.
Exercises (assessment: six exercises plus the type-selection quiz)
| ID | Outcome | Task |
|---|---|---|
| BEG-009-EX01 | 1 | Declare one variable of each type for: age, price in cents, temperature, first initial, is-student, full name. |
| BEG-009-EX02 | 2 | Explain in two sentences the difference between int and String in how they hold data. |
| BEG-009-EX03 | 3 | Rename these to Java style: Total_Price, maxspeed, a constant for 3.14159. |
| BEG-009-EX04 | 4 | Predict, then run: 7 / 2, 7 / 2.0, (int) 9.99, (double) 7 / 2. |
| BEG-009-EX05 | 4 | Predict the result of Integer.MAX_VALUE + 1, then run it and explain. |
| BEG-009-EX06 | 5 | Rewrite three declarations with var where the type is obvious; leave one that should not use it. |
أظهر الحلول
- EX01
int age;int priceCents;double temperature;char initial;boolean isStudent;String fullName. - EX02
intholds the value directly;Stringholds a reference to a text object elsewhere. - EX03
totalPrice,maxSpeed,final double PI = 3.14159;. - EX04
3,3.5,9,3.5. - EX05
-2147483648: the value wraps past the maximum ofint. - EX06 For example
var count = 10;andvar name = "Ana";; avoidvar x = compute();.
الاختبار
Outcomes: O1 declare · O2 primitive vs reference · O3 naming and final · O4 conversion · O5 var.
اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.
الجزء العملي
Six exercises BEG-009-EX01 to EX06 plus the lab. Pass: at least five exercises correct and the overflow explained.
أخطاء شائعة
int division where decimals were expected; using double for money; == on strings (flagged here, explained in BEG-026).
التقييم
6 exercises plus a quiz on type selection.
الصلة بالمسار الوظيفي
Type choice for money returns in JNR-028 (BigDecimal/numeric) and data modeling.