int a=2; int b=5; int min=(a<b)?a:b; System.out.println(min);
Assignment Operators
int a=10; int b=20; a+=4; b-=4; System.out.println(a); System.out.println(b);
Access Modifiers / Access Specifiers
They tell us the scope of the variable (where a variable can be accessed)
Access Modifiers
private, default, protected, public
Instance Data Members
Each object has a separate copy of value for instance variables, they can be accessed with object only
Static Data Members
There is only one copy of value in the memory for a given class, irrespective of how many objects the class has, all objects share this static variable, can be accessed with class name itself
Static Methods
Their behavior is common to all objects, can be called directly with the class name, no need of object
Non-Static (Instance) Methods
Operate on instance variables of the class, need an object to call
Wrapper Classes
Byte, Short, Integer, Long, Float, Double, Character & Boolean, used for data type conversion
Command Line Arguments
class Test { public static void main(String args[]) { int x,y,z; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); z=x+y; System.out.println("The sum="+z); } }
Taking Input from User at Runtime (Scanner Class)
import java.util.Scanner; class ex3 { public static void main(String args[]) { int x,y,z; Scanner sc=new Scanner(System.in); System.out.println("Enter the first no:"); x=sc.nextInt(); System.out.println("Enter the second no:"); y=sc.nextInt(); if(x>y) System.out.println("First no is bigger"); else System.out.println("Second no is bigger"); } }
while Loop
Executes a statement or code block repeatedly as long as an expression is true
while Loop
while (expression) { Statement(s) to be executed if expression is true }
do...while Loop
Executes the statement(s) first, then checks the condition