מה זה תכנות? JVM, JDK, IntelliJ ו-jshellWhat is programming? JVM, JDK, IntelliJ & jshell
מפגש 1: איך מחשב מבצע הוראות, איך Java רצה (קוד, javac, bytecode, JVM), התקנת JDK ו-IntelliJ ב-Windows וב-Mac, jshell, והתוכנית הראשונה.Session 1: 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.
המפגש הראשון הוא "יום ההתארגנות": מבינים מה זה תכנות ואיך Java רצה (קוד, מהדר, bytecode ו-JVM), מתקינים JDK ו-IntelliJ, כותבים ומריצים את התוכנית הראשונה, ומנסים שורות ב-jshell. אם משהו לא עובד בהתקנה, זה קורה לכולם: בשביל זה יש מדריך טכני.The first session is "setup day": we understand what programming is and how Java runs (source, compiler, bytecode and the JVM), install a JDK and IntelliJ, write and run the first program, and try lines in jshell. If something breaks during setup, it happens to everyone: that's what the tech guide is for.
מה נעשה היוםToday's plan
מה זה תכנותWhat programming is
למה JavaWhy Java
javac, bytecode ו-JVMjavac, bytecode, JVM
התקנת JDKInstalling the JDK
IntelliJIntelliJ
מבנה תוכניתProgram shape
עוברים על סדר היום ומזכירים את הפרויקט המלווה.Walk through the plan and mention the companion project.
נושאTopic 1
מה זה תכנותWhat programming is
מה זה תכנות?What is programming?
תוכנית היא רשימת הוראות שהמחשב מבצע לפי הסדרA program is a list of instructions the computer carries out in order
המחשב לא מנחש: הוא עושה בדיוק מה שכתובThe computer never guesses: it does exactly what's written
מחשב הוא מכונה מהירה מאוד, אבל הוא לא מנחש. הוא עושה בדיוק מה שאומרים לו, ורק את זה. תוכנית היא רשימת הוראות שהמחשב מבצע לפי הסדר, ותכנות הוא כתיבת ההוראות האלה בשפה שהמחשב יודע לבצע.A computer is a very fast machine, but it never guesses. It does exactly what it's told, and only that. A program is a list of instructions the computer carries out in order, and programming is writing those instructions in a language the computer can run.
אנלוגיהAnalogy
תחשבו על רובוט-שף שמקבל מתכון. הוא יבצע "שבור 2 ביצים" בדיוק, צעד אחרי צעד. אבל אם כתבתם "שבור 2 ביצם", הוא לא ינחש שהתכוונתם לביצים. הוא יעצור ויגיד "לא הבנתי". ככה בדיוק מתנהגת Java: מדויקת, צייתנית, ובלי דמיון.Think of a robot chef following a recipe. It will "crack 2 eggs" exactly, step by step. But if you wrote "crack 2 egs", it won't guess you meant eggs. It stops and says "I didn't understand". Java behaves exactly like that: precise, obedient, and with zero imagination.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
טעות נפוצהCommon mistake
Main.java · main
System.out.Println("שלום");
System.out.Println("Hello");
מה javac עונהWhat javac says
Main.java:3: error: cannot find symbol
cannot find symbol אומרת "אני לא מכירה את השם הזה". השורה symbol: method Println(String) מראה בדיוק איזה שם: אין מתודה Println. מתקנים ל-println עם p קטנה.cannot find symbol means "I don't know this name". The line symbol: method Println(String) shows exactly which name: there's no method Println. Fix it to lowercase println.
כותבים Println עם P גדולה. לבני אדם זה אותו דבר, אבל ל-Java אלה שתי מילים שונות לגמרי.Writing Println with a capital P. To a person it's the same, but to Java they're two completely different words.
נושאTopic 2
למה JavaWhy Java
למה דווקא Java?Why Java?
Java רצה בשרתים, ב-Android, בבנקים, במערכות נתונים ובמשחקיםJava runs servers, Android, banks, data systems and games
ה-מהדר בודק את הקוד לפני שהוא רץ, ותופס הרבה טעויות מוקדםThe compiler checks the code before it runs, and catches many mistakes early
מה שבמירכאות הוא טקסט (מחרוזת); מה שבלי מירכאות, Java מחשבתWhat's in quotes is text (a string); without quotes, Java calculates
יש מאות שפות תכנות. Java היא אחת הוותיקות והנפוצות בעולם: היא מריצה שרתים של חברות ענק, אפליקציות Android, מערכות בנקאיות, כלי ביג-דאטה, וגם את Minecraft במחשב. מי שיודע Java טוב מוצא עבודה כמעט בכל מקום.There are hundreds of programming languages. Java is one of the oldest and most widely used: it runs servers at huge companies, Android apps, banking systems, big-data tools, and also Minecraft on the computer. Someone who knows Java well finds work almost anywhere.
מריצים ומשווים לניחושים.Run it and compare with the guesses.
אנלוגיהAnalogy
המהדר של Java הוא כמו מורה קפדנית שבודקת את שיעורי הבית לפני השיעור: היא לא תיתן לכם להגיש עבודה עם מילה חסרה. זה מתסכל בהתחלה, אבל זה חוסך הרבה הפתעות כשהתוכנה כבר עובדת אצל אנשים אמיתיים.Java's compiler is like a strict teacher who checks your homework before class: she won't let you hand in work with a missing word. It's frustrating at first, but it saves a lot of surprises once the software is running for real people.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
טעות נפוצהCommon mistake
Main.java · main
System.out.println(2+);
מה javac עונהWhat javac says
Main.java:3: error: illegal start of expression
illegal start of expression היא שגיאת קומפילציה: השורה לא כתובה לפי חוקי ה-תחביר. ה-^ מצביע בערך למקום שבו המהדר הסתבך. משלימים: System.out.println(2 + 3);.illegal start of expression is a compile error: the line doesn't follow the syntax rules. The ^ points roughly to where the compiler got confused. Complete it: System.out.println(2 + 3);.
משאירים חישוב באמצע. אחרי ה-+ חסר משהו, ולכן המהדר לא מבין את השורה בכלל, ושום דבר לא רץ.Leaving a calculation half-written. Something is missing after the +, so the compiler can't understand the line at all, and nothing runs.
נושאTopic 3
javac, bytecode ו-JVMjavac, bytecode, JVM
איך Java רצה: javac, bytecode ו-JVMHow Java runs: javac, bytecode and the JVM
שני שלבים: javac Main.java מקמפל, java Main מריץTwo steps: javac Main.java compiles, java Main runs
אותו bytecode רץ בכל מחשב שיש בו JVMThe same bytecode runs on any computer with a JVM
את הקוד של Java המחשב לא מריץ ישירות. יש שני שלבים: קודם המהדרjavac קורא את כל הקוד, בודק שהוא תקין, ומתרגם אותו ל-bytecode: שפה פשוטה שנשמרת בקובץ .class. אחר כך הפקודה java מפעילה את ה-JVM, "מחשב וירטואלי" שמבצע את ה-bytecode, שורה אחרי שורה, החל מ-main.The computer doesn't run Java code directly. There are two steps: first the compilerjavac reads all the code, checks it, and translates it into bytecode: a simple language stored in a .class file. Then the java command starts the JVM, a "virtual computer" that runs the bytecode step by step, starting at main.
אנלוגיהAnalogy
דמיינו מתכון שכתוב בעברית. המהדר מתרגם אותו פעם אחת ל"שפת הרובוטים" (bytecode). בכל מטבח בעולם יש רובוט שמדבר את השפה הזו (JVM): אחד ל-Windows, אחד ל-Mac, אחד ל-Linux ואפילו אחד לדפדפן. לכן את אותו מתכון מתורגם אפשר לתת לכל מטבח. בעולם של Java קוראים לזה "כותבים פעם אחת, רץ בכל מקום".Picture a recipe written in English. The compiler translates it once into "robot language" (bytecode). Every kitchen in the world has a robot that speaks that language (a JVM): one for Windows, one for Mac, one for Linux and even one for the browser. So the same translated recipe can go to any kitchen. In the Java world this is called "write once, run anywhere".
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
נושאTopic 4
התקנת JDKInstalling the JDK
התקנת JDK 21 (Windows ו-Mac)Installing JDK 21 (Windows and Mac)
מתקינים JDK 21 (LTS), למשל Eclipse Temurin מ-adoptium.netInstall JDK 21 (LTS), for example Eclipse Temurin from adoptium.net
בודקים בטרמינל: java --version וגם javac --versionCheck in the terminal: java --version and also javac --version
ב-Windows מסמנים בהתקנה Set JAVA_HOME ו-Add to PATHOn Windows tick Set JAVA_HOME and Add to PATH during setup
כדי לכתוב Java מתקינים JDK (Java Development Kit): הוא כולל את ה-JVM, את המהדר javac, את jshell ועוד כלים. בקורס משתמשים ב-Java 21, גרסת LTS שמקבלת עדכונים במשך שנים. מומלץ להוריד את Eclipse Temurin מהאתר adoptium.net: חינמי, רשמי ופתוח.To write Java you install a JDK (Java Development Kit): it includes the JVM, the javac compiler, jshell and more tools. The course uses Java 21, an LTS version that gets updates for years. We recommend Eclipse Temurin from adoptium.net: free, official and open.
נושאTopic 5
IntelliJIntelliJ
IntelliJ IDEA והתוכנית הראשונהIntelliJ IDEA and the first program
קיצורים: psvm ואז Tab כותב את main, ו-sout ואז Tab כותב System.out.println()Shortcuts: psvm then Tab writes main, and sout then Tab writes System.out.println()
שם הקובץ חייב להיות זהה לשם המחלקה הציבוריתThe file name must match the public class name
אפשר לכתוב Java בכל עורך טקסט ולהריץ מהטרמינל, אבל רוב המתכנתים עובדים ב-סביבת פיתוח. בקורס משתמשים ב-IntelliJ IDEACommunity: חינמית, מסמנת טעויות עוד לפני שמריצים, משלימה קוד, ומריצה בלחיצה. (מעדיפים VS Code? גם אפשר, עם Extension Pack for Java. ההוראות במדריך הטכני.)You can write Java in any text editor and run it from the terminal, but most programmers work in an IDE. The course uses IntelliJ IDEACommunity: free, it marks mistakes before you run, completes code, and runs with one click. (Prefer VS Code? That works too, with the Extension Pack for Java. Instructions in the tech guide.)
שאלה לכיתהQuestion for the class
מה ידפיס הקוד?What will this print?
main
System.out.println("שלום מ-IntelliJ");
System.out.println("Hello from IntelliJ");
נותנים לכיתה חצי דקה לנחש, ואז עוברים לשקופית הבאה. (זה הגוף של main.)Give the class half a minute to guess, then move on. (This is the body of main.)
IntelliJIntelliJ
Main.java · main
System.out.println("שלום מ-IntelliJ");
System.out.println("Hello from IntelliJ");
פלטOutput
שלום מ-IntelliJ
Hello from IntelliJ
מריצים ומשווים לניחושים.Run it and compare with the guesses.
אנלוגיהAnalogy
עורך טקסט רגיל הוא כמו מחברת ועט. IntelliJ הוא כמו סדנה מסודרת: יש בה מחברת, אבל גם מורה שמסמנת טעויות בזמן הכתיבה, מכונה שמשלימה מילים, וכפתור אחד שמקמפל ומריץ. מאחורי הכפתור הירוק IntelliJ מריץ בדיוק את מה שראינו: javac ואחריו java.A plain text editor is like a notebook and a pen. IntelliJ is like a well-equipped workshop: there's a notebook, but also a teacher who marks mistakes as you write, a machine that finishes words, and one button that compiles and runs. Behind the green button IntelliJ runs exactly what we saw: javac, then java.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
טעות נפוצהCommon mistake
Main.java · main
System.out.println("Hi");
מה javac עונהWhat javac says
Main.java:1: error: class Hello is public, should be declared in a file named Hello.java
class Hello is public, should be declared in a file named Hello.java: המהדר מבקש להתאים. משנים את שם הקובץ ל-Hello.java (ב-IntelliJ: קליק ימני ← Refactor ← Rename), או את שם המחלקה ל-Main.class Hello is public, should be declared in a file named Hello.java: the compiler wants them to match. Rename the file to Hello.java (in IntelliJ: right-click → Refactor → Rename), or rename the class to Main.
שם המחלקה לא תואם לשם הקובץ: בקובץ Main.java כתוב public class Hello. ב-Java מחלקה ציבורית חייבת לגור בקובץ עם אותו שם בדיוק.The class name doesn't match the file name: the file Main.java says public class Hello. In Java a public class must live in a file with exactly the same name.
בלוק נפתח ב-{ ונסגר ב-}; כל משפט נגמר ב-;A block opens with { and closes with }; every statement ends with ;
הערה: // עד סוף השורה, או בין /* ל-*/A comment: // to the end of the line, or between /* and */
עכשיו נפרק את התוכנית לחלקים. בכל תוכנית Java יש לפחות מחלקה אחת, ובתוכה מתודה בשם main. כשמריצים, ה-JVM נכנסת ל-main ומבצעת את המשפטים שבה מלמעלה למטה. כל משפט נגמר בנקודה-פסיק;, וכל בלוק נפתח ב-{ ונסגר ב-}.Now let's take the program apart. Every Java program has at least one class, and inside it a method called main. When you run it, the JVM goes into main and runs its statements top to bottom. Each statement ends with a semicolon;, and each block opens with { and closes with }.
// This program prints a small cardSystem.out.println("+----------+");
System.out.println("| Java 21 |");
System.out.println("+----------+");
System.out.println(7*6);
נותנים לכיתה חצי דקה לנחש, ואז עוברים לשקופית הבאה. (זה הגוף של main.)Give the class half a minute to guess, then move on. (This is the body of main.)
// This program prints a small cardSystem.out.println("+----------+");
System.out.println("| Java 21 |");
System.out.println("+----------+");
System.out.println(7*6);
פלטOutput
+----------+
| Java 21 |
+----------+
42
+----------+
| Java 21 |
+----------+
42
מריצים ומשווים לניחושים.Run it and compare with the guesses.
אנלוגיהAnalogy
תחשבו על בובות מטריושקה: המחלקה היא הבובה הגדולה, main היא הבובה שבתוכה, והמשפטים הם מה שבפנים. כל { פותח בובה וכל } סוגר אותה, ולכן הם תמיד באים בזוגות.Think of Russian nesting dolls: the class is the big doll, main is the doll inside it, and the statements are what's inside that. Each { opens a doll and each } closes it, so they always come in pairs.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
';' expected אומרת "ציפיתי לנקודה-פסיק". ה-^ מצביע לסוף השורה שבה היא חסרה. מוסיפים ;. שימו לב: התוכנית לא הדפיסה אפילו את השורה השנייה, כי עם שגיאת קומפילציה שום דבר לא רץ.';' expected means "I expected a semicolon". The ^ points at the end of the line where it's missing. Add the ;. Notice: the program didn't print even the second line, because with a compile error nothing runs.
שוכחים נקודה-פסיק בסוף משפט. לבני אדם זה פרט קטן, אבל למהדר זה כמו משפט בלי נקודה: הוא לא יודע איפה המשפט נגמר.Forgetting the semicolon at the end of a statement. For people it's a small detail, but to the compiler it's like a sentence with no full stop: it doesn't know where the statement ends.
נושאTopic 7
הדפסה וחשבוןPrinting and maths
println, print ו-printfprintln, print and printf
println מדפיסה ויורדת שורה; print נשארת באותה שורהprintln prints and goes to a new line; print stays on the same line
+ בין טקסט למספר מחבר טקסט; סוגריים מחשבים קודם+ between text and a number joins text; brackets calculate first
7 / 2 הוא 3 (חלוקה של שלמים), 7 / 2.0 הוא 3.5, ו-7 % 2 הוא 17 / 2 is 3 (integer division), 7 / 2.0 is 3.5, and 7 % 2 is 1
System.out.println מציגה ערך ואז יורדת שורה. האחות שלה, System.out.print, מציגה בלי לרדת שורה, כך שההדפסה הבאה ממשיכה באותה שורה. ו-println() ריקה מדפיסה שורה ריקה.System.out.println shows a value and then moves to a new line. Its sister, System.out.print, shows it without a new line, so the next print continues on the same line. An empty println() prints a blank line.
שאלה לכיתהQuestion for the class
מה ידפיס הקוד?What will this print?
main
System.out.print("אחת, ");
System.out.print("שתיים, ");
System.out.println("שלוש!");
System.out.println();
System.out.println("אחרי שורה ריקה");
System.out.print("One, ");
System.out.print("two, ");
System.out.println("three!");
System.out.println();
System.out.println("After a blank line");
נותנים לכיתה חצי דקה לנחש, ואז עוברים לשקופית הבאה. (זה הגוף של main.)Give the class half a minute to guess, then move on. (This is the body of main.)
הדפסה וחשבוןPrinting and maths
Main.java · main
System.out.print("אחת, ");
System.out.print("שתיים, ");
System.out.println("שלוש!");
System.out.println();
System.out.println("אחרי שורה ריקה");
System.out.print("One, ");
System.out.print("two, ");
System.out.println("three!");
System.out.println();
System.out.println("After a blank line");
פלטOutput
אחת, שתיים, שלוש!
אחרי שורה ריקה
One, two, three!
After a blank line
מריצים ומשווים לניחושים.Run it and compare with the guesses.
אנלוגיהAnalogy
println היא כמו מכונת כתיבה שאחרי כל משפט מחזירה את הגלגלת לשורה חדשה. print כותבת ומשאירה את הגלגלת בדיוק איפה שעצרה.println is like a typewriter that returns the carriage to a new line after each sentence. print types and leaves the carriage exactly where it stopped.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
טעות נפוצהCommon mistake
Main.java · main
System.out.println(Hello);
מה javac עונהWhat javac says
Main.java:3: error: cannot find symbol
cannot find symbol עם symbol: variable Hello: המהדר חיפש משתנה בשם Hello ולא מצא. טקסט תמיד בין מירכאות כפולות: "Hello".cannot find symbol with symbol: variable Hello: the compiler looked for a variable named Hello and found none. Text always goes between double quotes: "Hello".
שוכחים מירכאות סביב טקסט. בלי מירכאות, המהדר חושב ש-Hello הוא שם של משתנה, ומחפש אותו.Forgetting the quotes around text. Without quotes, the compiler thinks Hello is the name of a variable, and looks for it.
נושאTopic 8
jshelljshell
jshell: לנסות שורה אחתjshell: try one line
jshell מריץ שורת Java מיד, בלי class ובלי mainjshell runs a line of Java at once, with no class and no main
תוצאה בלי שם נשמרת ב-$1, $2 וכן הלאהA result with no name is kept in $1, $2 and so on
יוצאים עם /exitLeave with /exit
לפעמים רוצים רק לבדוק משהו קטן: כמה זה 7 / 2? מה עושה "Java".length()? בשביל זה ה-JDK מגיע עם jshell. כותבים בטרמינל jshell, ואז כל שורה רצה מיד, בלי מחלקה, בלי main, ואפילו בלי נקודה-פסיק בסוף. זה לא מחליף תוכנית אמיתית, אבל זה מקום מצוין לנסות.Sometimes you just want to check something small: what's 7 / 2? What does "Java".length() do? For that the JDK comes with jshell. Type jshell in the terminal, and every line runs at once, with no class, no main, not even a semicolon at the end. It does not replace a real program, but it's a great place to try things.
אנלוגיהAnalogy
jshell הוא כמו דף טיוטה ליד המחברת: מנסים עליו תרגיל קטן, רואים מה יוצא, ואז כותבים את התשובה המסודרת במחברת (בתוכנית אמיתית).jshell is like scratch paper next to your notebook: try a small sum on it, see what comes out, then write the neat answer in the notebook (a real program).
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
טעות נפוצהCommon mistake
Main.java
publicclass Main {
System.out.println("Hi");
}
מה javac עונהWhat javac says
Main.java:2: error: <identifier> expected
<identifier> expected: בתוך מחלקה המהדר מצפה להגדרות (מתודות ושדות), לא למשפטים. מכניסים את השורה לתוך public static void main(String[] args) { ... }.<identifier> expected: inside a class the compiler expects definitions (methods and fields), not statements. Put the line inside public static void main(String[] args) { ... }.
כותבים משפט ישר בתוך המחלקה, כמו ב-jshell, בלי main. בקובץ אמיתי משפטים חייבים לגור בתוך מתודה.Writing a statement straight inside the class, like in jshell, with no main. In a real file, statements must live inside a method.
נושאTopic 9
שני סוגי שגיאותTwo kinds of errors
שני סוגי שגיאות: קומפילציה וזמן ריצהTwo kinds of errors: compile time and run time
חריגה: התוכנית התחילה לרוץ ונעצרה באמצעAn exception: the program started running and stopped halfway
קוראים את השורה הראשונה (מה קרה) ואת at ...(Main.java:N) (איפה)Read the first line (what happened) and at ...(Main.java:N) (where)
ב-Java יש שני סוגים עיקריים של שגיאות, וחשוב לדעת להבדיל ביניהם. שגיאת קומפילציה נמצאת על ידי javacלפני שהתוכנית רצה: שום שורה לא מתבצעת עד שמתקנים. חריגה קורית בזמן ריצה: הקוד תקין מבחינת התחביר, התוכנית מתחילה לרוץ, ובשורה מסוימת משהו בלתי אפשרי קורה.Java has two main kinds of errors, and it's important to tell them apart. A compile error is found by javacbefore the program runs: not a single line runs until it's fixed. An exception happens at run time: the syntax is fine, the program starts running, and on some line something impossible happens.
אנלוגיהAnalogy
שגיאת קומפילציה היא כמו בדיקת איות לפני ששולחים מכתב: המכתב לא יוצא עד שמתקנים. חריגה היא כמו רכב שיצא לדרך ונתקע באמצע: הדרך עד שם כבר נעשתה.A compile error is like a spellcheck before sending a letter: the letter doesn't go out until it's fixed. An exception is like a car that set off and broke down halfway: the road up to there was already travelled.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
unclosed string literal = "מחרוזת שלא נסגרה". מוסיפים " לפני הסוגר. ושימו לב: אפילו השורה הראשונה, שהייתה תקינה, לא הודפסה. זו שגיאת קומפילציה.unclosed string literal = "a string that was never closed". Add the " before the bracket. And notice: even the first line, which was fine, didn't print. That's a compile error.
שוכחים לסגור מירכאות. המהדר לא יודע איפה הטקסט נגמר.Forgetting to close the quotes. The compiler doesn't know where the text ends.
מה עושה הפקודה javac Main.java?What does the command javac Main.java do?
מריצה את התוכנית ומדפיסה את הפלטRuns the program and prints its output
בודקת את הקוד ויוצרת Main.class עם bytecodeChecks the code and creates Main.class with bytecode
מתקינה את Java במחשבInstalls Java on the computer
פותחת את IntelliJOpens IntelliJ
שואלים את הכיתה ומצביעים. התשובה בשקופית הבאה.Ask the class and take a vote. The answer is on the next slide.
בודקת את הקוד ויוצרת Main.class עם bytecodeChecks the code and creates Main.class with bytecode
נכון! זה תפקיד המהדר. אם יש שגיאה, היא מופיעה כאן ולא נוצר קובץ.Right! That's the compiler's job. If there's an error it shows here and no file is made.
מה למדנוWhat we learned
תוכנית היא רשימת הוראות שהמחשב מבצע לפי הסדרA program is a list of instructions the computer carries out in order
Java רצה בשרתים, ב-Android, בבנקים, במערכות נתונים ובמשחקיםJava runs servers, Android, banks, data systems and games
שני שלבים: javac Main.java מקמפל, java Main מריץTwo steps: javac Main.java compiles, java Main runs
מתקינים JDK 21 (LTS), למשל Eclipse Temurin מ-adoptium.netInstall JDK 21 (LTS), for example Eclipse Temurin from adoptium.net