Loading presentation...

Present Remotely

Send the link below via email or IM


Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.


TEST 1 Study Buddy

Intro to Computer Science Study Questions with explanations, examples and references.

Sarah Welty

on 26 September 2017

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of TEST 1 Study Buddy

Test 1 Study Buddy

What would the following print out?

>System.out.println("The cat jumped " + 1 + 4 +" feet high.");


The cat jumped 14 feet high

Java concatenates (combines) strings together with the use of + operator symbol.
The + sign tells Java that the following is also a String and should be listed exactly as written, no spaces.
You would need to use parenthesis to do any additional arithmetic in Strings, such as (1+4) which would output a 5 instead of 14.

Reference: Chapter 2 Page 24

What would the following print out?

>System.out.println("The cat jumped " + 9 + 5 + " feet high");


The cat jumped 95 feet high

Java concatenates (combines) strings together with the use of + operator symbol.
The + sign tells Java that the following is also a String and should be listed exactly as written, no spaces.
You would need to use parenthesis to do any additional arithmatic in Strings.

Reference: Ch 2, pg. 24

What would the following print out?

> double shoeSize = 9.5;
>System.out.println("My shoe size is " + shoeSize + ".");


My shoe size is 9.5.

You can declare a variable and then use the System.out.println function to print out not only Strings, but also the variable definition itself.

Reference: Chapter 2 Page 24

How many objects can be created from a class definition?

A) 10
B) Infinite
C) 312
D) 8
Answer: B Infinite
Reference: Chapter 2 Page 15
You can create an unlimited number of objects in your class (depending on your memory availability).
You have a class called DriversTraining You want to create a new object from this class, and the constructor requires that when you create the object, you have to enter the years of driving experience as a double.
How would you create a new DriversTraining object with 9.5 years of experience?
A) DriversTraining myExp = new DriversTraining();
B) myExp = new DriversTraining(9.5);
C) DriversTraining myExp = (9.5);
D) DriversTraining myExp = new DriversTraining (9.5);
Answer: D
DriversTraining myExp = new DriversTraining (9.5);
To create an object, ask the class to create and initialize a new object. This is also called creating an instance of a class or instantiating an object.
Reference: Chapter 3 Page 69
<className> <objRefVar> = <newKeyword> <constructorName(parameters)>;
ITSC 1212
An object is an instance of a/an:
A) Method
B) Constructor
C) Class
D) Field
Answer: C

A class in Java tells the computer what data we expect objects of that class, to have and what they can do.
A class is like a factory where objects are created.

They are like a cookie cutters (class) creating cookies with the same basic ingredients and shapes (cookies).

Reference: Chapter 3 Page 41
Data Types
Which of the following is not a primitive data type?

A) int
B) byte
C) literal
D) boolean
C) Literal

There are 8 primitive data types in Java. They are: char, byte, int, short, long, float, double, boolean.

Reference: Chapter 2 Page 23
How would you declare an int variable named size and assign it the value 30?
Data Types
int size = 30;
Reference: Chapter 2 Page 25
Question 7
Data Types

True or False: You should use the char data
type in storing letter grades you make in a course.

When you declare a variable in Java you specify the type for the variable and a name(type name).
You need to specify a type so Java knows how many bits to reserve in memory and how to interpret the bits.

To declare and initialize a variable, you need the <dataType> <refVarName> = <setAmount>;
What would be the outcome if the following was entered into the interaction pane?

>System.out.println((double) 1/2);

A) 1
B) 0.5
C) 1/2
D) 0.0

Answer: 0.5
Java casts the numbers as a double before doing the division.

Here is what would have happened if you put the division into parenthesis as well:
Notice you lose your .5 by not casting before the division.
>System.out.println ((double) 1/2);
Answer: True
Char data types are single character (one keystroke) values and must use SINGLE parenthesis when defining them.

Here is an example:
Reference: Chapter 2 Page 34
>char grade1= ‘A’;
>System.out.println("I made an " + grade1 + " in my math class.")
I made an A in my math class.

Practice these in your Dr Java interactions pane!
>System.out.println ((double) (1/2));
Reference: Chapter 2 Page 24
What is casting?

A) Turning one data type into another.
B) A way to change the variable completely.
C) What happens when a data types breaks a limb.
D) No answer text provided.

Answer: A
Reference: Chapter 2 Page 34
Casting is used to change the type of one data type to another.

Look at this example:

You casted the int into a double by referring to the 2 as a (double). This allowed the decimal point to be kept.
>System.out.println ((int)(3) / (double)(2));
Which of the following is the proper way to declare a main method?

A) private main(String []) {...}
B) public main method() {...}
C) mainMethod(String [] args){...}
D) public static void main(String [] args){...}

Main Method
Answer: D
Reference: Chapter 11 Page 366
public static void main(String [] args)
A main method is used to create objects and invoke methods.
Here's why:

String [] args-
A main method

must take an array of String objects as a parameter(it doesn't matter if you call the array of Strings args or some other name. (NOTE: args is the conventional standard)

so that it can be called by objects of other classes.

because no objects of the class exist when you start execution of the method.
Answer: C
Reference: Chapter 3 Page 70
If a method does not return a value, what has to be a part of the method signature?
A) return

B) int

C) void

D) string
If a method does not return a value, use the keyword "void" as the return type.

For example:
public static void myMethod() {
System.out.println("I do not return anything, but I still do work.");
Answer: B
How are parameters separated?

A) Spaces only
public static void updateName( int number String name){.....}

B) Commas
public static void updateName( int number, String name){.....}

C) + signs
public static void updateName(int number + String name){.....}
Parameters are separated by commas.
public static void updateName(int number, String name)
Reference: Chapter 3 Page 70
Arguments vs Parameters:
A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters.
Argument is the actual value of this variable that gets passed to function.
Which of the following would give you an error, assuming everything in the brackets is correct?

final class myClass {…}

class myClass
final void doStuff() {…

> final int BAGS = 5;
> BAGS = 7;

All of the above
The answer is C because you can not change the value of a constant (final) outside of the declaration statement.

You can set a method, variable or class to final.
If you set a class to final, it can not be extended.
If you set a method to final, it can not be overridden.
Answer: C
Reference: Chapter 3 Page 31
In the following code, identify the literal:

public static void main (String [] args){
int myNumber = 500;

Answer: 500
Reference: Chapter 3 Page 30
Literals are syntactic representations of boolean, character, numeric, or string data.
True or False:
The constructor must be named after the Class.
Answer: True
The constructor must be named after the Class.

The constructor here is saying, to create a new Dog object, you need to pass in the breed of the dog, in String form in order to create an object of the Class Dog.

The constructor may look slightly like a method, but it is not. A method always has a return type (void, String, int.. etc)
public class Dog {

public Dog (String breed) {…..}
//end of class Dog
Assume you have the following method declaration in a class called Groceries:

public class Groceries {
private double foodPrice;

public void updatePrice(double newPrice) {
foodPrice = newPrice;

If you created a Groceries object called newPrices2017, how would you change its price to $4.80?
You must call on the object(instance) of the class created, followed by the method you are able to access and provide an argument in the form of a double, in this case 4.80
Answer: 1
If you typed the following code into the interactions pane:
>World w = new World()
>Turtle a = new Turtle(w);
>Turtle b = new Turtle(w);
>Turtle c = new Turtle(w);
>c = b;
>c = a;
>b = a;
How many turtle objects are there?
Each Turtle object is set to equal the one same object.
Once you set that variable to point to that object, it no longer acknowledges the old object.
So by 'c=b' b is now pointing to c.
When 'c=a' a is also now pointing to c.
Lastly when 'b=a' They are already pointing to the same c object, so there is only one object.

All of the pointers (variables) point to c.

True or False:
A constant variable has to be capitalized for Java to recognize it.

Answer: False
The variable does not HAVE to be capitalized, it is common in the Java language though to be easily recognizable in all CAPS.

For example:

Reference: Chapter 3 Page 31
final int NUM = 5;

final double GPA = 3.5;
Imagine you have created a method in the Turtle file to draw a hexagon called drawHex. In your main program, you have created a world, w and a turtle, tom in that world. How would you make your turtle draw a hexagon?
A) tomdrawHex()
B) tom.drawHex();
C) Turtle.drawHex(tom);
D) tom = drawHex();
Answer: C
To make your Turtle tom execute a method such as, drawHex, you have to call to the method as so:
Reference: Chapter 3 Page 70
A special method that is called just once when a new object is created is called a:
When you create a new object of a class, it uses a constructor, (listed in that class) to produce the new object.

If you are creating an object of a class in which you wrote the class program, and you don't remember making any constructors, the compiler has automatically created a standard one that doesn't take any parameters and doesn't change the value of the fields.
Reference: Chapter 11 Page 351
Reference: Chapter 3 Page 43
foodPrice would be 6.0
Assume you have the following code:

public class Groceries

private static double

public double
updatePrice(double newPrice) {
foodPrice = newPrice;
System.out.println("The food price is now " + foodPrice);


>double standardPrice = 2.50;
>newPrices2017.updatePrice(standardPrice + 3.50);
After combining the value input (3.50) and the variables value(standardPrice = 2.50).

The new total is 6.0 and passes through the method with no problem since the method call takes a double value.
Reference: Chapter 3 Page 350
Reference: Chapter 3 Page 350
Reference: Chapter 3 Page 350
You can use underscores to help break up a number in Java, as long as the underscores are not at the beginning or end of the value. For Example:
>int i = 6000000;
>int r - 6_000_000;
>System.out.println(int i + " and " int r);

6000000 and 6000000
If you created a Groceries object called newPrices2017, what would be the foodPrice after the following was entered into the interactions pane?
A) void
B) int
C) myNumber
D) 500
Full transcript