INTERMEDIATE PROGRAMMING. Assessment.
INTERMEDIATE PROGRAMMING. Assessment.
1. Analyze and review your Java Program Coding and Debugging of each item.
Reference:
https://www.programiz.com/java-programming/examples
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 {
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.
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) {
Source line 7
System.out.println("LOUISE");
Source line 9
System.out.print("LOUISE");
Source line 10
System.out.print("GAB");
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:
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
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.
Program errors:
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.
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
Program errors:
Missing Javadoc (8) Because of the period the error missing Javadoc
arouse.
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
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 (})
Program errors:
; 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.
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
Program errors:
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)
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 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:
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:
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
Program errors:
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:
; expected (13)
The program can’t execute the mentioned source line because there is a
missing code to declare it as a statement.
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: