Week 1 - Intro to Java Flashcards
1
Q
Write a program that prints out “Hello World!”
A
public class HelloWorld {
—-public static void main ( String[] args) {
——–System.out.println(“Hello World!”);
—–}
}
2
Q
What to main types does Java have?
A
Primitive types
Non-Primitive types/Classes
3
Q
What are the primitive types?
A
- boolean - true/false
- char - ‘A’ ‘6’
- int - whole number
- short - small whole number
- long - larger whole number
- float - decimal number
- double - high precision float
4
Q
What are the non-primitive types?
A
- Classes
- Arrays
- Strings
- Interfaces
5
Q
What is scope of a variable?
A
Scope is where a variable can be used in a script. A variable can only be used inside the block in which it was declared.
6
Q
How do you create a variable?
A
In java variables have both a type and a name, so all variables must be declared before use.
int x;
int defines the type of variable and x is the name of the variable.