Introductory Concepts in Java Flashcards
Who created Java?
Sun Microsystems
Describe the Structure of a call
It contains an access modifier followed by a class name and {} brackets with the main method in the class
public class MyClass { public static void main(String[] args) { System.out.println("Hello World"); } }
What is the main method in Java
It is the method that Java first looks for when to run a program
How do you add single line comments in Java?
Use two forward slashes to start a comment //
How do you do a multi-line comment?
It begins with a /* and ends with a */
What are variables in Java?
Variables are used to store data
what are 5 types of variables?
1 - String 2 - Int 3 - Float 4 - Char 5 - Boolean
How do you declare a variable in Java?
The basic syntax for declaring a variable is Data Type Name of Variable = Value of Variable
A specific String Variable String firstName = “Doug”;
What happens when you add the keyword final to the start of a variable?
It makes it no longer possible to change the value of the variable
How do you display the value of the variable?
Here is the specific example
String firstName = “Bob”;
system.out.println(firstName);
You would use the printLn method and use the name of the variable.
What is the best way to declare multiple variables with the same type?
Use a comma separated list
String firstName = “Bob”, firstName2 = “Mary”, firstName3 =”Terry”;
what are some tips to naming variables?
1 - Choose names that help describe the purpose of the variable
2 - Can’t use reserved words
3- Can use letters, underscore and dollar sign
4- Needs to start with a lower case letter
What are the two groups of variables?
1 - Primitive
2- Non-Primitive
What are the primitive data types?
1- Byte 2- Short 3 - Int 4 - Long 5 - Float 6 - Double 7 - Boolean 8 - Char
What are the non-primitive types?
1 - String
2 - Array
3 - Class
What are the two groups of the number data type?
1 - Integer
2 - Floating Point Types
What are the two values of the boolean data type?
1 - True
2 - False
What is the char Data type?
1 - It represents one character and is surrounded by quotes.
For example
Char myChar = “b”;
What is type casting in Java?
It is going from one value to another value in primitive type.
What are the two types of casting?
1 - Widening
2 - Narrowing
What are the groups for operators in Java?
1 - Arithmetic 2 - Assignment 3 - Comparison 4 - Logical 5 - Bitwise
What is the syntax to designate a String data type?
String name = “Bob”;
What are some of the most popular String Methods?
1 - toUpperCase()
2 - toLowerCase()
3 - indexOf()
What is the Math Class?
The math class has many built in Math Methods that help perform many different Math functions.