1 00:00:00,159 --> 00:00:03,190 Welcome to today's video on Java programming. 2 00:00:03,430 --> 00:00:07,949 In this lesson, we'll discuss a common issue that many programmers encounter 3 00:00:08,420 --> 00:00:10,510 syntax errors in Java. 4 00:00:10,670 --> 00:00:13,310 A syntax error occurs when the structure of your 5 00:00:13,319 --> 00:00:17,700 code violates the rules defined by the Java language. 6 00:00:18,639 --> 00:00:21,950 Let's start by understanding what a syntax error is 7 00:00:22,319 --> 00:00:28,430 in Java syntax refers to the set of rules that govern how you write your code. 8 00:00:28,579 --> 00:00:32,729 These rules define the contact order and format of statements, 9 00:00:32,740 --> 00:00:35,470 expressions and other elements in your program. 10 00:00:36,400 --> 00:00:41,209 When you make a mistake and violate any of these rules. A syntax error is triggered. 11 00:00:42,900 --> 00:00:47,240 In this first example, we have int x equals five. 12 00:00:47,700 --> 00:00:49,979 Well, if you type that in and compile it, 13 00:00:50,279 --> 00:00:52,029 you'll get a syntax error. 14 00:00:52,500 --> 00:00:57,090 This is because every statement in Java must end with a semicolon. 15 00:00:57,099 --> 00:01:00,610 Forgetting to include it will result in a syntax error. 16 00:01:01,500 --> 00:01:02,909 In this second example, 17 00:01:03,259 --> 00:01:07,919 we are given a system dot out dot print Ln hello world. 18 00:01:08,779 --> 00:01:10,400 Now, if you type this in, 19 00:01:10,720 --> 00:01:12,230 you'll still get an error. 20 00:01:12,879 --> 00:01:15,879 This is because in Java parentheses are 21 00:01:15,889 --> 00:01:19,129 used to group expressions or indicate method calls 22 00:01:19,360 --> 00:01:23,769 if you open a parentheses but forget to close it or vice versa, 23 00:01:23,959 --> 00:01:26,330 you will encounter a syntax error. 24 00:01:26,830 --> 00:01:28,789 In our third and last example, 25 00:01:29,169 --> 00:01:34,509 we are given a for loop and inside the for loop has a system dot out print Ln 26 00:01:35,190 --> 00:01:36,029 here. 27 00:01:36,440 --> 00:01:41,080 The word for is misspelled and this will cause an error in the compiler. 28 00:01:41,739 --> 00:01:44,699 Java has a set of reserve words also known 29 00:01:44,709 --> 00:01:48,589 as keywords that have predefined meaning in the language 30 00:01:48,789 --> 00:01:51,989 misspelling these keywords will lead to a syntax error. 31 00:01:52,180 --> 00:01:55,470 The Java compiler provides error messages that indicate 32 00:01:55,479 --> 00:01:58,269 the line and location where the error occurred 33 00:01:58,509 --> 00:02:00,589 by carefully reading these error messages. 34 00:02:00,599 --> 00:02:04,110 You can identify the issue and make necessary corrections. 35 00:02:04,559 --> 00:02:06,529 Review the error message. 36 00:02:06,540 --> 00:02:10,850 The error message will specify the type of error and provide a line number, 37 00:02:11,119 --> 00:02:14,050 read the message carefully to understand the problem. 38 00:02:14,500 --> 00:02:15,850 Locate the error, 39 00:02:16,089 --> 00:02:20,490 go to the line indicated in the error message and examine the code around it. 40 00:02:20,619 --> 00:02:25,710 Look for any missing symbols, incorrect syntax or misspelled keywords, 41 00:02:26,270 --> 00:02:27,679 correct the error. 42 00:02:27,759 --> 00:02:32,220 Once you've identified the issue, make the appropriate changes to fix the error. 43 00:02:32,279 --> 00:02:34,800 It could involve adding a missing semicolon, 44 00:02:34,809 --> 00:02:38,079 correcting parentheses or using the correct keyword. 45 00:02:38,418 --> 00:02:42,250 Syntax errors are a common challenge when programming in Java. 46 00:02:42,550 --> 00:02:46,309 But with careful review of error messages and attention to detail, 47 00:02:46,320 --> 00:02:49,289 you can quickly identify and fix these issues. 48 00:02:49,300 --> 00:02:52,119 Remember to pay close attention to the syntax rules of 49 00:02:52,130 --> 00:02:55,699 the Java language and take note of the compiler's error messages 50 00:02:56,139 --> 00:02:59,149 that concludes our discussion on syntax errors in Java. 51 00:02:59,160 --> 00:03:01,429 Thank you for watching and Happy Coding.