Skip to content

Commit 16f06c9

Browse files
authored
Update README.md
1 parent 53c0c23 commit 16f06c9

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

README.md

+40-35
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Learn git and github
1717

1818
### 1- cannot find symbol PART 1
1919
Raised when you try to call an undeclared variable
20-
```
20+
```java
2121
public class Omar{
2222
public static void main(String [] args)
2323
{
@@ -32,7 +32,7 @@ public class Omar{
3232

3333
In line 8 we try to print to the console mean we have set the value of mean but we never declared it
3434
To solve we do this
35-
```
35+
```java
3636
public class Omar{
3737
public static void main(String [] args)
3838
{
@@ -46,7 +46,7 @@ public class Omar{
4646
```
4747
### 2- cannot find symbol PART 2
4848
Raised when you try to call an undeclared variable
49-
```
49+
```java
5050
public class Great{
5151
public static void main(String [] args)
5252
{
@@ -63,7 +63,7 @@ public class Great{
6363

6464
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
6565

66-
```
66+
```java
6767
public class Great{
6868
public static void main(String [] args)
6969
{
@@ -81,7 +81,7 @@ public class Great{
8181
### symbol: class Scanner
8282
### location: class Great
8383
Raised when you are using the scanner
84-
```
84+
```java
8585
public class Great{
8686
public static void main(String [] args)
8787
{
@@ -92,7 +92,7 @@ public class Great{
9292
```
9393

9494
In line 4 we are using the scanner but we never imported the library that enables us to use it
95-
```
95+
```java
9696
import java.util.Scanner;
9797
public class Great{
9898
public static void main(String [] args)
@@ -106,7 +106,7 @@ public class Great{
106106
### 4- class <.x.> is public, should be declared in a file named <X>.jav
107107
### Ignore the .x. its <x> how its displayed this error is raised when I do this:
108108

109-
```
109+
```java
110110
public class Thebest
111111
{
112112
public static void main(String[] args) {
@@ -119,7 +119,7 @@ public class Thebest
119119

120120
### 5- < identifier> expected
121121
This error is raised when I try to write code outside of a method which is unintentionally done.
122-
```
122+
```java
123123
public class Test {
124124
System.out.println("Hello!");
125125

@@ -131,7 +131,7 @@ This error is raised when I try to write code outside of a method which is unint
131131

132132
To fix I just place the print Statement of hello inside of main
133133

134-
```
134+
```java
135135
public class Test {
136136
public static void main(String[] args) {
137137
System.out.println("Hello!");
@@ -143,7 +143,7 @@ To fix I just place the print Statement of hello inside of main
143143
### 6- illegal start of expression
144144

145145
An "illegal start of expression" error occurs when the compiler when we start a expression before closing the previous one.
146-
```
146+
```java
147147
public class Test {
148148
public static void main(String[] args) {
149149
my_method();
@@ -156,7 +156,7 @@ An "illegal start of expression" error occurs when the compiler when we start a
156156
```
157157

158158
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
160160
public class Test
161161
{
162162
public static void main(String[] args)
@@ -174,7 +174,7 @@ public class Test
174174
### 7- incompatible types
175175

176176
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. BUt WE CANNOT 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, Regular Expression or Date..
177-
```
177+
```java
178178
public class Test
179179
{
180180
public static void main(String[] args)
@@ -186,7 +186,7 @@ public class Test
186186
The above code is an error because we are assigning the string Hello World to the variable num of type int.
187187
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.
188188
Step 1: Change the String value from Hello, world! to 500
189-
```
189+
```java
190190
public class Test
191191
{
192192
public static void main(String[] args)
@@ -197,7 +197,7 @@ public class Test
197197
```
198198

199199
Step 2: Use parsing to convert the string to an integer
200-
```
200+
```java
201201
public class Test
202202
{
203203
public static void main(String[] args)
@@ -213,7 +213,7 @@ public class Test
213213

214214
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.
215215
When a method declaration does not contain a return type, this error will occur:
216-
```
216+
```java
217217
public class Test
218218
{
219219
public static void main(String[] args)
@@ -233,7 +233,8 @@ public class Test
233233
To fix this, simply insert the appropriate return type in the method signature and the error will go away:
234234

235235

236-
```public class Test
236+
```java
237+
public class Test
237238
{
238239
public static void main(String[] args)
239240
{
@@ -250,7 +251,7 @@ To fix this, simply insert the appropriate return type in the method signature a
250251
### 9-java.lang.ArrayIndexOutOfBoundsException: <X>
251252

252253
An ArrayIndexOutOfBoundsException 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, if I enter a value of 8 or greater to access, this will raise an error.
253-
```
254+
```java
254255
public class Test {
255256
public static void main(String[] args) {
256257
int[] arr = {1, 2, 3};
@@ -261,8 +262,7 @@ An ArrayIndexOutOfBoundsException is thrown when an attempt is made to access an
261262
}
262263
```
263264
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
266266
public class Test {
267267
public static void main(String[] args) {
268268
int[] arr = {1, 2, 3};
@@ -277,7 +277,8 @@ public class Test {
277277
### 10- StringIndexOutOfBoundsException
278278
The exception StringIndexOutOfBoundsException is thrown to the console when an attempt is made to access an index in
279279
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
281282
public class Test
282283
{
283284
public static void main(String[] args)
@@ -295,7 +296,7 @@ public class Test
295296
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.
296297
Therefore the bottom code is bug free
297298
298-
```
299+
```java
299300
public class Test
300301
{
301302
public static void main(String[] args)
@@ -312,7 +313,7 @@ public class Test
312313
313314
314315
### 11- illegal start of expression
315-
```
316+
``` java
316317
public class Omar {
317318
public static void main(String[] args) {
318319
omarMethod(1.0, 2, "Hello!");
@@ -324,8 +325,9 @@ public class Test
324325
}
325326
326327
```
328+
327329
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
329331
public class Omar
330332
{
331333
public static void main(String[] args) {
@@ -337,8 +339,9 @@ public class Omar
337339
}
338340
}
339341
```
342+
340343
### 12- Left out return statement
341-
```
344+
```java
342345
public class Omar
343346
{
344347
public static void main(String[] args)
@@ -355,7 +358,8 @@ public class Omar
355358
```
356359
The above code errors because I have made the function behave like a void but my 3rd keyword indicates my return type should
357360
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
359363
public class Omar
360364
{
361365
public static void main(String[] args)
@@ -374,7 +378,7 @@ public class Omar
374378
375379
376380
### - Left out return statement in CASE#2
377-
```
381+
```java
378382
public class Omar
379383
{
380384
public static void main(String[] args)
@@ -397,8 +401,9 @@ public class Omar
397401
}
398402
}
399403
```
404+
400405
The above lines of code have an error in logic. We should switch the code to this:
401-
```
406+
```java
402407
public class Omar
403408
{
404409
public static void main(String[] args)
@@ -423,7 +428,7 @@ public class Omar
423428
```
424429
425430
### 13 - possible loss of precision
426-
```
431+
```java
427432
public class Omar
428433
{
429434
public static void main(String[] args)
@@ -435,7 +440,7 @@ public class Omar
435440
```
436441
There is an error above being raised being we are store double in an integer. An integer can only store 4
437442
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
439444
public class Omar
440445
{
441446
public static void main(String[] args)
@@ -447,7 +452,7 @@ public class Omar
447452
```
448453
449454
### 14 - Reached end of file while parsing
450-
```
455+
```java
451456
public class Omar
452457
{
453458
public static void main(String[] args)
@@ -462,7 +467,7 @@ public class Omar
462467
```
463468
There is an error above being raised being we are not properly closing our class. To solve this issue we add a closing
464469
curly brace. After, the closing curly brace of my method.
465-
```
470+
```java
466471
public class Omar
467472
{
468473
public static void main(String[] args)
@@ -480,7 +485,7 @@ public class Omar
480485
### 15 - unreachable statement
481486
482487
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
484489
public class Omar
485490
{
486491
public static void main(String[] args)
@@ -501,7 +506,7 @@ public class Omar
501506
The compiler will generate a number of errors. The first one to be listed is that it is unable to reach the print statement.
502507
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.
503508
To fix this error I simply reverse the order of the print statement and the return statement.
504-
```
509+
```java
505510
public class Omar
506511
{
507512
public static void main(String[] args)
@@ -521,7 +526,7 @@ public class Omar
521526
### 16 - Variable might not have been initialized
522527
An variable might not have been initialized error is triggered when we declare a variable and specify its type but
523528
never give it an initial value;
524-
```
529+
```java
525530
public class Omar
526531
{
527532
public static void main(String[] args) {
@@ -534,7 +539,7 @@ never give it an initial value;
534539
535540
The compiler will generate the error variable myNum2 might not have been initialized because we declared it with
536541
the specified data type but never gave it an initial value. To solve this, I simply give it an initial value.
537-
```
542+
```java
538543
public class Omar
539544
{
540545
public static void main(String[] args)

0 commit comments

Comments
 (0)