Test 1 Flashcards
What is the first part of any java class?
public class classname { }
Does indenting matter in Java?
No, but it is used to improve human readibility
What is the first thing you have to put into any java class?
the main method.
public static void main(String[] args){
}
What is a function called in java?
A Function is referred to as a method in Java
How do you create a single line comment in java?
//
How do you create a multi line comment in java?
/* * */
How do you create a javadoc?
/**
*
**/
what needs to go at the end of every line of code in java that doesn’t have a }?
;
similar to CSS
In java, What has to be stated for creating variables?
the variable has to have their data type declared, unlike python.
int x = 5 ** the variable x is now an integer type variable and can never be changed to a different data type**
Whats the first two things that needs to be done when dealing with user input in java?
You have to import the scanner utility by typing: import java.util.Scanner then Scanner input = new Scanner(System.in);
What are some of the methods used to use the scanner utility?
nextInt() and nextDouble() for numeric input, and next() to get a single word or nextLine() to get an entire line.
How do you use the equivalent to the print function from python in java?
System.out.println()
The single quote and double quotes are interchangeable in python, is that the case for Java?
No, the single quotes are used for the char datatype and represent one character, and the double quotes are used for strings and represent multiple characters.
What are the two forms of data types in java?
Primitive and Object(reference)
What is a Primitive data type?
primitive data types represent a single value, that has no attributes or methods
What is an Object(reference) data type?
Object data types represent chunks of data (fields) with code attached (methods)
How do you do integer division in java?
/ not like // in python.
How do you do the power of in java?
with the module Math.pow()
How do you convert types in java? and what is it called?
To convert types in java, you put the name in brackets in front of the expression. This is known as type casting, or casting for short. (int) 5.0 …… makes it 5
When creating a method, do you have to pass the type?
You only have to declare the type if the method is returning that type. ex. public int myMethod(){ } ……..
if there is no return then you simply replace the int above with void
in the method:
public void myMethod(){
}
what does the void indicate?
The void indicates that the method does not return any value.
What does the GET method do?
It returns something back to the class that is calling the method. so make sure you declare the proper data type that is being returned. (Read Access)
What does the SET method do?
it passes whatever parameter you are setting & defines a variable with no return. use void since there is nothing being returned. (Write Access)
Do constructors have a pass type?
No just leave it blank,, no void, not data type.
What happens if a set method is made private?
only other methods can call upon that method
Whats the difference between methods and constructors?
Constructors are defined as they are initiated and cannot be called upon later. Methods can be used as a tool later on.
How do you know when a method should be split into different methods?
When you can clearly see different parts of the method that could easily act on their own.
when do you want to make constant variable and how do you do it?
if you never want it to be changed again, and you use the final method ex private final double b;
What is the difference between these two statements?
c1.getB();
System.out.println(c1.getB());
the first one returns the location in memory of the object. ex. examReviewClass@5e2de80c
the second one prints the value inside of that variable in the method. ex. 4.5
What does the underlined items in a UML diagram mean?
it means they are static
what does static mean?
it can be accessed by the other classes without first creating an object.
what is the naming convention of a constructor?
it has to have the exact same name as the class it is in.
what is overloading a constructor and how does it work?
Overloading a constructor is basically building a bunch of different constructors with different possible scenarios for handling input. It allows someone to use the constructor and pass no parameters, or pass different types of parameters