מה זה תכנות? JVM, JDK, IntelliJ ו-jshellWhat is programming? JVM, JDK, IntelliJ & jshell
איך מחשב מבצע הוראות, איך Java רצה (קוד, javac, bytecode, JVM), התקנת JDK ו-IntelliJ ב-Windows וב-Mac, jshell, והתוכנית הראשונה.
How a computer follows instructions, how Java runs (source, javac, bytecode, the JVM), installing the JDK and IntelliJ on Windows and Mac, jshell, and a first program.
כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-IntelliJ ולסמן פתרתי. ההתקדמות נשמרת.Write in each exercise's editor, press Run to see output and Check for the automatic checker. You can also work in IntelliJ and mark I solved it. Progress is saved.
חימום: 3 שאלותWarm-up: 3 questions
תרגיליםExercises
תרגילExercise 1
מכינים את המחשבSet up your computer
נבדק ידניתSelf-checked
במחשב שלכם: התקינו JDK 21 ובדקו את הגרסאות. צרו על שולחן העבודה תיקייה בשם java-course, צרו בה (בכל עורך) קובץ Hello.java עם תוכנית שמדפיסה Hi, ואז קמפלו והריצו מהטרמינל.
On your own computer: install JDK 21 and check the versions. Create a folder named java-course on the Desktop, create Hello.java in it (in any editor) with a program that prints Hi, then compile and run it from the terminal.
רמזHint 1:ב-Mac פותחים Terminal, וב-Windows פותחים PowerShell. מתחילים ב-cd Desktop.On a Mac open Terminal; on Windows open PowerShell. Start with cd Desktop.
רמזHint 2:mkdir java-course ואחר כך cd java-course.mkdir java-course then cd java-course.
רמזHint 3:שם המחלקה בקובץ חייב להיות Hello, בדיוק כמו שם הקובץ. מריצים java Hello, בלי .class.The class name in the file must be Hello, exactly like the file name. Run java Hello, without .class.
שלום, עולם (בגרסה שלכם)Hello, world (your version)
כתבו תוכנית שמדפיסה שתי שורות: ברכה עם השם שלכם, ומשפט על משהו שאתם אוהבים.
Write a program that prints two lines: a greeting with your name, and a sentence about something you love.
איך הפלט אמור להיראות?What should the output look like?
שלום, אני נועה!
אני אוהבת פיצה וטיולים
Hi, I am Noa!
I love pizza and hiking
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:כל שורת פלט היא System.out.println נפרדת.Each output line is a separate System.out.println.
רמזHint 2:טקסט תמיד בתוך מירכאות כפולות, וכל משפט נגמר ב-;.Text always goes inside double quotes, and each statement ends with ;.
הדפיסו כרטיס ביקור של 5 שורות לפחות: קו עליון, שם, תפקיד (למשל "מפתח/ת Java מתחיל/ה"), אימייל וקו תחתון. הוסיפו הערה אחת עם // שמסבירה מה התוכנית עושה.
Print a business card of at least 5 lines: a top border, a name, a role (e.g. "Beginner Java developer"), an email and a bottom border. Add one //comment explaining what the program does.
איך הפלט אמור להיראות?What should the output look like?
-------------------------
נועה לוי
מפתחת Java מתחילה
noa@example.com
-------------------------
-------------------------
Noa Levi
Beginner Java developer
noa@example.com
-------------------------
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:קו אפשר לצייר עם הרבה מקפים: System.out.println("-------------");.Draw a border with lots of dashes: System.out.println("-------------");.
רמזHint 2:הערה מתחילה ב-// והמהדר מדלג עליה.A comment starts with // and the compiler skips it.
רמזHint 3:רוצים שורה ריקה באמצע? System.out.println();.Want a blank line in the middle? System.out.println();.
ציירו בפלט חתול, בית או רובוט, בעזרת תווים רגילים בלבד. לפחות 5 שורות.
Draw a cat, a house or a robot in the output, using plain characters only. At least 5 lines.
איך הפלט אמור להיראות?What should the output look like?
/\_/\
( o.o )
> ^ <
/ \
(_______)
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:כל שורה של הציור היא println נפרדת.Each line of the drawing is a separate println.
רמזHint 2:רווחים בתוך המירכאות נשמרים, כך שאפשר להזיז חלקים ימינה.Spaces inside the quotes are kept, so you can shift parts across.
רמזHint 3:זהירות: התו \ הוא תו מיוחד במחרוזת. כדי להדפיס אותו כותבים \\ (פעמיים).Careful: \ is special in strings. To print it, write \\ (twice).
הדפיסו, עם כיתוב ברור, כמה שעות יש בשבוע וכמה דקות יש ביממה. Java צריכה לחשב, לא אתם!
Print, with clear labels, how many hours are in a week and how many minutes are in a day. Let Java calculate, not you!
איך הפלט אמור להיראות?What should the output look like?
שעות בשבוע: 168
דקות ביממה: 1440
Hours in a week: 168
Minutes in a day: 1440
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:שעות בשבוע = 7 ימים כפול 24 שעות. כפל ב-Java: *.Hours in a week = 7 days times 24 hours. Multiply in Java: *.
רמזHint 2:כיתוב וחישוב באותה שורה: "כיתוב: " + (7 * 24). הסוגריים מבטיחים שהחישוב יקרה קודם.A label and a calculation on one line: "label: " + (7 * 24). The brackets make the calculation happen first.
בקוד הזה יש 3 באגים. לחצו הרצה, קראו את ההודעות של javac, ותקנו עד שהתוכנית מדפיסה 3 שורות. טיפ: המהדר מראה קודם שגיאות תחביר, ורק אחרי שהן מתוקנות הוא מוצא שמות לא נכונים.
This code has 3 bugs. Press Run, read javac's messages, and fix them until the program prints 3 lines. Tip: the compiler shows syntax errors first, and only after they're fixed does it find wrong names.
איך הפלט אמור להיראות?What should the output look like?
מתחילים!
2 * 21 = 42
סוף
Let's go!
2 * 21 = 42
The end
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:קודם מטפלים בשתי השגיאות ש-javac מראה: ';' expected ו-unclosed string literal.First deal with the two errors javac shows: ';' expected and unclosed string literal.
רמזHint 2:אחרי שתיקנתם, מריצים שוב: מופיעה שגיאה חדשה, cannot find symbol. זה הבאג השלישי.After fixing them, run again: a new error appears, cannot find symbol. That's the third bug.
רמזHint 3:חפשו: אות גדולה במקום הלא נכון, נקודה-פסיק חסרה, ומירכאות חסרות.Look for: a capital letter in the wrong place, a missing semicolon, and a missing quote.
הדפיסו את השורה 1 2 3 GO! בעזרת ארבע פקודות הדפסה: שלוש print ו-println אחת. אחר כך, בשורה נפרדת, הדפיסו done.
Print the line 1 2 3 GO! using four print commands: three print and one println. Then, on a separate line, print done.
איך הפלט אמור להיראות?What should the output look like?
1 2 3 GO!
done
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:print לא יורדת שורה, אז הרווחים צריכים להיות בתוך הטקסט: "1 ".print doesn't move to a new line, so the spaces go inside the text: "1 ".
רמזHint 2:את ה-GO! מדפיסים עם println, ואז done כבר יופיע בשורה חדשה.Print GO! with println, and then done lands on a new line.
מדף, צעד 1: באנר וספר ראשוןShelf, step 1: banner and first book
פרויקט מלווהCompanion project
מתחילים את הפרויקט המלווה, מדף: ספרייה אישית. הדפיסו באנר פתיחה בין שני קווים, ואחריו ספר אחד בשורה בפורמט שם הספר - סופר (שנה). את השנה כתבו כמספר, ובשורה האחרונה הדפיסו כמה שנים עברו מאז שהספר יצא, כש-Java מחשבת (השתמשו ב-2026).
Start the companion project, Shelf: a personal library. Print a welcome banner between two lines, then one book on a line in the format Title - Author (Year). Write the year as a number, and on the last line print how many years have passed since the book came out, with Java doing the maths (use 2026).
איך הפלט אמור להיראות?What should the output look like?
==============================
מדף: הספרייה האישית שלי
==============================
הנסיך הקטן - Antoine de Saint-Exupéry (1943)
שנים מאז שיצא: 83
==============================
Shelf: my personal library
==============================
The Little Prince - Antoine de Saint-Exupéry (1943)
Years since it came out: 83
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:הבאנר: שלוש שורות println.The banner: three println lines.
רמזHint 2:טקסט + מספר + טקסט: "(" + 1943 + ")".Text + number + text: "(" + 1943 + ")".
רמזHint 3:כמה שנים עברו: (2026 - 1943) בסוגריים, כדי שיחושב לפני ההדבקה.Years since: (2026 - 1943) in brackets, so it's calculated before gluing.
מרתון של סרטים נמשך 100000 שניות. בלי לחשב בראש, הדפיסו בשורה אחת כמה ימים, שעות, דקות ושניות זה, למשל 1 days, 3 hours, 46 minutes, 40 seconds. השתמשו רק ב-/ וב-% של מספרים שלמים.
A movie marathon lasts 100000 seconds. Without doing the maths yourself, print on one line how many days, hours, minutes and seconds that is, e.g. 1 days, 3 hours, 46 minutes, 40 seconds. Use only whole-number / and %.
איך הפלט אמור להיראות?What should the output look like?
1 ימים, 3 שעות, 46 דקות, 40 שניות
1 days, 3 hours, 46 minutes, 40 seconds
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:ביום יש 24 * 60 * 60 שניות. 100000 / 86400 נותן ימים שלמים.A day has 24 * 60 * 60 seconds. 100000 / 86400 gives whole days.
רמזHint 2:% נותן את מה שנשאר: 100000 % 86400 הן השניות שלא נכנסו ליום שלם. ממשיכים משם לשעות.% gives what's left: 100000 % 86400 is the seconds that didn't fit into a whole day. Go on from there to hours.
הדפיסו 5 שורות: 1 * 1, 11 * 11, 111 * 111 וכן הלאה עד 11111 * 11111 (רק Java מחשבת!). מה מיוחד בתוצאות? כתבו את התשובה בהערה בסוף הקוד.
Print 5 lines: 1 * 1, 11 * 11, 111 * 111 and so on up to 11111 * 11111 (Java does the maths!). What's special about the results? Write the answer in a comment at the end of the code.
איך הפלט אמור להיראות?What should the output look like?
1
121
12321
1234321
123454321
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:כל שורה היא println של כפל אחד.Each line is a println of one multiplication.
רמזHint 2:הסתכלו על הספרות של כל תוצאה: הן עולות ואז יורדות.Look at each result's digits: they go up and then down.