Week 1 - Core Java (S1 - S3)
What logical statement will you inject where the blank is so you can check both conditions in the code below? int age = 23; int money = 4000; if(age > 21 __ money > 500) { System.out.println("Winner!"); }
&&
What are the common numeric operators in Java?
+ addition - subtraction * multiplication / division % modulo
What operator is used in: int x = 6 + 3;
+ addition operator
Question 4: What do you need to put in the blank to print 11? int a = 10; _ a; System.out.println(a);
++
What will the following code print out? for(int x = 0 ; x <= 10; x=x+2) { System.out.println(x); }
0 2 4 6 8 10
What will print out? int x = 10, y = 5; if (x > y) { System.out.print(x); } else { System.out.println(y); }
10
Please select the correct output from the code below? int x = 4; int y = 7; int sum = x + y; System.out.println(sum);
11
What will the code produce: int test = 125; test--; System.out.println(test);
124
What is the output of the following code? int number = 125; System.out.println(++number);
126
What is the latest version of Java in 2020?
13
What is the output of the following code? int x = 14; System.out.println(x++);
14
How many times will the following for loop execute? for (int i = 2; i < 10; i = i*i) { System.out.println(i); }
2
What will be the output? int x = 3; while (x > 0) { System.out.println(x); x--; }
3 2 1
How many time will the following loop iterate? int x = 0, y = 5; while(x < y) { System.out.println("Java"); x++; }
5
What will the code produce: int test = 5; test++; System.out.println(test);
6
How many primitive data types are there is Java?
8
What are the common comparison operators in Java?
<, >, !=, ==, <=, >=
What is the assignment operator in Java?
=
What do you need to put in the blank to print out (Yea!)? int x = 5; if(x __ 5) { System.out.println("Yea!"); }
==
Can a String be changed once it is created?
A String cannot be changed once it has been created.
What are breakpoints when using a debugger?
A breakpoint allows for stopping the program execution at certain points. Breakpoints can be set by hovering the mouse over the editor's gutter area and clicking on it. The breakpoint will be identified by red circle symbols. To remove the break point you will just click on the red circle symbol.
What makes a do while loop different from a while loop?
A do while loop is guaranteed to execute the body of the loop at least once before the condition is checked.
What is a String in Java?
A string in java is a sequence of characters in Java.
In java is a string mutable?
A string is not a mutable object.
What will a while loop statement allow in Java?
A while loop statement will repeatedly execute a target statement as long as a given condition is true.
An if statement can contain how many else if statements?
As many as you want.
What is class cast exception?
Class cast exception is an exception which occurs at run time when an object of one type cannot be casted to another type.
What are conditional statements used for?
Conditional statements are used to perform different actions based on different conditions.
What is debugging in Software Development?
Debugging refers to identifying, analyzing, and removing errors in a program.
Can you explain the inspecting variables action with debugger?
During debugging, IntelliJ shows you the value of the variable in the editor window. You can even also view the same information in the debug window.
In a switch statement what is each value called?
Each value is called a case.
What is git config used for?
Git config is used to set your user name and email in the main configuration file.
What is Git?
Git is a distributed version-control system for tracking changes in source code during software development
What will be the output of the following code? int x = 7; if(x < 42) { System.out.println("I am in the if statement"); }
I am in the if statement
Can you explain the IntelliJ Debugger?
IntelliJ provides an inbuilt Java debugger. It allows for stopping the execution of a program at certain points, inspect variables, and step into functions/methods to see what the program is doing.
Who invented Java?
James Gosling
What are logical operators used for?
Logical operators are used to combine multiple conditions.
What will be the output of the code? int test = 0; do{ System.out.println("Luke"); test++; } while(test < 5);
Luke Luke Luke Luke Luke
What will this code output? String firstName, lastName; firstName = "David"; lastName = "Williams"; System.out.println("My name is " + firstName + " " + lastName + ".");
My name is David Williams.
What is narrowing as it pertains to typecasting?
Narrowing is converting a larger datatype to a smaller datatype. In this case the casting/conversion is not done automatically. You will need to convert the data type using the following syntax (<data type>) explicitly, where this syntax must be on the left-hand side of the datatype being converted. When using this syntactic construct this is known as explicit typecasting or type conversion.
What are the types of casting?
Primitive casting: when the data is casted from one primitive type like int, float, double to another primitive type. This is called primitive casting. Derived casting: when the data is casted from one derived type to another derived type, then it is called derived casting. In other words when one is casting from one object to another object.
What are primitive data types in Java?
Primitive types are the most basic data types available within the Java language.
What are the methods that are available through the Scanner class?
Read a byte = nextByte() Read a short = nextShort() Read an int = nextInt() Read a long = nextLong() Read a float = nextFloat() Read a double = nextDouble() Read a boolean = nextBoolean() Read a complete line = nextLine() Read a word = next()
What will go in the blank? Scanner userInput = new Scanner(System.in); ____ input = userInput.nextLine();
String
Which is the correct representation of a String literal? string work; String word = "HEILO"; new String word = "Hello"; int x = "Hello";
String word = "HEILO";
Why do we need Strings in Java?
Strings in Java are one of the most used data types in Java. They allow users to be able to store anything in them.
What is Java Development Kit (JDK) in Java?
The Java Development Kit (JDK) is the java development kit that is used to build the application that will run on the JRE (Java Run Time Environment)
What is the Java Runtime Environment (JRE)?
The Java Runtime Environment (JRE) is a software layer that runs on top of a computer's operating system software and provides the class libraries and other resources that a specific Java program needs to run.
When is the best time to use a for loop?
The best time to use a for loop is when the starting and ending numbers are known.
In a while loop when the expression is tested and the result checked to be false what will happen?
The body of the loop is skipped and the first statement after the while loop is executed.
What will happen when a switch statement encounters a break statement?
The break statement can be used to exit out of the switch statement.
What is the condition in a for loop used for?
The condition in a for loop is evaluated each time the loop iterates. The loop executes the statement repeatedly until the condition returns false.
Can you explain the evaluate expression action with debugger?
The evaluate expression will allow you to evaluate an expression on the fly. You can do the following step to evaluate an expression in the IntelliJ debugger: 1. Start the application in debugger 2. Navigate to Run->Evaluate expression 3. Enter the expression
What will the for loop allow you to do?
The for loop allows you to be able to write loops that will execute a specific number of times.
What will the git add command do?
The git add command will add all the changes to the stage/index in your working directory.
What will the git branch command do?
The git branch command will list out all the branches.
What is the git clone command used for?
The git clone command is used to copy a git repository from a remote source, and this will also set the remote to the original source so that you can pull again.
What will the git commit command do?
The git commit command will commit your changes and set it to a new commit object to your remote.
What is the git init command used for?
The git init command is used to initialize a git repository for a new or existing project.
What will the git merge command do?
The git merge command will merge the two branches you are working on.
What does the increment or decrement operator provide?
The increment and decrement operator provides a more convenient and compact way to increase or decrease the value of a variable by one.
In a for loop what is the increment/decrement used for?
The increment/decrement will execute after each iteration of the loop.
What is the initialization in a for loop used for?
The initialization in a for loop is the expression that will execute only once during the beginning of the loop.
What will the git push/git pull command do?
The push command will push your changes to the remote. The pull command can retrieve the changes you want for your remote.
Can you explain the resume program action with a debugger?
The resume program action will continue the execution of a program by ignoring all the breakpoints.
Can you explain the step out action with a debugger?
The step out action is the same as the step into action. The key is that if you place the breakpoint in front of the method you are wanting to debug the application will stop. At that point you can use the step to step through each line of code for the method and when you are done you can use the step out action to resume the normal flow of the program.
Can you explain the step over action with a debugger?
The step over action does not enter into a function instead, it will jump to the next line of code. For instance, if you are at line 9 and execute the step over action then it will move the execution to line 10.
What is the output of the code below? while(true) { System.out.println("Darth Vader"); }
This code will execute but it will trigger an infinite loop.
Why does Java support automatic type casting of integers to floating points?
This is because there is no loss of precision.
What is the git status command used for?
To check the status of files you have changed in your working directory.
When you change a value of one type to another type it is known as?
Type Casting
When is type casting mandatory?
Type casting is mandatory when assigning floating point values to integer variables.
What is type casting?
Type casting is when you convert one primitive datatype into another type casting (type conversion) in Java. You can cast primitive datatypes to another primitive datatype. The datatype will be either widening or narrowed.
Why is up casting automatic and down casting manual?
Up casting can never fail. But if you have a group of different Animals and want to downcast them all to a Cat, then there is a chance that some of these Animals are actually Dogs, so the process fails.
What are variables in Java?
Variables in Java are used for storing data for processing.
What will be the output of the code below? int day = 3; switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; case 4: System.out.println("Thursday"); break; default: System.out.println("Wrong..."); }
Wednesday
What will be the output of the code? int day = 3; switch(day) { case 1: System.out.println("Monday"); case 2: System.out.println("Tuesday"); case 3: System.out.println("Wednesday"); case 4: System.out.println("Thursday"); default: System.out.println("Wrong..."); }
Wednesday Thursday Wrong...
What will be the output of the code below? int age = 25; if(age <= 0) { System.out.println("Error"); } else if(age <= 16) { System.out.println("Too Young"); } else if(age < 100) { System.out.println("Welcome!"); } else { System.out.println("Really?"); }
Welcome!
Can you explain the smart step into action with a debugger?
While debugging, you may sometimes reach a line of code that calls several methods. When debugging these lines of code, the debugger typically allows you to use step into and leads you through all child functions and then back to the parent function. However, what if we only wanted to step into one child function? With Smart step-into, it allows you to choose the function to step into.
Can you explain the step into action with a debugger?
While in debugger mode if you have a breakpoint placed in front of a method the application will stop when it gets to the breakpoint before the method. At that time, you can select the step into tab that is part of the debugger to step through each line of the method and you will continue stepping through each line of code for the rest of the program.
What is widening as it pertains to typecasting?
Widening is converting a smaller datatype to a larger datatype. In this case the cast/conversion is done automatically therefore, it is known as implicit type casting. In this case both datatypes should be compatible with each other.
What is auto widening and explicit narrowing?
Widening: The data is implicitly casted from a smaller primitive type to larger primitive type. This is called auto-widening. The data is automatically casted from byte to short, sort to int, int to long, and float to double. Narrowing: You must explicitly cast the data from a larger primitive type to a smaller primitive type. You will have to convert the data from double to float, long to int, int to short and short to byte. This is called explicit narrowing.
What is boxing and unboxing?
Wrapping a primitive type into the corresponding wrapper class is called boxing. Unwrapping is when the runtime retrieves the primitive datatype from the wrapper class. This is also known as unboxing.
In down casting can you cast an object of a super class to its subclass?
Yes
Is String in Java a class?
Yes, String in Java is a class that has its own methods.
Will this code print out (You Win!)? int age = 55, money = 1000; if (age > 18 && money > 500) { System.out.println("You Win!"); }
Yes, will print out You Win.
Is the if statement one of the most frequently used conditional statements in java?
Yes.
Looking at the following code what is the output? int age = 65; if(age < 18) { System.out.println("Not Old Enough!"); } else { System.out.println("You Shall Enter!"); }
You Shall Enter!
An array is...
a collection of variables of the same type.
What is the correct syntax for a for loop?
for (initialization; condition; increment/decrement) { statement(s) }
Which for loop will print out: 5 4 3 2 1
for (int i = 5; i >= 1; i--) { System.out.println(i); }
What is the correct import to use the Scanner class?
import java.util.Scanner
What are the primitive data types in Java?
int, double, float, char, boolean, short, long, byte
What type is: 123549
integer
What will be the output of this code? int x = 1; do{ System.out.println("Do While Loop..."); } while(x < 5);
it is an infinite loop.
The value that is used on either side of an operator is called:
operand
What are the two forms that can be used with the increment and decrement operator?
prefix and postfix
A switch statement will ...
test a variable for equality against a list of values.
In every executable Java Program...
there must be a method called "main".
Fill in the blank to complete the following code: int x = 25; int y; y = _ - 12; System.out.println(y);
x