You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+40-35
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ Learn git and github
17
17
18
18
### 1- cannot find symbol PART 1
19
19
Raised when you try to call an undeclared variable
20
-
```
20
+
```java
21
21
publicclassOmar{
22
22
publicstaticvoidmain(String [] args)
23
23
{
@@ -32,7 +32,7 @@ public class Omar{
32
32
33
33
In line 8 we try to print to the console mean we have set the value of mean but we never declared it
34
34
To solve we do this
35
-
```
35
+
```java
36
36
publicclassOmar{
37
37
publicstaticvoidmain(String [] args)
38
38
{
@@ -46,7 +46,7 @@ public class Omar{
46
46
```
47
47
### 2- cannot find symbol PART 2
48
48
Raised when you try to call an undeclared variable
49
-
```
49
+
```java
50
50
publicclassGreat{
51
51
publicstaticvoidmain(String [] args)
52
52
{
@@ -63,7 +63,7 @@ public class Great{
63
63
64
64
In line 4 we are incorrectly calling the_best_method but we forget the parenthesis. To fix this error I must place the open and close parenthesis
65
65
66
-
```
66
+
```java
67
67
publicclassGreat{
68
68
publicstaticvoidmain(String [] args)
69
69
{
@@ -81,7 +81,7 @@ public class Great{
81
81
### symbol: class Scanner
82
82
### location: class Great
83
83
Raised when you are using the scanner
84
-
```
84
+
```java
85
85
publicclassGreat{
86
86
publicstaticvoidmain(String [] args)
87
87
{
@@ -92,7 +92,7 @@ public class Great{
92
92
```
93
93
94
94
In line 4 we are using the scanner but we never imported the library that enables us to use it
95
-
```
95
+
```java
96
96
importjava.util.Scanner;
97
97
publicclassGreat{
98
98
publicstaticvoidmain(String [] args)
@@ -106,7 +106,7 @@ public class Great{
106
106
### 4- class <.x.> is public, should be declared in a file named <X>.jav
107
107
### Ignore the .x. its <x> how its displayed this error is raised when I do this:
108
108
109
-
```
109
+
```java
110
110
publicclassThebest
111
111
{
112
112
publicstaticvoidmain(String[] args) {
@@ -119,7 +119,7 @@ public class Thebest
119
119
120
120
### 5- < identifier> expected
121
121
This error is raised when I try to write code outside of a method which is unintentionally done.
122
-
```
122
+
```java
123
123
publicclassTest {
124
124
System.out.println("Hello!");
125
125
@@ -131,7 +131,7 @@ This error is raised when I try to write code outside of a method which is unint
131
131
132
132
To fix I just place the print Statement of hello inside of main
133
133
134
-
```
134
+
```java
135
135
publicclassTest {
136
136
publicstaticvoidmain(String[] args) {
137
137
System.out.println("Hello!");
@@ -143,7 +143,7 @@ To fix I just place the print Statement of hello inside of main
143
143
### 6- illegal start of expression
144
144
145
145
An "illegal start of expression" error occurs when the compiler when we start a expression before closing the previous one.
146
-
```
146
+
```java
147
147
publicclassTest {
148
148
publicstaticvoidmain(String[] args) {
149
149
my_method();
@@ -156,7 +156,7 @@ An "illegal start of expression" error occurs when the compiler when we start a
156
156
```
157
157
158
158
To fix this piece of code, I simply add a closing curly brace for the main method. To know we are doing the right thing, just look at the lines of code before the error, there may be a missing closing paranthesis or a missing closing curly brace. This would give us what the error is.
159
-
```
159
+
```java
160
160
publicclassTest
161
161
{
162
162
publicstaticvoidmain(String[] args)
@@ -174,7 +174,7 @@ public class Test
174
174
### 7- incompatible types
175
175
176
176
The incompatible types error is raised when we are facing with data type errors. We can overcome this, by converting say a char to an int. We can convert a double to an integer with typecasting. BUtWECANNOT convert between primitive types and objects. A primitive type is say a:null, undefined, boolean, number, string or char. However objects can be:Arrays, Maps, Sets, Functions, RegularExpression or Date..
177
-
```
177
+
```java
178
178
publicclassTest
179
179
{
180
180
publicstaticvoidmain(String[] args)
@@ -186,7 +186,7 @@ public class Test
186
186
The above code is an error because we are assigning the string HelloWorld to the variable num of type int.
187
187
To fix this error I must put a integer within the quotes and use the ParseInt method. This is not a syntax error but a logical error.
188
188
Step1:Change the String value from Hello, world! to 500
189
-
```
189
+
```java
190
190
publicclassTest
191
191
{
192
192
publicstaticvoidmain(String[] args)
@@ -197,7 +197,7 @@ public class Test
197
197
```
198
198
199
199
Step2:Use parsing to convert the string to an integer
200
-
```
200
+
```java
201
201
publicclassTest
202
202
{
203
203
publicstaticvoidmain(String[] args)
@@ -213,7 +213,7 @@ public class Test
213
213
214
214
Every method in Java requires that you explicitly state the return type of the method. Even methods that do not return a value must explicitly say void in the method signature, just as the main method does.
215
215
When a method declaration does not contain a return type, this error will occur:
216
-
```
216
+
```java
217
217
publicclassTest
218
218
{
219
219
publicstaticvoidmain(String[] args)
@@ -233,7 +233,8 @@ public class Test
233
233
To fix this, simply insert the appropriate return type in the method signature and the error will go away:
234
234
235
235
236
-
```public class Test
236
+
```java
237
+
publicclassTest
237
238
{
238
239
publicstaticvoidmain(String[] args)
239
240
{
@@ -250,7 +251,7 @@ To fix this, simply insert the appropriate return type in the method signature a
AnArrayIndexOutOfBoundsException is thrown when an attempt is made to access an index in an array that is not valid. This means that say an array has 8 elements and we know that the number of elements in index is 7.We start counting at 0.So, ifI enter a value of 8 or greater to access, this will raise an error.
253
-
```
254
+
```java
254
255
publicclassTest {
255
256
publicstaticvoidmain(String[] args) {
256
257
int[] arr = {1, 2, 3};
@@ -261,8 +262,7 @@ An ArrayIndexOutOfBoundsException is thrown when an attempt is made to access an
261
262
}
262
263
```
263
264
The code above errored due to the for loop iteration settings. The first element is index 0 which is fine however, the function's output of arr.length of our array named arr of type int is 3. However, we are using the comparison operator of <=. This means less than or equal to. If, we change it to < it will not error. The equal means it will try to access index 3 which is the 4th item in the array which we do not have.
264
-
```
265
-
265
+
```java
266
266
public class Test {
267
267
public static void main(String[] args) {
268
268
int[] arr = {1, 2, 3};
@@ -277,7 +277,8 @@ public class Test {
277
277
### 10- StringIndexOutOfBoundsException
278
278
The exception StringIndexOutOfBoundsException is thrown to the console when an attempt is made to access an index in
279
279
the String that is not valid. The only valid index of the String we can access is from 0 to the (length of the String-1). This means that if the array 8 elements. The biggest number I can access is 7 not 8. If we enter any number greater than 7 for access will throws an outofBoundsException. This is an error in runtime not compile-time. It is accepted by the compiler because it is a logical error
280
-
```
280
+
281
+
``` java
281
282
public class Test
282
283
{
283
284
public static void main(String[] args)
@@ -295,7 +296,7 @@ public class Test
295
296
To fix this I simply change the String a declaration in line 7 from index -1 to 1. Then another error, will raise because str.length output is 13. The last index we can access is 12. Then, we must change the datatype of b because the operation will output a character not a string. The fourth change we must make is change 20. The biggest index we can access is 12.
296
297
Therefore the bottom code is bug free
297
298
298
-
```
299
+
```java
299
300
public class Test
300
301
{
301
302
public static void main(String[] args)
@@ -312,7 +313,7 @@ public class Test
312
313
313
314
314
315
### 11- illegal start of expression
315
-
```
316
+
``` java
316
317
public class Omar {
317
318
public static void main(String[] args) {
318
319
omarMethod(1.0, 2, "Hello!");
@@ -324,8 +325,9 @@ public class Test
324
325
}
325
326
326
327
```
328
+
327
329
This errors because I have called the methods with the specified data types in the wrong order. I must call it in the right order
328
-
```
330
+
```java
329
331
public class Omar
330
332
{
331
333
public static void main(String[] args) {
@@ -337,8 +339,9 @@ public class Omar
337
339
}
338
340
}
339
341
```
342
+
340
343
### 12- Left out return statement
341
-
```
344
+
```java
342
345
public class Omar
343
346
{
344
347
public static void main(String[] args)
@@ -355,7 +358,8 @@ public class Omar
355
358
```
356
359
The above code errors because I have made the function behave like a void but my 3rd keyword indicates my return type should
357
360
be of type int. To fix this, after storing the computation in a variable. I use the return keyword to return to the console. The output of the computation performed by the method.
358
-
```
361
+
362
+
```java
359
363
public class Omar
360
364
{
361
365
public static void main(String[] args)
@@ -374,7 +378,7 @@ public class Omar
374
378
375
379
376
380
### - Left out return statement in CASE#2
377
-
```
381
+
```java
378
382
public class Omar
379
383
{
380
384
public static void main(String[] args)
@@ -397,8 +401,9 @@ public class Omar
397
401
}
398
402
}
399
403
```
404
+
400
405
The above lines of code have an error in logic. We should switch the code to this:
401
-
```
406
+
```java
402
407
public class Omar
403
408
{
404
409
public static void main(String[] args)
@@ -423,7 +428,7 @@ public class Omar
423
428
```
424
429
425
430
### 13 - possible loss of precision
426
-
```
431
+
```java
427
432
public class Omar
428
433
{
429
434
public static void main(String[] args)
@@ -435,7 +440,7 @@ public class Omar
435
440
```
436
441
There is an error above being raised being we are store double in an integer. An integer can only store 4
437
442
4 bytes in main memory. The value we are storing in it is a double which has a memory size of 8 bytes. The way to solve this issue. We will explictly cast the variable theAwesomePi to an int.
438
-
```
443
+
```java
439
444
public class Omar
440
445
{
441
446
public static void main(String[] args)
@@ -447,7 +452,7 @@ public class Omar
447
452
```
448
453
449
454
### 14 - Reached end of file while parsing
450
-
```
455
+
```java
451
456
public class Omar
452
457
{
453
458
public static void main(String[] args)
@@ -462,7 +467,7 @@ public class Omar
462
467
```
463
468
There is an error above being raised being we are not properly closing our class. To solve this issue we add a closing
464
469
curly brace. After, the closing curly brace of my method.
465
-
```
470
+
```java
466
471
public class Omar
467
472
{
468
473
public static void main(String[] args)
@@ -480,7 +485,7 @@ public class Omar
480
485
### 15 - unreachable statement
481
486
482
487
An "unreachable statement" error takes place when the compiler sees that it is impossible to reacha a certain statement. This is caused by the following code.
483
-
```
488
+
```java
484
489
public class Omar
485
490
{
486
491
public static void main(String[] args)
@@ -501,7 +506,7 @@ public class Omar
501
506
The compiler will generate a number of errors. The first one to be listed is that it is unable to reach the print statement.
502
507
This is because whenever we create a method and use the keyword return the compiler says you are done with the method therefore, we can exit out of the method and execute the next line of code.
503
508
To fix this error I simply reverse the order of the print statement and the return statement.
504
-
```
509
+
```java
505
510
public class Omar
506
511
{
507
512
public static void main(String[] args)
@@ -521,7 +526,7 @@ public class Omar
521
526
### 16 - Variable might not have been initialized
522
527
An variable might not have been initialized error is triggered when we declare a variable and specify its type but
523
528
never give it an initial value;
524
-
```
529
+
```java
525
530
public class Omar
526
531
{
527
532
public static void main(String[] args) {
@@ -534,7 +539,7 @@ never give it an initial value;
534
539
535
540
The compiler will generate the error variable myNum2 might not have been initialized because we declared it with
536
541
the specified data type but never gave it an initial value. To solve this, I simply give it an initial value.
0 commit comments