חלקPart 1: יסודותFoundations
כ-3 שעות (כולל הפסקה)About 3 hours (with a break)
מה זה תכנות? 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.
הנקודות החשובותKey points
- תוכנית היא רשימת הוראות שהמחשב מבצע לפי הסדרA program is a list of instructions the computer carries out in order
- המחשב לא מנחש: הוא עושה בדיוק מה שכתובThe computer never guesses: it does exactly what's written
- Java רצה בשרתים, ב-Android, בבנקים, במערכות נתונים ובמשחקיםJava runs servers, Android, banks, data systems and games
- ה-מהדר בודק את הקוד לפני שהוא רץ, ותופס הרבה טעויות מוקדםThe compiler checks the code before it runs, and catches many mistakes early
- שני שלבים:
javac Main.javaמקמפל,java MainמריץTwo steps:javac Main.javacompiles,java Mainruns - ה-מהדר יוצר bytecode בקובץ .class, וה-JVM מריצה אותוThe compiler makes bytecode in a .class file, and the JVM runs it
- מתקינים 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 --versionand alsojavac --version - IntelliJ IDEA Community היא סביבת פיתוח חינמית: עורך, הרצה ודיבוג במקום אחדIntelliJ IDEA Community is a free IDE: editor, running and debugging in one place
מונחיםTerms
- תוכניתprogram: רשימה של הוראות שהמחשב מבצע לפי הסדר. ב-Java תוכנית מתחילה תמיד במתודה main.A list of instructions the computer carries out in order. In Java a program always starts at the main method.
- תכנותprogramming: כתיבת הוראות מדויקות למחשב בשפה שהוא יודע לבצע, כדי שיפתור בעיה או יעשה משימה.Writing precise instructions for a computer, in a language it can run, so that it solves a problem or does a task.
- קודcode: הטקסט שאנחנו כותבים בשפת תכנות. "לכתוב קוד" זה לכתוב תוכנית.The text we write in a programming language. "Writing code" means writing a program.
- שפת תכנותprogramming language: שפה עם חוקים מדויקים (תחביר) שבה כותבים הוראות למחשב. Java היא שפת תכנות אחת מתוך הרבה.A language with exact rules (syntax) for writing instructions to a computer. Java is one programming language among many.
- JavaJava: שפת תכנות מבוססת מחלקות עם טיפוסים קבועים, שרצה על ה-JVM. משמשת לשרתים, אפליקציות Android, מערכות בנקאיות, ביג-דאטה ומשחקים.A class-based, statically typed programming language that runs on the JVM. Used for servers, Android apps, banking systems, big data and games.
- מהדר (compiler)compiler: תוכנה שקוראת את כל הקוד, בודקת שהוא תקין, ומתרגמת אותו לשפה אחרת. ב-Java המהדר הוא javac, והוא מתרגם ל-bytecode.A program that reads all the code, checks it, and translates it into another language. In Java the compiler is javac, and it translates into bytecode.
- javacjavac: המהדר של Java. הפקודה javac Main.java בודקת את הקוד ויוצרת את הקובץ Main.class.Java's compiler. The command javac Main.java checks the code and creates the file Main.class.
- bytecodebytecode: השפה שה-JVM מבינה: הוראות פשוטות שנשמרות בקבצי .class. אותו bytecode רץ בכל מחשב שיש בו JVM.The language the JVM understands: simple instructions stored in .class files. The same bytecode runs on any computer with a JVM.
- קובץ .class.class file: הקובץ שהמהדר יוצר מקובץ .java. הוא מכיל bytecode, ולא נועד לקריאה של בני אדם.The file the compiler makes from a .java file. It holds bytecode and isn't meant for people to read.
- JVMJVM: Java Virtual Machine: "מחשב וירטואלי" שמריץ bytecode. יש JVM ל-Windows, ל-Mac, ל-Linux ואפילו לדפדפן, ולכן אותה תוכנה רצה בכולם.Java Virtual Machine: a "virtual computer" that runs bytecode. There's a JVM for Windows, Mac, Linux and even the browser, so the same program runs on all of them.
- JDKJDK: Java Development Kit: ערכת הפיתוח. כוללת את ה-JVM, את המהדר javac, את jshell ועוד כלים. מתקינים JDK כדי לכתוב Java.Java Development Kit: the developer's kit. It includes the JVM, the javac compiler, jshell and more tools. You install a JDK to write Java.
- JREJRE: Java Runtime Environment: רק מה שצריך כדי להריץ תוכנות Java (JVM וספריות), בלי מהדר. היום מתקינים בדרך כלל JDK שלם.Java Runtime Environment: just what's needed to run Java programs (the JVM and libraries), with no compiler. Today you usually install a whole JDK.
- LTSLTS: Long-Term Support: גרסה שמקבלת עדכונים ותיקונים במשך שנים. Java 21 היא גרסת LTS, ולכן הקורס בנוי עליה.Long-Term Support: a version that gets updates and fixes for years. Java 21 is an LTS version, so the course is built on it.
- סביבת פיתוח (IDE)IDE: Integrated Development Environment: תוכנה לכתיבת קוד שכוללת עורך, הרצה, דיבוג והשלמה אוטומטית במקום אחד.Integrated Development Environment: a program for writing code with an editor, running, debugging and autocomplete in one place.
- IntelliJ IDEAIntelliJ IDEA: סביבת הפיתוח הפופולרית ביותר ל-Java. בקורס משתמשים בגרסה החינמית, Community.The most popular IDE for Java. The course uses the free edition, Community.
- jshelljshell: כלי שמגיע עם ה-JDK ומאפשר להקליד שורת Java ולראות מיד את התוצאה, בלי class ובלי main.A tool that comes with the JDK: type a line of Java and see the result at once, with no class and no main.
- טרמינלterminal: חלון שבו מקלידים פקודות טקסט למחשב במקום ללחוץ עם העכבר. ב-Mac נקרא Terminal, וב-Windows משתמשים ב-PowerShell.A window where you type text commands to the computer instead of clicking. On a Mac it's called Terminal; on Windows we use PowerShell.
- פקודהcommand: הוראה אחת שמקלידים בטרמינל ולוחצים Enter, למשל javac Main.java או java --version.One instruction typed in the terminal followed by Enter, for example javac Main.java or java --version.
- PATHPATH: רשימת התיקיות שבהן הטרמינל מחפש תוכנות. אם התיקייה bin של ה-JDK לא ב-PATH, הפקודה javac "לא מוכרת".The list of folders where the terminal looks for programs. If the JDK's bin folder isn't on PATH, the javac command is "not recognized".
- JAVA_HOMEJAVA_HOME: משתנה סביבה שמצביע על התיקייה שבה מותקן ה-JDK. כלים כמו Maven ו-Gradle משתמשים בו כדי למצוא את Java.An environment variable pointing at the folder where the JDK is installed. Tools like Maven and Gradle use it to find Java.
- מחלקה (class)class: תבנית שממנה יוצרים עצמים. ב-Java כל קוד נמצא בתוך מחלקה, ושם הקובץ חייב להיות זהה לשם המחלקה הציבורית.A blueprint for making objects. In Java all code lives inside a class, and the file name must match the public class's name.
- המתודה mainthe main method: public static void main(String[] args): נקודת הכניסה של התוכנית. ה-JVM מתחילה לבצע מכאן.public static void main(String[] args): the program's entry point. The JVM starts running from here.
- מתודהmethod: פעולה עם שם שמוגדרת בתוך מחלקה, כמו main או println. קוראים לה עם סוגריים.A named action defined inside a class, like main or println. You call it with parentheses.
- משפט (statement)statement: הוראה אחת בתוכנית, למשל הדפסה. ב-Java משפט נגמר בנקודה-פסיק ;.One instruction in a program, like a print. In Java a statement ends with a semicolon ;.
- בלוקblock: קבוצת שורות בין סוגר מסולסל פותח { לסוגר סוגר }. הבלוק שייך למה שכתוב לפניו: מחלקה, מתודה, תנאי או לולאה.A group of lines between an opening { and a closing }. The block belongs to what comes right before it: a class, a method, a condition or a loop.
- מחרוזת (String)string: טקסט. ב-Java כותבים מחרוזת בין מירכאות כפולות: "שלום". מה שבמירכאות מוצג כמו שהוא.Text. In Java a string goes between double quotes: "hello". Whatever is inside the quotes is shown as is.
- printlnprintln: System.out.println מציגה ערך על המסך ויורדת שורה. System.out.print מציגה בלי לרדת שורה.System.out.println shows a value on the screen and moves to a new line. System.out.print shows it without a new line.
- פלטoutput: מה שהתוכנית מציגה החוצה, בדרך כלל על המסך.What the program shows out, usually on the screen.
- אופרטורoperator: סימן שעושה פעולה על ערכים: + - * / %. בין מחרוזות, + מחבר אותן.A symbol that does something to values: + - * / %. Between strings, + joins them.
- חלוקה של שלמיםinteger division: כששני המספרים שלמים, / זורק את מה שאחרי הנקודה: 7 / 2 הוא 3. ה-% נותן את השארית: 7 % 2 הוא 1.When both numbers are whole, / drops what's after the point: 7 / 2 is 3. % gives the remainder: 7 % 2 is 1.
- הערהcomment: טקסט בקוד שהמהדר מדלג עליו, בשביל בני אדם: // עד סוף השורה, או בין /* ל-*/.Text in the code that the compiler skips, for people: // to the end of the line, or between /* and */.
- תחבירsyntax: החוקים של איך כותבים בשפה: איפה שמים סוגריים, נקודה-פסיק ומירכאות. טעות תחביר נתפסת כבר בקומפילציה.The rules of how to write in the language: where brackets, semicolons and quotes go. A syntax mistake is caught at compile time.
- שגיאת קומפילציהcompile error: בעיה שהמהדר javac מוצא לפני שהתוכנית רצה. התוכנית לא תרוץ בכלל עד שמתקנים. ההודעה מתחילה בשם הקובץ ומספר השורה.A problem the javac compiler finds before the program runs. The program won't run at all until it's fixed. The message starts with the file name and line number.
- חריגה (exception)exception: בעיה שקורית בזמן ריצה, למשל חלוקה ב-0. אם אף אחד לא מטפל בה, התוכנית עוצרת ומדפיסה Exception in thread "main".A problem that happens while running, like dividing by 0. If nobody handles it, the program stops and prints Exception in thread "main".
- stack tracestack trace: הרשימה שמופיעה מתחת לחריגה, שורות שמתחילות ב-at. היא אומרת באיזו מתודה ובאיזו שורה החריגה קרתה.The list under an exception, lines starting with at. It says which method and which line the exception happened on.
- באגbug: טעות בתוכנית שגורמת לה להתנהג אחרת ממה שרצינו. לחפש ולתקן באגים נקרא דיבוג (debugging).A mistake in a program that makes it behave differently from what we wanted. Finding and fixing bugs is called debugging.
- רגיש לאותיות גדולותcase-sensitive: ב-Java אות גדולה וקטנה הן שונות: System ו-system הן שתי מילים שונות לגמרי.In Java capital and small letters are different: System and system are two completely different words.
- התקנהinstallation: הכנסת תוכנה למחשב כך שאפשר להשתמש בה. בקורס מתקינים JDK ו-IntelliJ IDEA פעם אחת.Putting a program onto the computer so you can use it. In this course you install a JDK and IntelliJ IDEA once.
Cheatsheet
מה זה תכנותWhat programming is
System.out.println("שלום! זו התוכנית הראשונה שלי ב-Java");
System.out.println("Java מבצעת שורה אחרי שורה");System.out.println("Hello! This is my first Java program");
System.out.println("Java runs one line after another");למה JavaWhy Java
System.out.println(2 + 3);
System.out.println("2 + 3");IntelliJIntelliJ
System.out.println("שלום מ-IntelliJ");System.out.println("Hello from IntelliJ");מבנה תוכניתProgram shape
// התוכנית מדפיסה כרטיס קטן
System.out.println("+----------+");
System.out.println("| Java 21 |");
System.out.println("+----------+");
System.out.println(7 * 6);// This program prints a small card
System.out.println("+----------+");
System.out.println("| Java 21 |");
System.out.println("+----------+");
System.out.println(7 * 6);הדפסה וחשבוןPrinting and maths
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");שגיאות שפגשנוErrors we met
| שגיאהError | מה זה אומרWhat it means | מה עושיםWhat to do |
|---|---|---|
cannot find symbol | כותבים 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. | 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. |
illegal start of expression | משאירים חישוב באמצע. אחרי ה-+ חסר משהו, ולכן המהדר לא מבין את השורה בכלל, ושום דבר לא רץ.Leaving a calculation half-written. Something is missing after the +, so the compiler can't understand the line at all, and nothing runs. | 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);. |
class Hello is public, should be declared in a file named He | שם המחלקה לא תואם לשם הקובץ: בקובץ 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. | 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. |
';' expected | שוכחים נקודה-פסיק בסוף משפט. לבני אדם זה פרט קטן, אבל למהדר זה כמו משפט בלי נקודה: הוא לא יודע איפה המשפט נגמר.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. | ';' 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. |
package system does not exist | כותבים system עם s קטנה. System עם S גדולה היא מחלקה מוכנה של Java, ואילו system לא קיים בכלל.Writing system with a small s. System with a capital S is a ready-made Java class, while system doesn't exist at all. | package system does not exist: המהדר חשב ש-system הוא שם של חבילה (תיקייה של מחלקות), ולא מצא כזו. מתקנים ל-System עם S גדולה.package system does not exist: the compiler thought system was a package name (a folder of classes), and found none. Fix it to System with a capital S. |
cannot find symbol | שוכחים מירכאות סביב טקסט. בלי מירכאות, המהדר חושב ש-Hello הוא שם של משתנה, ומחפש אותו.Forgetting the quotes around text. Without quotes, the compiler thinks Hello is the name of a variable, and looks for it. | 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". |
<identifier> expected | כותבים משפט ישר בתוך המחלקה, כמו ב-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. | <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) { ... }. |
unclosed string literal | שוכחים לסגור מירכאות. המהדר לא יודע איפה הטקסט נגמר.Forgetting to close the quotes. The compiler doesn't know where the text ends. | 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. |