Classes and Objects Flashcards

1
Q

Scanner Class

A

Scanner is a class in java.util package used for obtaining the input of the primitive types like int, double etc. and strings. It is the easiest way to read input in a Java program, though not very efficient if you want an input method for scenarios where time is a constraint like in competitive programming.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Package

A

A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Steps in creating Scanner Class

A

Import:
import java.util.Scanner

Create Scanner:
Scanner input = new Scanner(System.in);

Prompt:
System.out.println(“Please enter your name:”)

Keyboard Input:
String firstName = input.next();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Increment and Decrement Operators

A

Increment (++) and decrement (—) operators in Java programming let you easily add 1 to, or subtract 1 from, a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

++var

i = 1
int j = ++i

A

Increment var by 1, and use the new var value in the statement

int j = ++1;
// j is 2 & i is 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

var++

i = 1
int j = i++

A

Increment var by 1, and use the original var value in the statement

int j = 1++;
// j is 1 & i is 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

–var

i = 1
int j = –i

A

Decrement var by 1, and use the new var value in the statement

int j = --1;
// j is 0 & i is 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

var–

i = 1
int j = i–

A

Decrement var by 1, and use the original var value in the statement

int j = 1--;
// j is 1 & i is 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Type Casting

A

Type Casting in Java. Type casting is used to convert an object or variable of one type into another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Implicit Casting

A

An implicit cast means you don’t have to write code for the cast.

An implicit cast happens when you’re doing a widening conversion.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explicit Casting

A

An explicit casting is where you use some syntax to tell the program to do a conversion.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Shorthand Assignment Operators

A

In addition to the basic assignment operator, Java also defines 12 shorthand assignment operators that combine assignment with the 5 arithmetic operators ( += , -= , *= , /= , %= ) and the 6 bitwise and shift operators ( &= , |= , ^= , «= ,&raquo_space;= ,&raquo_space;>= ).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Comparison Operators

A
Operators
The result of every comparison is boolean (true or false).
operator 	meaning
<	less than
<=	less than or equal to
==	equal to
>=	greater than or equal to
>	greater than
!=	not equal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly