Good program design requires that each object and method have a well-defined role and clear definition of what information is needed for the task and what results will be produced.
Good program design is important; the sooner you start coding, the longer the program will take to finish. Good program design strives for readability, clarity, and flexibility.
An algorithm is a step-by-step process that solves some problem. Algorithms are often described in pseudocode, a hybrid language that combines English and programming language constructs.
A syntax error occurs when a statement breaks a Java syntax rules. Syntax errors are detected by the compiler. A semantic error is an error in the programβs design and cannot be detected by the compiler.
An identifier must begin with a letter of the alphabet and may consist of any number of letters, digits, and the special characters _ and $. An identifier cannot be identical to a Java keyword. Identifiers are case sensitive.
When it is executed it determines the value of the Expression on the right of the assignment operator (\(=\)) and stores the value in the variable named on the left.
Javaβs operators are type dependent, where the type is dependent on the data being manipulated. When adding two int values (7 + 8), the \(+\) operation produces an int result.
A class definition has two parts: a class header and a class body. A class header takes the form of optional modifiers followed by the word class followed by an identifier naming the class followed, optionally, by the keyword extends and the name of the classβs superclass.
Dot notation takes the form qualifiers.elementName. The expression System.out.print("hello") uses Java dot notation to invoke the print() method of the System.out object.
A Java source program must be stored in a file that has a .java extension. A Java bytecode file has the same name as the source file but a .class extension. It is an error in Java if the name of the source file is not identical to the name of the public Java class defined within the file.
public class OldMacDonald
{
public static void main(String args[]) // Main method
{
System.out.println("Old MacDonald had a farm");
System.out.println("E I E I O.");
System.out.println("And on his farm he had a duck.");
System.out.println("E I E I O.");
System.out.println("With a quack quack here.");
System.out.println("And a quack quack there.");
System.out.println("Here a quack, there a quack,");
System.out.println("Everywhere a quack quack.");
System.out.println("Old MacDonald had a farm");
System.out.println("E I E I O.");
System.out.println("Old MacDonald had a farm");
System.out.println("E I E I O.");
System.out.println("And on his farm he had a pig.");
System.out.println("E I E I O.");
System.out.println("With an oink oink here.");
System.out.println("And an oink oink there.");
System.out.println("Here an oink, there an oink,");
System.out.println("Everywhere an oink oink.");
System.out.println("Old MacDonald had a farm");
System.out.println("E I E I O.");
} // End of main
} // End of OldMacDonald
public class Pattern
{
public static void main(String args[])// Main method
{
System.out.println("**********");
System.out.println("* ** ** *");
System.out.println("* ** *");
System.out.println("* * * *");
System.out.println("* **** *");
System.out.println("**********");
} // End of main
} // End of Pattern