Chapter 2: Elementary Programming Flashcards
What is an algorithm?
A well-defined sequence of steps that goes over the outline of your program.
What is the “Main Method” in a Java program?
It is the entry point and spot where your program begins execution.
What is a variable?
A value stored inside the computer’s memory.
How do you connect a string that takes up multiple lines?
At the end of the first line, use “+” and then continue the string on the next line.
How do you create and read a new System.in input value?
Use the Scanner class to create an object. import java.util.Scanner; Scanner input = new Scanner(System.in);
Explain the difference between a wildcard import and a specific import.
A wildcard import will import ALL the classes in a package while a specific import will only import the single class that is specified from the package. There is no performance difference.
Explain an Identifier.
An Identifier is the name of anything that appears in your program (class, method, integer, etc.) It must start with a letter, _, or $, but can’t start with a digit.
Explain a variable.
A value in your program that can be changed. A variable must be declared and initialized before it can be used.
What is a named constant?
An identifier that represents a value that is permanent. It can’t be changed.
List the numeric operators of Java.
Addition (+), Subtraction (-), Multiplication (*), Division (/), and Remainder (%).
Name some uses of the Remainder operator.
It can be used to determine whether a number is even or odd. You can also use it as a way to find out what day of the week you will be on in a certain number of days using a remainder of 7.
How to compute exponents?
You can use the Math.pow method from the Math class of the Java API.
Value a is the base, value b is the exponent.
EG: Math.pow(a, b);
What is JShell?
JShell is a command line tool that allows you to quickly evaluate an expression or executing a statement without making an entire class.
What are increment and decrement operators?
They will add or subtract the value by 1. The increment operator is (++), and the decrement operator is (–).
Explain type casting.
Type casting is converting one value type to another within the program. Java will automatically widen types for you, but narrowing types must be done yourself.