Basics Flashcards
Important scanner
Import java.util.Scanner;
Scanner inputData = new Scanner(System.in)
Syntax—>Math random
-50 to 50
0-10
(int) (Math.random() * 101-50)
(int) (Math.random() * 11
String to primitive
integer
String num1 = “22”;
int int1 = Integer.parseInt(num1);
String to primitive
Wrapper class
String n1 = “22”;
Integer int1 = Integer.valueOf(n1);
(++, –)
Increment and decrement operators
(+, -, *, /, %)
Arithmetic operators
(, <=, >=, ==, !=)
Comparison (Relational) operators
(&&, ||, !)
Logical operators
( =, += , -=, *=, /=, %=)
Assignment operators
Implicit casting
converting a smaller data type to a larger data type size. Performed
automatically by the compiler
byte number1 = 45;
int number2 = number1
Explicit casting
converting a larger data type to a smaller data type size and performed manually
by users
double d1 = 100.0;
float f1 = (float)d1;
What are if-else statements in Java and what are they are used for?
- Java if-else statements are used to test specific conditions and they control the flow of the program based on the condition.
- It will execute a block of code if given condition is true, and another code of block if condition is false
What is break statement in Java?
break is used for termination in Java
It is used with switch statements and loops
What are wrapper classes in Java?
- Wrapper classes are object representations of primitives
- There is a wrapper class for each primitive type
- Wrapper class names are usually same as with primitive data types
Explain main() method in java?
- It is one of the most important methods in java as it tells java where the programs start
- We cannot run our programs without main method and all our programs should be in main() method
- JVM always look for this method to start running an application