Basics of Java Flashcards
What is Java?
a programming language that allows you to provide instructions to a computer, and with which you can create computer programs
Java compiler
translates Java code into machine or computer language so the computer can execute the program
How to delineate a single line and multi line comment?
single line comment //
multi line comment /…/
How to name the program?
class Main {…}
tells Java the name of the program is Main
What is the main method?
static public void main (String[] args)
this statement is called the main method and should be included in every Java program. Tells the compiler this is the beginning of the Java program. ‘public’ and ‘static’ can be interchanged.
Is syntax important in Java?
proper syntax is essential or the program will not run.
What is an executable statement?
code that produces output
statements in Java must end with a semicolon;
What does public mean in
static public void main (String[] args)
means that any object can use the main method
What does static mean in
static public void main (String[] args)
means that the main method is a class method, also means you can access this method without having an instance of the class
What does void mean in
static public void main (String[] args)
tells Java the main method won’t return a value. Other methods in other classes can receive and return values/variables, but main cannot return anything
What does main mean in
static public void main (String[] args)
the main method is responsible for calling any other methods within the program. This is the first thing the compiler looks for in the program.
What does string args in
static public void main (String[] args)
sets up the main method to accept parameters, once packaged and distributed users can specify arguments to pass to the main function
What is one argument the main method takes?
an array of string elements
(String[] args)
What does args do in
static public void main (String[] args)
holds the actual parameters passed in
What are java statements?
instructions that tell the programming language what to do
What is an assignment statement?
assigns a value to a variable
What is a Java method?
blocks of code that perform a task and can be used by other parts of a computer program such as a declaration statement.
What are the core Java statements that end in curly brackets instead or semicolon?
if statement
while statement
for loop statement
What is the difference between rules and conventions in Java?
Rules are hard and fast: your program won’t compile or run if you violate the rule. Conventions are practices that most Java programmers follow.
What are keywords?
words that have a predefined meaning for the language
Rules of naming variables:
- variables are case sensitive
- cannot be Java keywords
- main/Main is not a keyword in Java
- no spaces in variable names
Naming conventions for constants:
- convention: use uppercase with underscore
final FIRST_NAME = “Sandy”; - rule: constant names cannot be Java keywords
- rule: constants cannot have spaces
Naming convention for classes and interfaces:
Capitalized nouns, each word capitalized
Employee, UnionEmployee, Remote
Naming convention for methods:
lowercase verbs
public void enterData() {}