0% found this document useful (0 votes)
126 views32 pages

INTERMEDIATE PROGRAMMING. Assessment.

The document discusses Java programming concepts including input/output, expressions, blocks, comments, and flow control. It provides examples of errors that may occur in Java code and their explanations. For each error, debugging steps are proposed to correct the code, such as removing unnecessary characters, adding missing brackets or semicolons, and ensuring variable and method names are spelled correctly. Overall, the document aims to help programmers learn Java programming basics and how to debug common syntax errors through examples and explanations.

Uploaded by

Gael Louise
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views32 pages

INTERMEDIATE PROGRAMMING. Assessment.

The document discusses Java programming concepts including input/output, expressions, blocks, comments, and flow control. It provides examples of errors that may occur in Java code and their explanations. For each error, debugging steps are proposed to correct the code, such as removing unnecessary characters, adding missing brackets or semicolons, and ensuring variable and method names are spelled correctly. Overall, the document aims to help programmers learn Java programming basics and how to debug common syntax errors through examples and explanations.

Uploaded by

Gael Louise
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

A.

Java Program Coding and Debugging:

1. Analyze and review your Java Program Coding and Debugging of each item.

2. Accomplish the following:


2.1. Program Title Functions and Descriptions of each item
2.2. (10) Error codes with explanation (indicate the source line number)
2.3. (10) Debugging codes with explanation based on 2.2.
1.6. Java Input and Output
The input is the data that the user give to the program. The output is the
data what the user receive from the program in the form of result.
1.6.1. Java Output
1.6.2. print() and println()
1.6.3. Printing Variables and Literals
1.6.4. Print Concatenated Strings
1.6.5. Get Integer Input From the User
1.6.6. Get float, double and String Input

o 1.7 Java Expressions & Blocks

1.7.1. Java Blocks


o 1.8 Java Comment
1.8.1. Single-line Comment
1.8.2. Multi-line Comment

2. Java Flow Control

o 2.1 Java if...else


o 2.2 Java switch Statement
o 2.3 Java for Loop
o 2.4 Java for-each Loop
o 2.5 Java while Loop
o 2.6 Java break Statement
o 2.7 Java continue Statement

Reference:
https://www.programiz.com/java-programming/examples

1.6.1. Java Output

To send output into a standard output (The PrintStream class


accessed through the System. Outfield. Standard output prints to the
display, also called the console..) and be able to accept the output data
in the program.
Program errors:

 Empty character literal (1)


Because of the apostrophe the program error shows. The program
interprets my declaration as trying to print empty character in Java.
 class java output is public, should be declared in a file named
javaoutput.java (4)
In this source line, the error is pertaining to the Javaoutput. Where in
it doesn’t match to the file name of the program
 class, interface, enum or error expected (4)
This program error arouse because of the compile time error where I
am violating the rules of writing syntax. As we can see the there is a
misspelled in public class. That is the reason why this error shows
 ']' expected (5)
This line error shows because there is a missing code in encoding the
string array argument. Which is the ‘]’.
 Invalid method declaration; return type required. (5)
The program error pertains to the invalid method declaration. Where
the void is missing in the source line.
 <Identifier expected> (5)
In this line error, it says that the code doesn't comply with the syntax
rules of the Java language. The method name main is missing.
 missing method body, or declared abstract (5)
There is something missing in the source code that’s why I can’t
successfully execute the starting point of the program. The ‘{‘is
missing.
 Unclosed string literal (6)
It refers to the string literal which has not been closed. In my source
code I forgot to encode the open quotation mark that is why the
declaration of the string was failed.
 <identifier expected> (6)
Because of the period after the close quotation mark, the program
error shows. Where in the code doesn't comply with the syntax rules of
the Java language again.
 Illegal start of expression (6)
This line error shows because the Java compiler finds something
inappropriate with the source code at the time of execution. The :
colon was the error in this source line.

Debugging:

Source line 1
 package javaoutput;
 I remove the apostrophe (‘’) and replace it into semicolon (;) to
declare the correct source code.

Source line 4
public class JavaOutput {

 JavaOutput is the correct source code in this line program. The


source code must match the name of java file to prevent errors
from arousing.
 Public class is the correct source code in this source line
program. Double checking the spelling is a must to avoid such
errors.

Source line 5
public static void main(String[] args) {
 (String[] args) java command line arguments is very important to
proceed to the starting point of the program. Having a one missing
code can cause an error. Always checking small details is a must.
In this source line the closing bracket (]) is the solution to sort out
the problem.
 Void is one of the missing source code in the source line error.
The reason why void is important in the starting line of the
program is because it is a java main that doesn’t return anything.
That is why its return type is void.
 Main is also one of the source code that we need to encode to
complete it and successfully execute the program. This is the java
main method. Where its fixed and when starting a java program, it
looks for the main method.
 { the open curly brace is also one of the missing code in the source
line. The program can’t execute properly because the program
can’t specify if the source program that we are going to encode
later on is included to the class line. That is why curly braces ({})
is important to identify the main group and subgroups in the
program.

Source line 6
System.out.println("Java programming is challenging.");
 "Java programming is challenging." The source code that is
missing in this source line error is the quotation mark (“) before
the word Java. To declare a string, it is important to always put
quotation mark (“”) in the beginning and end of a statement.
 ("Java programming is challenging."); the 2nd error in this line
program pertains to the period. I failed to declare the string as a
statement that is why the program interprets the period in the
string that doesn't comply with the syntax rules of the Java
language.
 ("Java programming is challenging."); I removed the colon in
the last part of the statement to correct the source code.

1.6.2. print() and println()


The java print() is a method used to display a text/string inside the
quotation mark on the console. While the println() adds new line after
print text on console.

Program errors:

 { expected (5)
The source line error pertains to the wrong declaration of source code
where in the close curly brace (}) was encoded in the starting point of
the program.
 Cannot find symbol (5)
This error arouse because the program can’t identify the purpose of
Str in the program. There is something wrong in the encoded source
code.
 <identifier> expected (5)
Because of the misspelled source code the program denied the
declaration that I encoded because it doesn’t comply with the syntax
rules of the programming language.
 initializer can be static (5)
In this error the program mistakenly interpret the period as
initializing a type and name of a variable. That is why the program is
telling me that it’s impossible for me to initialize the period in the
source line program.
 Variable println is neither read or written to (6)
This line error shows because I didn’t follow the proper way of
declaring the correct source code.
 package system does not exist (7)
Because of the wrong encode. An error arouse. The source code
system was not encoded in a proper way.
 ; expected (9)
Because of the colon this program error arouse. The statement was
not declared properly.
 not a statement (9)
Because of the apostrophe the program declared the source line as a
not statement because it is not the proper way of encoding a string.
 ) expected (10)
I mistakenly encode 0 instead of close parenthesis that is why this
error shows.
 class, interface, enum or error expected (11)
The source line 11 had an error because of the wrong declaration in
source line 5. Both of it is trying to declare the same purpose.

Debugging:

Source line 3
 public class JavaprintAndprintln {
 } Replace the close curly brace (}) into open curly brace ({) to correct
the source code and declare the starting point of the program.

Source line 5
public static void main(String[] args) {

 (String[] args) is the correct source code in line 5


 public static void main is the correct spelling of the code in line
5. This code is important because it has something to do to the JVM
where it load the class into memory and call the main method.
 (String[] args) The period has nothing to do in this source line
code. That is why it must be efface to avoid such diversion.
Source line 6
 System.out.println("GAB");

 System.out.println the debugging method in this program is to


encode the source code in a proper way. Code assistance is a big help
in program because it guide or assist us to declare the codes that we
want to execute.

Source line 7
 System.out.println("LOUISE");

 System.out.println programming is a key sensitive one. It is


important to be mindful in encoding such codes. Always identify the
codes that should be capitalized or not.

Source line 9
 System.out.print("LOUISE");

 ("LOUISE"); declaring a statement always end with semicolon (;)


not colon (:)

 ("LOUISE"); knowing the correct source code of declaring a string


is very important to avoid such errors putting open and close
quotation marks (“”) is the correct code to declare a string.

Source line 10
 System.out.print("GAB");

 ("GAB") by replacing the zero into close parenthesis the source


code will be execute successfully.

1.6.3. Printing Variables and Literals

Java variables is located in memory that holds data and has a unique
name as its identifier while literals are data’s that is used in representing
fixed values.
Program errors:

 Incorrect package (1)


This program error arouse because there is something wrong in the name
of the package.
 class PrintingVaribleandLiterals is public, should be declared in a
filenamed PrintingVaribleandLiterals.java (4)
The class name is not match in the file name of the program that is why I
encountered an error.
 missing java doc (7)
An error arouse because there is a misspelled code in my program.
 cannot find symbol (7)
the program cannot find the symbol because there is no such code Strng
in java programming.

 Variable nmber is neither read or written to (8)


The misspelled code cause an error and the program can’t accept or
interpret it.
 as of release 9,'_' is a keyword and may not used as an identifier (8)
There is an underscore which is not part of the program. The error
explained it that underscore is only a keyword.
 not a statement (9)
The program state a not statement as an error in the source line 9 because
the variable was not declared in its proper code.
 empty statement (9)
Putting a semicolon in the end of the line program we declare it as a
complete statement in this part the semicolon was doubled that is why
this error shows.
 ) expected (10)
Because of the doubled open parenthesis the program is asking to encode
another close parenthesis to partner the other open parenthesis.
 reach end of file while pharsing (11)
The program is telling me that my Source code is not ending completely
because there is a missing code in the end part of my program

Debugging:
Source line 1
 package printingvariablesandliterals;
 It is important to always encode the correct name of the
package to avoid such errors in a program. Because it is a
namespace that organizes a set of related classes and
interfaces. That Preventing naming conflicts.

Source line 4
 public class PrintingVariablesandLiterals {
 Always encode the proper and correct code that matches to the file
name when encoding a public class

Source line 7
 public static void main(String[] args) {
 public static void main
To avoid the error missing java doc it is important to be mindful in
spellings. The main in the starting point of the program is fixed
 (String[] args) { is the correct code in source line 7. There is no
Strng code in the source code program.

Source line 8
 Double number = 40.7;
 The program can’t interpret the nmber because it is not the right
code. It is misspelled it should be number.
 The underscore (_) must be replace with equal sign (=) to properly
declare the variable of the double number.

Source line 9
 System.out.println(8);
 In declaring a method in a class it is always followed by open and
close parenthesis () to complete the statement.
 While in each program there is only one statement required I each
line programs that is why only one semicolon is enough to declare a
statement in each source line program.

Source line 10
 System.out.println(number);
 Only one open and close parenthesis is required when declaring a
method. It will cause error if some of the symbol got doubled in each
source line.

Source line 12
 }
 The reason why there’s an error in the line 11 because I didn’t
completely ended the program. In each open curly braces it should
be partnered by close curly braces

1.6.4. Print Concatenated Strings

Merging a variable using the + operator to perform a


combination of multiple strings.
Program errors:

 invalid method declaration; return type required (5)


because of the comma an error arose in the source line 5
 incompatible types: int cannot be converted to double (6)
Because of the wrong encode of variable an error shows. We declared a
double number but then we encoded an int variable.
 ; expected (6)
The source line can’t be declared as a statement because of the missing
semicolon.
 unextpected type (9)
Because of incorrect operator this error arouse.
 bad operand type string for a unary operator (9)
This error shows because of the improper use of operators. A compile-
time error when both types of operands are incompatible
 unclosed string literal (9)
When performing so much combination of multiple strings it is hard to
identify where we made a mistake. And there’s a possibility of having
an unclosed string literal.
 Illegal start of expression (10)
This error shows because Java compiler finds something inappropriate
with the source code at the time of execution. And at this source line
the error is the period after the println.
 not a statement (10)
This error shows because the declaration of calling a method is not
appropriate.
 unextpected type (10)
An unexpected type arouse when something is not right while declaring
the operator in a source code.
 class, interface, enum, or record expected (14)
This error shows because there is an excess close curly brase (}) at the
end of the program.

Debugging:

Source line 5
 public static void main(String[] args) {
 Knowing the correct source code is important specially in this
source line because this is the starting point of the program.

Source line 6
 Double number = 44.8;
 In declaring a variable it is important to insert or include the
correct type that we declared. The program will not be executed
properly if we encode a variable that is different to its type.
 In every source line it is important to put a semicolon (;) to declare
it as a statement. but if we are going to declare the start and end of a
program it should be open and close curly braces ([])
Source line 9
 System.out.println("I am " + " in " + " danger please " + " help me!
" );
 Encoding the correct operator will help us to avoid such errors.
The reason why we are inserting a plus sign (+) operator this program
is because it is used to emerge multiple string.
 In every string both open and close quotation mark (“”) is
important to declare it as a string.
Source line 10
 System.out.println("Number = " + number);
 Removing the period after the println will solve the first error in
source line 10 because a period is not included in the source code
and it is against the syntax rule of the java programming.
 The reason why not statement shows in the second error of this
source line is because I made a mistake in calling a method. It
should be open and close parenthesis () and not open and close
brackets []
 The last error shows because I mistakenly insert the plus sign
operator (+) instead of equal sign (=)

Source line 13
 }
 In this source line debugging method. To successfully resolve the
error. I remove the close curly brace in source line 14. Because in
each declaration of curly braces they should be partnered.

1.6.5. Get Integer Input From the User


A method where the scanner class will get an integer input from the
user.

Program errors:

 Unused import (2)


This program error shows because I imported the package with a
misspelled source code, and because of so many mistakes the program
thought that I didn’t used it in my program.
 empty character literal (3)
This error shows because of the unexpectedly apostrophes (‘’) beside the
open curly brace ({)
 missing method body or declare abstract (5)
Because of the missing open curly brace ({) my program can’t execute a
starting point of my program.
 no suitable constructor found for scanner (printstream) (6)
Because of wrong source code this program error arouse. The source code
that I encoded is not appropriate.
 may split declaration into a declaration and assignment (6)
This error showed because there is something wrong in declaring the
source code in line 6 the comma (,) should be a period (.)
 new instance ignored (6)
Because of the wrong declaration of operator the program interpret that I
am ignoring the mistakes that I did in the source line 6
 illegal start of type (7)
Because of inappropriate execution in the starting point of the program line
7 was affected.
 not a statement (8)
Because of a missing source code the program can’t declare the source line
as a statement.
 unexpected type (9)
The error pertains to the wrong declaration of operator in source line 9.
 class, interface, enum, or record expected (11)
This program error shows because there is a missing open curly brace ({) in
the source line 5 the starting point of the program.

Debugging:
Source line 2
 import java.util.Scanner;
 In each program there is always a syntax rule and it is important
to follow it. The debugging code in this source line is in the first
bullet. The reason why this source line had an error because instead
of Scanner the source code that I encode is Scaner. It was misspelled
and the other thing is that because of so much mistakes in my
program I didn’t had a chance to import in my program.
Source line 3
 public class GetIntegerInputFromtheUser {
 To resolve the error in this source line. I remove the apostrophe (‘’)
to declare the appropriate source code.
Source line 5
 public static void main(String[] args) {
 The reason behind this error is because the open curly brace ({) is
missing where in the execution of the starting point of the program
can’t continue successfully.
Source line 6
 Scanner scan = new Scanner(System.in);
 The reason behind the error “no suitable constructor found for
scanner (printstream)” in the source line 6 is because I change the
declaration into System.in instead of out.
 The 2nd error is the “may split declaration into a declaration and
assignment” it is because of the wrong source code. Instead of
System.in I declared it as System,out
 The last error in this source line is the “new instance ignored” the
solution in this error is that replacing the wrong operator which is the
plus sign (+) into equal sign (=) to make it right.
Source line 7
 System.out.print("Enter an integer: ");
 There’s nothing wrong in the declaration of source code in this
source line. An error arouse here because of inappropriate execution
in the starting point of the program.
Source line 8
 int number = input.nextInt();
 By encoding the complete source code in this program the
statement will be complete. The missing source code in this source
line is the number.
Source line 9
 System.out.println("You entered " + number);
 By replacing the equal sign (=) into plus sign (+) operator the error
in this source line will be resolve.
Source line 11
 }
 There is nothing wrong in this source line. If we resolve the error in
source line 5 which is the missing open curly brace ({) or start point of
the program. This source line will be resolve.

1.6.6. Get float, double and String Input


A method where the scanner class will get a float, double and string
input from the user.
Program errors:
 incorrect package (1)
There is something missing in this source line program that is why the
error incorrect package shows.
 illegal '.' (8)
The declaration of the source code is not appropriate. My encoding doesn’t
comply with the syntax rule of the java language.
 variable inpt is never read (8)
This error arouse because of my misspelled code.
 Illegal start of expression (8)
At the last part of this source line program. Beside the semicolon (;) there is
a comma (,) that is why an error arouse. It shouldn’t be there because the
comma (,) is not included in the source code of the program.
 Source line 9 ( Illegal start of type)
There is nothing wrong in this line program. But because there are so
many mistakes in the source line 8, this source line program got affected.
The program is telling me that I continued in encoding in this line program
even though there is a mistake that is why illegal start of type showed.
 variable myChar is never written to (10)
Because of inappropriate operator, the program can’t accept the variable
that I encoded because I made a mistake in declaring the correct flow of the
statement.
 Source line 11 & 13 (Illegal start of type)
Again, there is nothing wrong in this line program. But because there’s an
error in the source line 10 which was the wrong encode of operator. The
program can’t accept the statement that I am declaring. While the issue in
source line 13. The declaration of my source code is correct but then
because I still continued to encode even though there is an error in the
upper parts of the program the program is reminding me that I started to
encode again and it result illegal start of type.
 cannot find symbol (14)
Because the program is a key sensitive, even small changes can cause an
error. I forgot to capitalize one of the letters in the name of the variable that
I declared that is why this error shows.
 unexpected type (15)
Because of wrong operator, this error showed. The program can’t
understand my declaration because it doesn’t comply in the syntax rule of
the program.
 unclosed string literal (15)
The program can’t execute my declaration because there is something
missing in the source code.
 Source line 17 (illegal start of type)
This is the step in the program where the program will get the input from
the user. But then, this step can’t be execute because there is something
wrong in the declaration of the program. In this source line it is supposed
to get a double input from the user. But because there’s an error in the
source line 15 the program can’t proceed to this step.
 variable mystring is never read (18)
As what I said, programming is a key sensitive, I encoded a miss capitalized
code that is why this error arouse. And the other thing is, because there’s
an error in the right spelling of input in line 8 this source line also got
affected.
 illegal start of expression (19)
Because of the period (.) it caused illegal start of expression. The program
didn’t understand my declaration because it doesn’t comply in the syntax
rule of the java language.
Debugging:
Source line 1
 package getfloat.doubleandstringinput;
 In encoding a package it is important to encode the right source code to
avoid such errors. Having a package is important because it is use to avoid
name conflicts,
Source line 8
 Scanner input = new Scanner(System.in);
 The first error that I encountered in this source line is the variable inpt is
never read. Because of misspelled code the program can’t read or interpret
my encode source code. The right code is input.
 The second error that I encountered is the illegal start of expression. The
program is reminding me that there is something wrong in my declaration
that caused an error. And it can’t be accepted as a statement. In every
source line we are putting semicolon (;) at the end part to declare it as a
complete statement. But if there’s any small symbol that inserted, the
program will not accept it because the program can’t understand why
there’s a comma (,) in this source line. It doesn’t comply with the syntax
rule of the program.
Source line 10
 String myChar = input.next();
 I replace the plus sign (+) into equal sign (=) to correct the error.
Source line 14
 double myDouble = input.nextDouble();
 I capitalized the small letter d in the input.nextdouble because it is the
appropriate source code in this source line program.
Source line 15
 System.out.println("Double entered = " + myDouble);
 The purpose of this source line is to get a double data type input from
the user. The first error that I encountered here is the unexpected type, it
is because of the wrong operator. It should be plus (+) and not equal sign
(=).
 While the second error that I encountered is the unclosed string literal,
where I forgot to put close quotation mark to create it as a string.
 Source line 18
 String myString = input.next();
 In naming a variable it is important to be consistent in encoding it. The
program won’t accept the codes that we will encode if they are always
constructed in different ways.
Source line 19
System.out.println("Text entered = " + myString);
The Java compiler finds something inappropriate with the source code at
the time of execution. And at this source line the error is the period after
the open parenthesis.

1.7 Java Expressions & Blocks


Created to produce a new value. Expressions are built using values,
variables, operators and method calls. A block of code holds any number
of statements that you need to keep together

1.7.1. Java Blocks


A group of statements (zero or more) that is enclosed in curly braces
Program errors:
• Empty statement (7)
Putting a semicolon in the end of the line program we declare it as a
complete statement in this part the semicolon was doubled that is why
this error shows.
• incompatible types (9)
The reason behind this source line error is because of the inappropriate
operator.
• comparing strings using == or != (9)
The program is suggesting to use equals and reverse operands.
• not a statement (10)
The calling method in this source line is inappropriate that is why this
error arouse.
• reached end of file while phrasing (13)
This error shows because the program is not ended properly.

 Incorrect package (1) there is something added in this source line


program that is why the error incorrect package shows.
 initializer can be static (3) the program error pertains to the doubled
open curly braces ({)
 illegal start of expression (5) because of the error in the declaration of
public class. The starting point of the program got affected even though
there is no incorrect source code.
 Unclose string literal (7) the string was not execute properly because of
inappropriate source code.
 Variable block is neither read or written to (12) the source line 12 was
supposed to be an ending point of the program but then because of
inappropriate source code of inserting a comment it caused an error.
Debugging:
Source line 7

 String band = "Beatles";


 In each statement only one semicolon (;) is required to declare a source
code as a complete statement.
Source line 9
 if ("Beatles".equals(band)) {
 In this source line the program suggested to convert my source code into
use equals and reverse operands. It is because the == checks if both
objects point to the same memory location whereas. Equals () evaluates to
the comparison of values in the objects
Source line 10
 System.out.print("Hey");
 In calling a method open and close parenthesis () is the appropriate code.
Source line 14
}
To successfully end the program encoding one more close curly brace (}) is
the solution because in the upper part of the program there are three open
curly braces ({), meaning there are 3 groups inside the program. In each
group there must be both 1 open and close curly braces {}

Source line 1
 package javablocks;
 In encoding a package it is important to encode the right source code to
avoid such errors. Having a package is important because it is use to avoid
name conflicts,
Source line 3
 public class JavaBlocks {
 in every start and end of the program only 1 open and close curly braces
({}) is required in every group.
Source line 5
 public static void main(String[] args) {
Source line 7
 String band = "Beatles";
 In creating a string it is important to put open and close quotation mark
(“”) in the beginning and end of the string.
Source line 12
} // end of block
In inserting comments in programs its important to make sure that the
source code is correct so that the program wont misinterpret the codes.
1.8 Java Comment
1.8.1. Single-line Comment
Single-line comments allow narrative on only one line at a time.
Program errors:

 ; expected (1) this source line error arouse because of the wrong declaration.
 class JavasinglelineComment is public, should be declared in a file named
JavasinglelineComment.java (3) The class name is not match in the file name
of the program that is why I encountered an error.
 illegal start of expression (7) Because of the wrong declaration in creating a
comment this line error showed.
 Unclosed string literal (7) the string was not execute properly because of
inappropriate source code.
 void cannot be dereferenced (8) The program mistook my mistyped as
accessing or retrieving the value pointed to by a reference.

Debugging:

Source line 1

 package javasinglelinecomment;
 The reason why semicolon (;) is the correct code in this source line is because I
am just declaring a statement about the package name of the program. Open
curly brace ({) is used as a starting point of the program.
Source line 3

 public class JavaSinglelineComment {


 Always encode the proper and correct code that matches to the file name when
encoding a public class
Source line 7

 // prints "10 errors?, 10 errors!"


 In inserting a comment the correct code for it is encoding doubled slash sign
(//) at the beginning.
 While in creating a string always put open and close quotation mark (“”) in the
beginning and end of the code.
Source line 8

 System.out.println("10 errors? , 10 errors! ");


 To resolve the misunderstanding just remove the period (.) after the closing
parenthesis ‘ )’ and before the semi colon (;)
1.8.2. Multi-line Comment
Used for large text descriptions of code or to comment out chunks of code
while debugging applications.

Program errors:

 Unclosed comment (3) The closing code of comment is missing


 reached end of file while pharsing (14) because of the unclosed comment
the program interpret my whole source code as a comment.

 Missing Javadoc (8) Because of the period the error missing Javadoc
arouse.

 class, interface, enum, or record expected (3&4) there is a missing code


in this line program that’s why this error arouse.
 reached end of file while pharsing (13) The program was not end properly
that’s why this error showed.
Debugging:

Source line 3
/* This is an example of multi-line comment.
* The program prints "Hello, World!" to the standard output.
*/

The source code for multi line is /***/. It is important to make sure that
we close the comment before proceeding to another source code. So

Source line 14 because of the unclosed comment this error arouse. There
is nothing wrong in the program. The debugging code here is to solve the
error in source line 3.
Source line 8

 public static void main(String[] args) {


 because of the period the declaration of the source line code caused an
error. The only solution for it is to remove the period (.)
Source line 3&4
/* This is an example of multi-line comment.
* The program prints "Hello, World!" to the standard output.
*/

The source code for multi line is /***/. The missing source code in this
source line is the asterisk (*).

Source line 13

 }
 the program was not ended properly and there is a missing close curly
brace (})

JAVA FLOW CONTROL


Statements can be executed multiple times or only under a specific condition.
Break up the flow of execution by employing decision making, looping, and
branching, enabling your program to conditionally execute particular blocks of
code.

2.1 Java if...else


Use else to specify a block of code to be executed, if the same condition is false.

Program errors:

Incompatible types: possible lossy conversion from double to int (6)


This error shows because there is a loss of information while handling data.
Where in the variable that the user encoded have different types.

Illegal start of expression (11)


The sub group of the program was not execute or ended properly because close
braces is not the source code to end a program or a particular group in a
program.

‘else’ without ‘if’ (14)


The reason behind this error is because the user didn’t end the if statement
properly that is why the program is unable to find an if statement associated to
the users else statement.

; expected (15)
The statement cannot execute properly because there is an error in encoding
the source code. There’s a code that shouldn’t be encoded.

Reached end of file while parsing (20)


This is because of a sub group in a program, particularly the if statement was
not ended properly.

Debugging:
Source line 6
Removing the period beside the int is the debugging method to correct the
source code of the source line 6. It is because to clarify and to declare that the
variable that we are declaring is an integer and not a double type.

Source line 11
The debugging method in this source line is replacing the close braces (]) into
close curly brace (}) to end the if statement and continue into the else
statement.

Source line 14
By correcting the source code in if statement, the error in this source line will
disappear. It is because Else statements do not work unless they are
associated with an if statement.

Source line 15
Removing the open and close parenthesis () is the debugging method to declare
the statement correctly.

Source line 20
This source line is also associated in the source line 11 if the user debug it and
ended the if statement properly the error in this source line program will also
disappear.
2.2 Java switch Statement

The switch expression is evaluated once. The value of the expression is


compared with the values of each case. If there is a match, the associated block
of code is executed. While when the break statement is reached the switch
terminates, and the flow of control jumps to the next line.

Program errors:

Illegal start of expression (7)


Because the string size statement was not declared properly that is why this
error arouse. The user encoded an excess and wrong code at the end part of
the statement. That is why the program can’t execute it properly.

Convert switch to rule switch (9)


The program is requesting to convert my encoded source codes into rule
switch.

The assigned value is never used (12, 16, 21, 25, and 29)
This error arouse because the user give a value but not reference it to its given
values in each cases (size)

Unreachable statement (32)


It refers to statements that won't get executed during the execution of the
program. Because there is something wrong or missing source code that
should be declared.

Reached end of file while parsing (34)


Because of a missing and an unclosed or a particular group in the program
was not ended successfully that is why this error arouse.
Debugging:

Source line 7
Removing the colon (:) beside the semicolon (;) is the debugging method in this
line program to successfully execute the declaration of string.

Source line 9
Because of some changes in each versions the developers are improving the
flexibility of programs when defining conditions especially for switch cases. By
the help of code assistant in NetBeans the source code that we encoded will
automatically convert the switch into rule switch.

Source line 12, 16, 21, 25 and 29


The debugging method in this source line errors is by putting a close curly
brace (}) after declaring all the cases. It is because the program will not execute
what we declared if the source codes is not complete. And for it to declare that
we are already done in encoding such cases.

Source line 32
The debugging method in this source line is also encoding the close curly brace
(}) at the end part of the cases. Because we all know that in programming it is
important to follow the process of encoding chronologically.

Source line 34
The debugging method in this source line program is again, the close curly
brace (}) at the end of declaring the cases.
2.3 Java for Loop
An entry-controlled loop that facilitates a user to execute a block of a
statement(s) iteratively for a fixed number of times.

Program errors:

Illegal character ‘`’ (4)


Because of the back tick mark (`) before the source code public static void main
(String[] args) { an error arouse because it is not included in the source code of
the opening point or starting point of the program.

Illegal character ‘\’ & not a statement (5)


The declaration of comment in the mentioned source line is improper
that is why an error arouse.

Variable n is never read (7)


Because of improper declaration of operator in source line 9 the program can’t
identify the purpose of the variable n that the user encoded.

The assigned value is never used (9)


Because of improper declaration/ encoding of operator it causes an error.

Unclosed string literal (10)


Because of missing close quotation mark (”) an error arouse.
Debugging:

Source line 4
The debugging method in this source line is by removing the back tick mark (`)
to correct the source code of the starting point of the program.

Source line 5
Replacing the back slash (\\) into forward slash (//) is the debugging method
to declare the source line as a comment.

Source line 7
To debug this source. The user must debug first the error in source line 9. For
the program to be able to ready the variable that the user declared.

Source line 9
The debugging method in this source line is replacing the equal to less than
(=<) into less than is equal to (<=) because it is the proper way to declare the
operator.

Source line 10
By putting a close quotation mark (”) at the text (“Java is fun”) we can finally
declare that it is a string.
2.4 Java for-each Loop
Can only be used on a collection of items. It will loop through the collection
and each time through the loop it will use the next item from the collection.

Program error:

Illegal start of type (4)


An error arouse because the user didn’t encode the proper way of declaring a
comment.

Incompatible types: possible lossy conversion from double to int (7)


Inserting a period beside an integer type of data will surely cause an error
because the program will misinterpret that the user’s declaration is in double
type and not int type of data or variable.

Illegal start of expression (10)


Because of wrong source code in declaring a method or constructor an error
arouse.

Variable number might not have been initialized (11)


Because of wrong declaration for each loop the variable number become not
been initialized.

Reached end of file while parsing (13)


The ending part of the program is not ending properly. There is a missing close
curly braces (})
Debugging

Source line 4
In declaring a comment the source code should be start with two forward slash
(//) for the program to ignore it.

Source line 7
The debugging method in this source line program is by removing the period
beside the variable to declare it as an integer.

Source line 10
The proper way in constructing or declaring a method is by changing the open
and close braces [] into open and close parenthesis.

Source line 11
When the user debug the error in source line 10 the error in this source will
also disappear.

Source line 13
By adding one more close curly braces (}) it will resolve the error and the
program will be ended properly.
2.5 Java while Loop

A control flow statement that allows code to be executed repeatedly based on a


given Boolean condition.

Program errors:

illegal start of type (4)


Because of importing a scanner that shouldn’t not be included on the program,
it causes an error.
method main(String[]) is already defined in class javawhileloop (7)
In declaring and encoding the starting point of a program it is important to
check first if it is already encoded or not because it might be doubled and
cause an error.

Incompatible types: possible lossy conversion from double to int (9)


Inserting a period beside an integer type of data will surely cause an error
because the program will misinterpret that the user’s declaration is in double
type and not int type of data or variable.

Illegal start of expression (14)


In encoding a starting point of a sub group it is important to encode the correct
code. An error will arouse if we inserted the wrong code to open or start
another group inside a program.

invalid method declaration, return type required (17)


Because of the misspelled code the error arouse.

class, interface, enum, or record expected (23)


This error arouse because there’s an error in the open or starting point of the
program.
Debugging

Source line 4
The debugging method in this source line program is by removing the imported
scanner.

Source line 7
Removing the excess starting point source code is the debugging method in
this source line.

Source line 9
Remove the period beside the variable to declare it as an integer.

Source line 14
Replacing the open braces ([) into open curly braces ({) is the correct code to
start or open another sub group in the program.

Source line 17
The debugging method in this source line is correcting the spelling of the
misspelled source code. Which is the “while”

Source line 23
Debugging the source line 14 will also resolve the error in this source line.
2.6 Java break Statement

It is used to terminate loops and switch statements in java. When the break
keyword is encountered within a loop, the loop is immediately terminated and
the program control goes to the next statement following the loop.

Program errors:

Cannot find symbol (4)


Programming is key sensitive, every small detail needs to be correct. In this
source code the reason why an error arouse is because there is a code that
supposedly capitalized, that is why the program cannot find its symbol because
it is not the correct code that follows the syntax rule of the program.

Not a statement (7)


The operator that the user encoded is incorrect that is why an error shows.

Illegal start of expression (12)


The code for ending a particular sub group in the program is improper that is
why an error arouse. The program can’t execute it properly because the code
that the user encoded is incorrect.

; expected (13)
The program can’t execute the mentioned source line because there is a
missing code to declare it as a statement.

Illegal start of type (17)


This error shows because the program was not ended properly. The code that
the user encoded to end the program is incorrect.
Debugging:

Source line 4
The debugging method in this source line is to capitalized the S to make it
String. Because it is the proper code to declare the starting point of the
program.
Source line 7
To debug this source line error. Encoding the correct code of operator is the
solution. ++i is the correct code to declare a increment operator.
Source line 12
Replacing the close braces (]) into closing curly brace (}) is the debugging
method in this source line program to end a sub group in a proogram.
Source line 13
In each source line, when declaring a statement it is important that always
ends it with the semi colon (;). So that, the program will interpret that the user
is already done in that particular source line.
Source line 17
To end a program close curly braces (}) is the correct code to complete and end
a program.
2.7 Java continue Statement

Breaks one iteration (in the loop), if a specified condition occurs, and continues
with the next iteration in the loop.

Program errors:

Incorrect package (1)


The reason behind this error is because of a misspelled word in the name of the
package that is why this error shows.
Class JacacontinueStatement is public, should be declare in a filename
JavacontinueStatement.java (3)
This error arouses because the declared code in the program is not match in
the file name that the user inserted.
Initializer can be static (6)
The program finds something wrong in this source line that’s why it cannot be
execute. The code for calling a method or the declaration of constructor is
incorrect.
Illegal start of expression (11)
The program misinterprets this source line as another statement and not a
comment that is why an error arouse.
; expected (16)
Colon (:) is not the correct code to declare a statement.
Debugging:
Source line 1
Correcting the misspelled word in the name of the package is the debugging
method in this source line.
Source line 3
The user must ensure that the filename and the source code in declaring the
name of the public class is match to avoid such errors. Always check for the
letters that must be in uppercase and lowercase. Because programming is a
key sensitive.
Source line 6
To declare a method open and close parenthesis () is the correct code.
Source line 11
The correct source code for declaring a comment is encoding a two forward
slashes (//) for the program to ignore it and not to misinterpret it as another
statement.
Source line 16
In each source line, when declaring a statement, it is important that always
ends it with the semi colon (;). So that, the program will interpret that the user
is already done in that particular source line.

You might also like