Friday, May 19, 2017

how to recover files from wannaCry ransomeware?

Hello Guys, 
  • Does your system affected with wannaCry ransomeware?
  • Do you want to get your File back?
  • You don't want to pay
  • Are you in deep trouble because of WannaCry Ransomeware?

Don't worry, i have solution for you, you can try your luck.
I got a good news for you, you can decrypt your files from wannacry ransomeware.
I got a software which can help you to get your files back, its fully verified and open source so don't doubt on it. 

It is a software which decrypt the encrypted files by using wanndecrypt (it is a script to decrypt the encrpted files by wannacry).

Click here to get the software -> wanaKiwi
Download it and try it. 



Compatibility:
  • winXP x86
  • win2003 x86
  • win7 x86
Limitations:
  • Given the fact this method relies on scanning the address space of the process that generated those keys, this means that if this process had been killed by, for instance, a reboot - the original process memory will be lost. It is very important for users to NOT reboot their system before trying this tool.
  • Secondly, because of the same reason we do not know how long the prime numbers will be kept in the address space before being reused by the process. This is why it is important to try this utility ASAP.
  • This is not a perfect tool, but this has been so far the best solution for victims who had no backup

Thursday, January 19, 2017

Iterative statements in java..(for,while, do while loop)

3. Iterative Statements:

---------------------------------------------------------------------------------------------------

These statements are able to allow to execute a block of instructions repeatedly on the basis of a particular condition.

There are 3 type of iterative statement in java.


1. for 2. while          3. do-while


1. for:
----------------
Syntax:

for(Expr 1: Expr 2: Expr 3)
{
---Instructions---
}

EX 1:
for (int i = 0; i < 10 ; i++ )
{
System.out.println(i);
}

Expr 1: 1 time execution
Expr 2: 11 times execution
Expr 3: 10 times execution
Body : 10 times execution

EX 2:
int i = 0;
for ( ; i < 10 ; i++ )
{
System.out.println(i);
}

Status: No compilation error.

EX 3:
int i = 0;
for (System.out.println("Hello") ; i < 10 ; i++ )
{
System.out.print(i + " ");
}

Status: No compilation Error
OP:
Hello
0 1 2 3 4 5 6 7 8 9

Note: 
In for Loop, Expr1 is optional, we can write for loop without Expr1, we can provide any statement as Expr1 in for loop, but always it is suggestible to provided loop variable declaration and their initialization type of statements as Expr1.


EX 4:
for (int i = 0, float f = o.of; i<10 & f <10.0; i++ ,f++)
{
System.out.print(i + " " + f);
}

Status: Compilation Error

EX 5:
for (int i = 0, int j = o; i<10 & j <10; i++ ,j++)
{
System.out.print(i + " " + j);
}

Status: Compilation Error

EX 6:
for (int i = 0, j = 0; i<10 & j <10; i++ ,j++)
{
System.out.print(" " + i + " " + j);
}

Status: No Compilation Error
OP:  0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9

Reason:
In for loops, Expr1 is able to allow utmost one declarative statement , if we provide more than one declarative statement then compiler will rise an error. In single declarative statement we can declare more than one variable.

(one keyword is one statement so if we use int&float or int&int then these are two keyword so it become two declarative statement, in EX 6, we use  only one keyword so it does not show any error)

EX 7:
for (int i = 0; ; i++ )
{
System.out.println(i);
}

Status: No Compilation Error

EX 8:

for (int i = 0; System.out.println("Hello"); i++ )
{
System.out.println(i);
}

Status: Compilation Error

Reason:
In for loop, Expr2 is optional, we can write for loop without Expr2, if we write for loop without Expr2 then for loop will take "true" value in place of Expr2 and it will make for loop as infinity loop. if we want to provide any statement as Expr2 then that statement must be Boolean statement, it must return either true value or false value.


EX 9:
System.out.println("Befor Loop");
for (int i = 0; i <=0 || i >= 0 ; i++ )
{
System.out.println("Inside loop");
}
System.out.println("After Loop");

Status: No compilation Error

EX 10: 
System.out.println("Befor Loop");
for (int i = 0; true ; i++ )
{
System.out.println("Inside loop");
}
System.out.println("After Loop");

Status: Compilation Error

EX 11: 
System.out.println("Befor Loop");
for (int i = 0;  ; i++ )
{
System.out.println("Inside loop");
}
System.out.println("After Loop");

Status: Compilation Error: Unreachable Statement

Note:
If we provide any statement immediately after infinity loop then that statement is called as "Unreachable Statement".

In java applications, when compiler identifiers the provided loop as an infinity loop and it is identified any following statement that infinity loop then compiler will provide an error like " Unreachable Statement". In for loop if we provide constant expression as conditional Expr & it
return "true" value then compiler will recognize that provided loop as infinite loop. if we provide variable expression as conditional Expr in  for loop as an infinite loop even it is really an infinite loop & compiler will not rise any "Unreachable Statement" like error even it  identify any statement immediately after the provided loop.

EX 12:
for (int i = 0; i < 10 ; )
{
System.out.println(i);
i = i + 1;
}
Status: No compilation Error

EX 13:
for (int i = 0; i < 10 ; System.out.println("Hello"))
{
System.out.println(i);
i = i + 1;
}
Status: No compilation Error

Reason:
In for loop, Expr3 is optional, we can write for loop without Expr3. we can write any statement as Expr3, but , it is suggestible to provide loop variable increment & decrements kind of statements as Expr3.

EX 14:
class  Test
{
public static void main(String[] args)
{
for ( ;  ; )
}
}
Status: Compilation Error

EX 15:
class  Test
{
public static void main(String[] args)
{
for ( ;  ; )
{
}
}
}

or

class  Test
{
public static void main(String[] args)
{
for ( ;  ; ) ;
}
}
Status: No Compilation Error
Output: No output but JVM is in infinite loop.

EX 16:
class  Test
{
public static void main(String[] args)
{
for ( ;  ; )
;
}
}
Status: No Compilation Error

Reason:
In for loop, if we want to provide single statement in body then curly braces {} are optional, if we don't want to provide any statement in for loop then we must provide either curly braces or  ' ; ' .

In Java Application, we are able to use "for" loop when we aware the number of iteration in advance before writing the loop.

To retrieve elements from array, we are going to use for loop only, because, we can identify number of iterations before the loop, that is, size of array represented in form of "length " variable.

EX 17:
class  Test
{
public static void main(String[] args)
{
int[] a = {1,2,3,4,5};
for ( int i = 0; i < a.length ; i++ )
{
System.out.println(a[i]);
}
}
}

To retrive elements from arrays if we use the above "for" loop approach then we are able to get following drawbacks:

1. We have to manage a separate loop variable.
2. At each and every iteration, we have to execute conditional expression.
3. At each & every iteration, we have to perform either increment or decrement operation over the loop variable.
4. We have to retrive elements from array on the basis of index values, if the provided index value is not proper then JVM will rise an Exception
like java.lang.ArrayIndexOutOfBoundsException

To overcome the above drawbacks, we have to use "for-Each" loop provided by JDK5.0 version.

Syntax:
for(Array_Data_Type var: Array_Ref_Var)
{
  ---Instructions--
}

when JVM Encounters the above for-each loop, JVM will perform iteration over the provided array right from first element to last element, At each & every
iteration, JVM will take element from array & JVM will assign that elements to the specified variables in for-each loop.

EX 18:
 int[] a = {1,2,3,4,5};
for ( int i : a )
{
System.out.println(i);
}


EX 19:
class  Test
{
public static void main(String[] args)
{
String[] str = {"AAA","BBB","CCC","DDD"};
for ( int i = 0; i < str.length ; i++ )
{
System.out.println(str[i]);
}

System.out.println();

for (String i : str)
{
System.out.println(i);
}
}
}
OP:
AAA
BBB
CCC
DDD

AAA
BBB
CCC
DDD

-------------------------------------------------------------------------------------------------------------------------

2. While Loop:
------------------------------
In java application, we will use "while" loop when we are not aware about number of loop iteration in advance before writing loop.

Syntax:
while(Condition)
{
 --- instrucion---
}

EX 1:
int i = 0;
while(i < 10)
{
System.out.print(i + "  ");
i = i + 1;
}
OP:
0 1 2 3 4 5 6 7 8 9

EX 2:
int i = 0;
while( )
{
System.out.print(i + "  ");
i = i + 1;
}
Status: Compilation Error
Reason: Conditional Expression is mandatory in while loop.

EX 3:
System.out.println("Befor Loop");
int i = 0;
while( i <=0 || i >= 0 )
{
System.out.println("Inside loop");
i = i + 1;
}
System.out.println("After Loop");

Status: No compilation Error

EX 4:
System.out.println("Befor Loop");
int i = 0;
while( true )
{
System.out.println("Inside loop");
i = i + 1;
}
System.out.println("After Loop");

Status: compilation error: Unreachable statement

-------------------------------------------------------------------------------------------------------------

3. Do-while loop:
------------------------------------

Q.) what are the difference between while loop & do-while loop?
Ans:
1. while loop will not give guarntee to execute loop body minimum one time.
    do-while loop will give guarantee to execute loop body minimum one time.

2. In case of while loop, first conditional expression will be executed then loop body will be                   executed.
   In case of do-while loop, first loop body will be executed then conditional expression will be               executed.

3. In case of while loop, conditional expression will be executed to perform current iteration.
   In case of do-while loop, conditional expression will be executed to perform next iteration.

Syntax:
while(condition)
{
 --- instruction --
}


do
{
--- instruction ---
} while(condition);


EX 1: 
int i = 0;
do
{
System.out.print(i + "  ");
i = i + 1;
}while(i < 10);
OP:
0 1 2 3 4 5 6 7 8 9

EX 2:
int i = 0;
do
{
System.out.print(i + "  ");
i = i + 1;
}while( );
Status: Compilation Error


EX 3:
System.out.println("Befor Loop");
int i = 0;
do
{
System.out.println("Inside loop");
i = i + 1;
}while( true );
System.out.println("After Loop");

Status: compilation error: Unreachable statement

You may also like: --> if-else condition in java

Wednesday, January 18, 2017

Operators in Oracle DBMS

15. OPERATORS:

1. Arithmetic Operators:

   +   -   *   /

-> To perform Arithmetic operation on users data & on table data.
-> If the calculations is on users data, use dual table.

EX:1. select 100 + 200 - 1000*4 from dual; (it only show operation at once)

EX:2. select 0.25*75000 from dual;

EX:3. select (25*75000)/100 from dual;

# on table data:

EX:4. display emp name, sal, 20% of salary as bonus and also final salary.
-> select ename, sal "Actual",
   0.20*sal "Bonus",
   sal+(0.20*sal) "Final Sal"
   from emp;

EX:5. Display acc_no, balance, 12% as interest.
-> select actNo, act_bal "balance",
   0.12*act_bal "interest"
    from cuts_dtls;


2. Relative Operators:

   =   <   >   <=   >=

These operators used to compare values. we can specify conditions in the select query.

You may also like: -->  Commands in Oracle DBMS

Commands in Oracle DBMS


Metadata: saved under data dictionary.
Actual data saved under actual database.
---------------------------

8. Insert All:
Using this command, we can insert multiple records into single table or multiple table at a time.

Syntax:
insert all into table_name(col_name)
values(.........)
into table_name(col_name)
values(........)
into table_name(col_name)
values(....)
select * from dual;

Dual: it is a system defined table, which holds the values under buffer area.

EX: SQL>insert all
into emp_info
values(111,'a',1200,'clerk','21-oct-14')
into emp_info
values('112','b','1200','clerk','22-jan-14')
select * from dual;

display: 2 rows created.
--------------------------------------------------

9. Inserting record at run time:
by using &(address of) operator

Syntax:
Insert into table_name(col_name)
values('&col1','&col2','&col3','&col4',..........);

EX:
insert into emp_info
values('&eid','&ename','&sal','&desg','&jdate');

display:
Enter value for eid:....
Enter value for ename:....
Enter value for sal:....
Enter value for desg:...
Enter value for jdate:...

1 row created.

SQL>/

Enter value for eid:...
Enter value for ename:...
Enter value for sal:...
Enter value for desg:...
Enter value for jdate:...
1 row created.
--------------

Note: '/' command: it will re-execute recent SQL query in SQL * plus  window.

-----------------------------------------------

9. NULL VALUE:

A null value is known as missed value in a column, null values are handled by oracle engine, a null value not equal to zero, space or other null value. null value are independent of data type.

EX: Null values are inserted using two methods:

1. implicit insertion:
EX: insert into emp_info(ename, sal)
values('hemant','1200');

2. explicit insertion:
EX: insert  into emp_info
values(null,'hemant', 1200, null, null);
---------------------------

10. Distinct Clause:
display list of unique values from given column.

SYntax:
select distinct col1, col2,...
from table_name;

EX: display list of different desg:
SQL> select distinct desg from emp_info;

or

SQL> select distinct desg from emp_info where desg not equal to null;
---------------------------------

11. User Tables:
It is system defined table which contains list of table names, it will not maintain recycle bin table names.
->select table_name from user_tables;

# How to create a table from other table:
-> create table <new name>
    as
    select cl1,cl2,cl3,... / *
    from <old_table_name>;

EX:1
SQL> create table emp as select * from scott.emp;
Display: Table Created.

EX:2
SQL> create table emp1
     as
     select ename,sal,job,deptno
     from emp;

-> select table_name from user_table;
-> select * from tab; -> it shows tables in recycle bin too.

# creating empty table from other table: means creating only table structure from other.
SQL> create table emp2
     as
     select empno, ename, sal, job
     from emp
     where 1 = 2;
Ans: Write any query with a false condition, so it will create an empty table with structure only.

------------------------------------

12. change name of column temporary for output:
by default column names are displayed as titles in the output, to change the title, use below syntax

SQL> select colname "title Name"
     from table_name.
-> title with spaces allowed & same case maintained in title if we use " ".

SQL> select ename EmpName from emp;
-> it will change ename to EMPNAME;

SQL> select ename "EmpName" from emp;
-> it will change ename to EmpName.

SQL> select ename "Emp Name" from emp;
-> it will change ename to Emp Name.

SQL> select ename as Emp_name from emp;
-> it will change ename to EMP_NAME.
--------------------------------------------------------

13. increase page size in sql * plus tool:
SQL> set pagesize = 100;
-------------------------------------------------------

14. Order by Clause:
-> it will display ascending and descending order data in the output.
Generally table data is random ordered data.

Syntax:
SQL> select col1, col2,...
     from <table name>
     order by cl1,cl2,..[ASC/DESC];
Note: ASC is default.
DESC: Reverse Order.

Note: At the place of col_name, we can also use col position number in order by clause.

EX:1. display emp_name, sal, job & dept no based on sal order.
SQL> select ename, sal, job, dept_no
     from emp
     order by sal;
   
     (or)

SQL> select ename, sal, job, dept_no
     from emp
     order by 2;

-> display above output department wise & also from each department least salary emp to the highest salary employee.

EX:2 select ename, job, sal, dept_no
    from emp
    order by dept_no, sal;

Note: it will order the deptNo first in order, if their is only duplication then it will give second priority to sal for order.

EX:3. Display emp_name in reverse order:
SQL> select ename
     from emp
     order by ename desc;

EX:4. Display emp_name, salary & join date like latest employee to the old employee.
SQL> select ename, sal, jdate
     from emp
     order by 3 desc;

EX:5. Display customer details based on gender order:
SQL> select * from cust_dtls
     order by gender;
--------------------------------------------------------------------------------

You may also like: --> Naming Rules in Oracle DBMS 

Switch Case in java and its operation

Switch:

---------------------------------------------------------------------------------------------

Rule 1 :
'if' conditional statement is able to allow one condition checking but switch is able to allow multiple condition checking.

Syntax:
--------
Switch(var_name)
{
case 1:
----- instructions---
  break;
case 2:
----- instructions---
  break;
case 3:
----- instructions---
  break;
--------
--------
-------
default:
----- instructions---
  break;
}

Note: In general, we will utilize 'switch' in menu driven application.

EX:1. 
class Test
{
public static void main(String[] args)
{
int i = 10;
switch(i)
{
case 5:
System.out.println("five");
break;
case 10:
System.out.println("ten");
break;
case 15:
System.out.println("fifteen");
break;
case 20:
System.out.println("tweenty");
break;
default:
System.out.println("Number is not in 5,10,15 and 20");
break;
}
}
}
Status: No compilation error.
OP: ten

Rules to Write Switch:

--------------------------------
1. Switch is able to allow the data types like byte, short, int, and char as parameters. switch is unable to allow the data types like long, float and double as parameters.

Note: Up to JAVA6 version, java is not allowing string data type as parameter to switch, but, right from java7 version switch is able to allow string data type as parameter.

EX:1. 
class Test
{
public static void main(String[] args)
{
byte b = 5;
switch(b)
{
case 5:
System.out.println("five");
break;
case 10:
System.out.println("ten");
break;
default:
System.out.println("default");
break;
}
}
}
Status: No compilation Error.
OP: ten

EX:2.
class Test
{
public static void main(String[] args)
{
char c = 'B';
switch(c)
{
case 'A':
System.out.println("A");
break;
case 'B':
System.out.println("B");
break;
case 'C':
System.out.println("C");
break;
default:
System.out.println("default");
break;
}
}
}
Status: No compilation Error.
OP: B

EX:3.
class Test
{
public static void main(String[] args)
{
string str = "AAA";
switch(str)
{
case "AAA":
System.out.println("AAA");
break;
case "BBB":
System.out.println("BBB");
break;
case "CCC":
System.out.println("CCC");
break;
default:
System.out.println("default");
break;
}
}
}
Status: No compilation Error.
OP: AAA
--------------------------------------

Rule 2.
In switch all cases and defaults are optional. we can write switch without cases & with default, or we can write switch with cases &
without default. if we write switch without both cases & defaults still we get no error.

EX:1. 
class Test
{
public static void main(String[] args)
{
int i = 10;
switch(i)
{
case 5:
System.out.println("five");
break;
case 10:
System.out.println("ten");
break;
}
}
}
Status: No compilation Error.

EX:2.
class Test
{
public static void main(String[] args)
{
int i = 10;
switch(i)
{
default:
System.out.println("default");
break;
}
}
}
Status: No compilation error

EX:3.
class Test
{
public static void main(String[] args)
{
int i = 10;
switch(i)
{
}
}
}
Status: No compilation Error.
------------------------------------------

Rule 3:
In switch, break statement is optional, we can write switch without break statement, in this case, JVM will execute all the cases right
from matched case to end of switch.

EX:1.
class Test
{
public static void main(String[] args)
{
int i = 10;
switch(i)
{
case 5:
System.out.println("five");

case 10:
System.out.println("ten");

case 15:
System.out.println("fifteen");

default:
System.out.println("default");

}
}
}
Status: No Compilation Error.
OP:
ten
fifteen
default
-----------------------------------------------------------

Rule 4:
In switch, all cases value must be provided with in the range of the data type, which we provide as parameter.

EX: 1.
class Test
{
public static void main(String[] args)
{
byte b = 126;
switch(b)
{
case 126:
System.out.println("126");
break;
case 127:
System.out.println("127");
break;
case 128:
System.out.println("128");
break;
default:
System.out.println("default");
break;
}
}
}
Status: Compilation Error.
Reason: 128 is not in the range of byte.
---------------------------------------------------------------

Rule 5: 
In switch, all case values must be either direct constants or final constants.

EX:
final int i = 5, j = 10, k = 15, l = 20;
switch(10)
{
case i:
System.out.println("five");
break;
case j:
System.out.println("ten");
break;
case k:
System.out.println("fifteen");
break;
case l:
System.out.println("twenty");
break;
default:
System.out.println("default");
break;
}

Status: No Compilation Error.
OP: ten
-------------------------------------------------------------------------------------------
You may also like: Operation on IF-else

Operation of If-else condition in java

If-else

------------------------------------------------------------------------------------------------
Syntax:1if(Condition)
{
  ----- instructions-----
}

Syntax:2.
if(Condition)
{
  ----- instructions-----
}
else
{
----instructions----
}

Syntax:3.
if(Condition)
{
  ----- instructions-----
}
else if(condition)
{
------instruction---
}
------
-----
------
else
{
----instructions----
}

EX:1. 
class Test
{
public static void main(String[] args)
{
int i = 10;
int j;
if(i == 10)
{
j = 20;
}
System.out.println(j);
}
}

Status: Compilation Error: J not initiated.

EX:2.
class Test
{
public static void main(String[] args)
{
int i = 10;
int j;
if(i == 10)
{
j = 20;
}
else
{
j = 30;
}
System.out.println(j);
}
}
Status: No Compilation Error.
OP: 20

EX:3.
class Test
{
public static void main(String[] args)
{
int i = 10;
int j;
if(i == 10)
{
j = 20;
}
else if(i == 20)
{
j = 30;
}
System.out.println(j);
}
}
Status: Compilation Error.

EX:4. 
class Test
{
public static void main(String[] args)
{
int i = 10;
int j;
if(i == 10)
{
j = 20;
}
else if(i == 20)
{
j = 30;
}
else
{
j = 40;
}
System.out.println(j);
}
}
Status: No compilation Error.
OP: 20

EX:5.
class Test
{
public static void main(String[] args)
{
final int i = 10;
int j;
if(i == 10)
{
j = 20;
}
System.out.println(j);
}
}
Status: No compilation Error.

EX:6. 
class Test
{
public static void main(String[] args)
{
int j;
if(true)
{
j = 20;
}

System.out.println(j);
}
}
Status: No compilation Error
OP: 20



Reasons:
1. In Java, only class level variables are having default values, local variables are not having default values. If we declare local variable in java application then we must provide initialization for that local variable explicitly either at he same declaration statement or at least be for accessing that local variable. if we access any local variable without initialization then compiler will rise an error like "variable xxx might not have been initialized".

EX:
class A
{
int i;
void m1()
{
int j;
System.out.println(i); // No Error
System.out.println(j); // Error
j = 20;
System.out.println(j); // No Error
}
}

-----------------------------------

2. There are two types of conditional expressions:
1. Constant Expression
2. Variable Expression

A. Constant Expressions:
--> It includes only constants under final constants, it would be evaluated by compiler.
EX 1:
i. if(10 == 10) {    }
ii. if(true) {    }
iii. final int i = 10;
     if(i == 10) {    }


B. Variable Expressions:
--> These expressions includes at least one non-final variable and these expressions are evaluated by JVM.
EX:
i. int i = 10;
   int j = 10;
   if(i == j) {    }

ii. int i = 10;
    if(i == 10) {   }


----------------------------------------------------------------

You may also like -->  Reserve Keyword in JAVA

Thursday, January 12, 2017

Statements in JAVA(if-else, switch, for ...)

JAVA Statements

---------------------------------------------------------------------------------------------------------

Statement is a collection of expressions.

To design java application, java has provided the following list of statements:

1. General purpose statements:
----------------------------------------------------------
Declaring variables, methods, classes, interfaces....
creating objects for classes...
accessing variables, methods,...


2. Conditional statements:
---------------------------------------------------
1. If          2. Switch


3. Iterative Statements:
----------------------------------------------
1. for 2. while 3. do-while


4. Transfer statements:
--------------------------------------------
1. break     2. continue 3. return


5. Exception Handling Statements:
----------------------------------------------------------------
1. throw          2. try-catch-finally


6. Synchronized Statements:
--------------------------------------------------------
Synchronized Methods
Synchronized Blocks

Note: All Statements will be detailed in upcoming post or you can go directly by clicking on Statements.

You May Also Like: --->  Naming Conventions in JAVA
                      

Type Casting in Java

Type Casting:

----------------------------------------------------------------------------------------------------

The process of converting data from one data type to another data type is called as "Type Casting".

There are two types of Type casting in java:

1. Primitive data types type casting
2. User defined data types type casting

The process of converting data from one user defined data type to another user defined data type is called as user defined data types type casting.

To perform user defined data types type casting we have to provide either "intends" relation or "implementation" relation between two user defined
data types.

Primitive data types type casting:
------------------------------------------------

The process of data from one primitive data type to another primitive data type is called as "primitive data types type casting".

there are two types of primitive data types type casting:

a) Implicit type casting
b) Explicit type casting

a) Implicit type casting:
----------------------------
The process of converting data from lower data type to higher data type is called as implicit type casting.

To cover all the possibilites of implicit type casting java has provided the following chart:

byte ---> short ---> int ---> long ---> float ---> double
                      ^
                      |
                     char

In java application to perform implicit type casting, we have to assign lower data type variables to higher data type variable.

EX: byte b = 10;
    int i = b;

when we compile above code, when compiler encounter the above assignment statement, compiler will check whether right side variable data type is compatible with left side variable data type or not, if not, compiler will rise an error like "possible loss are precision" in jdk7. if right side variable
data type is compatible with left side then compiler will not rise any error and compiler will not perform any type casting.

When we execute the above code, when the JVM encounter the above assignment statement than JVM will perform the following two actions:

1. JVM will convert right side variable data type to left side data type [Type Casting].
2. JVM will copy right side variable value to left side variable.

EX:1.
      int i = 10;
      byte b = i;
      System.out.println(i+"  " + b);

Status: Compilation Error, possible loss of precision.

EX:2.
      byte b = 65;
      char c = b;
      System.out.println(b+"  " + c);
Status: Compilation Error, possible loss of precision.

EX:3. char c = 'A';
      short s = c;
      System.out.println(c+"  " + s);

Status: Compilation Error, possible loss of precision.

Reason: Conversion are not possible between byte and char, short and char in implicit type casting because their internal data representation are not compatible.

EX:4.
      byte b = 130;
      System.out.println(b);

Status: Compilation Error, possible loss of precision.

Reason: If the provided value is greater than the specified data type maximum value then compiler will treat that value is of the next higher data
type, in implicit type casting we are unable to assign higher data type value to lower data type variable.

EX:5.
     byte b1 = 60;
      byte b2 = 70;
      byte b = b1+ b2;
      System.out.println(b);
Status: Compilation Error, possible loss of precision.

EX:6.
      byte b1 = 30;
      byte b2 = 30;
      byte b = b1+ b2;
      System.out.println(b);
Status: Compilation Error, possible loss of precision.

Reason:
consider X,Y,Z are three primitive data types:
X + Y = Z

1. If X & Y belongs to {byte, short, int} then Z should be Int.
2. If either X or Y or both X & Y are belongs to {long, float, double} then Z should be higher (X,Y) as per implicit type casting chart.

EX:
byte + byte = int
byte + short = int
short + long = long
long + float = float
float + double = double
int + double = double
--------
--------


------------------------------------------------------------------------------------------------------------------------

2. Explicit Type Casting:
---------------------------------
The process of converting data type from higher data type to lower data type is called as Explicit type casting.

To perform explicit type casting, we have to use the following pattern:

P a = (Q) b;

where Q must be either same as P or lower than P.


EX:1.
      int i = 10;
      byte b = (byte) i;
      System.out.println(b+"  "+i);

Status: No compilation error.
OP: 10  10

When we compile the above program, when compiler encounter the above assignment statement, compiler is compatible with left side data type or not, if not, compiler will rise an error like "possible loss of precision". If right side data type is compatible with left side data type then compiler will not rise any error & compiler will not perform type casting.

When we execute the above program, the JVM encounter the above assignment statement then JVM will perform the following two actions:

1. JVM will convert right side variable data type to cast operator [data type] provided data type at right side explicitly.[Explicit type casting]

2. JVM will copy value from right side variable to left side variable.

EX:2.
       int i = 10;
      short s = (byte) i;
      System.out.println(i+"  " + s);

Status: No Compilation Error.
OP: 10  10

EX:3. 
      byte b = 65;
      char c = (char) b;
      System.out.println(b+"  " + c);

Status:No Compilation Error.
OP: 65  A

EX:4.
     char c = 'A';
      short s = (byte) c;
      System.out.println(c+"  " + s);

Status:No Compilation Error.

EX:5.
      short s = 65;
      char c = (byte) s;
      System.out.println(s+"  " + c);

Status: Compilation Error, possible loss of precision.

EX:6.
      byte b1 = 30;
      byte b3 = 30;
      byte b = (byte)b1 + b2;
      System.out.println(b);

Status: Compilation Error, possible loss of precision.

EX:7.
      byte b1 = 30;
      byte b3 = 30;
      byte b = (byte)(b1 + b2);
      System.out.println(b);

Status:No Compilation Error.

EX:8. 
      float f = 22.22f;
      long l = 10;
      long l1 = (long)f + l;
      System.out.println(l1);

Status: No compilation Error.

EX:9.
      double d = 22.22;
      byte b = (byte)(short)(int)(long)(float)d;
      System.out.println(b);

Status: No compilation Error.
---------------------------------
You may also like:--> Data Types in JAVA

Saturday, January 7, 2017

Data Type in java

Data Type:

--------------------------------------------------------------------------------------------------

Java is strictly a typed programming language, where in java applications before representing data, first, we have to confirm which type of data

we are representing, we have to use "Data Type".

In JAVA applications, data types are able to provide the following two advantages.

1. we can identify memory sizes to store data.
2. we can identify range value for the variables in order to assign.

To prepare java applications, java has provided the following data types:

1. Primitive data type/ primary data types:
---------------------------------------------------------------------------------

1. Numeric Data Types:
------------------------

1. Integral/ Integer data types
---------------------------------
data type memory default value
--------- --------- --------------
byte -----------> 1 byte ---------> 0
Short ----------> 2 bytes --------> 0
int ------------> 4 bytes --------> 0
long -----------> 8 bytes --------> 0

2. Non Integral Data type:
---------------------------
float ----------> 4 bytes --------> 0.0f
double ---------> 8 byte ---------> 0.0

2. Non-Numeric Data Types:
-----------------------------
char -----------> 2 bytes --------> ' '[single space]
boolean --------> 1 bit  ---------> false

2. User Defined data types/ secondary data types:
------------------------------------------------------------------------

All classes interfaces, abstract classes, arrays...

Note: The default value for user defined data types is 'null'.

To get range values on the basis of the data types, we have to use the following formula:

     n-1                    n-1
   -2            to        2  - 1
where 'n' is number of bit.

Note: The above formula is applicable only for integral data types.

EX: byte
size: 1 byte = 8 bits


     8-1                    8-1
   -2            to        2  - 1

     7                      7
   -2            to        2  - 1

   -128  to 127

EX: calculate minimum & maximum value of Long:

class Test {
public static void main(String[] args) {
System.out.println(Long.MIN_VALUE+ "---->" + Long.MAX_VALUE);
 }
}

To get minimum value & maximum value for each and every primitive data type. java has provided the following two constants from each and every  wrapper class.

MIN_VALUE    MAX_VALUE

Note: Classes representation of premitive data type is called as "Wrapper Classes". JAVA has provided 8 number of wrapper classes in java.lang
package w.r.t. the 8 number of premitive data types.

Primitive Data Types               Wrapper classes
---------------------                     -----------------
byte ----------------------------->  java.lang.Byte
short  --------------------------->  java.lang.Short
int  ----------------------------->  java.lang.Integer
long  ---------------------------->  java.lang.Long
float  --------------------------->  java.lang.Float
double  -------------------------->  java.lang.Double
char  ---------------------------->  java.lang.Character
boolean  ------------------------->  java.lang.Boolean

EX: class Test {
public static void main(String[] args){
System.out.println(Byte.MIN_VALUE + " -----> " + Byte.MAX_VALUE);
System.out.println(Short.MIN_VALUE + " -----> " + Short.MAX_VALUE);
System.out.println(Integer.MIN_VALUE + " -----> " + Integer.MAX_VALUE);
System.out.println(Long.MIN_VALUE + " -----> " + Long.MAX_VALUE);
System.out.println(Float.MIN_VALUE + " -----> " + Float.MAX_VALUE);
System.out.println(Double.MIN_VALUE + " -----> " + Double.MAX_VALUE);
System.out.println(Character.MIN_VALUE + " -----> " + Character.MAX_VALUE);
//System.out.println(Boolean.MIN_VALUE + " -----> " + Boolean.MAX_VALUE); --> error
}
}
Output:

-128 -----> 127
-32768 -----> 32767
-2147483648 -----> 2147483647
-9223372036854775808 -----> 9223372036854775807
1.4E-45 -----> 3.4028235E38
4.9E-324 -----> 1.7976931348623157E308
  -----> ?

You may also like:

--> Type Casting in JAVA

Tuesday, January 3, 2017

short circuit operators in java

Short-Circuit Operators:

----------------------------------------------------------------------------------------------------------
The main intention of short circuit operator is to improve java application performance.

There are two types of short-circuit operators in java:

1. ||(double or) 2. &&(double and)

Q. what is the difference between | and ||?
Ans:
------
In case of 'logical-OR' operator, if first operand value is "true" then it is not required to check second operand value, directly we can predict the result of "OR" operator is "true".

If First operand value is "false" then it is mandatory to evaluate second operand value.

In case of  '|' operator, even though first operand value is true, still JVM will evaluate second operand value in order to get the overall expression
result, here evaluating second operand is unnecessary, it will increase application execution time and it will reduce application performance.

In case of '||' operator, if first operand value is "true", then JVM will predict the overall expression result is "true", without evaluating
second operand value, it will reduce application execution time & it will improve application performance.

EX:
class  Test
{
public static void main(String[] args)
{
int a = 10;
int b = 10;
if((a++ == 10) | (b++ == 10))
{
System.out.println(a+"  "+b);
}

int c = 10;
int d = 10;
if((c++ == 10) || (d++ == 10))
{
System.out.println(c+"  "+d);
}
}
}

Output:
D:\New folder>java Test
11  11
11  10

Note: Here you can see, in the First operation, even the first operand is true, still |(single or) perform both operand while || perform only single operand and display output.
--------------------------------------------------------------------------------------

Q. what is the difference between & and &&?
Ans:
------
In case of 'logical-AND' operator, if first operand value is "false" then it is not required to check second operand value, directly we can predict the result of "AND" operator is "false".

If First operand value is "true" then it is mandatory to evaluate second operand value.

In case of '&' operator, even though first operand value is false, still JVM will evaluate second operand value in order to get the overall expression
result, here evaluating second operand is unnecessary, it will increase application execution time and it will reduce application performance.

In case of '&&' operator, if first operand value is "false", then JVM will predict the overall expression result is "false", without evaluating
second operand value, it will reduce application execution time & it will improve application performance.

EX:
class  Test
{
public static void main(String[] args)
{
int a = 10;
int b = 10;
if((a++ != 10) | (b++ != 10))
{
}
System.out.println(a+"  "+b);

int c = 10;
int d = 10;
if((c++ == 10) || (d++ == 10))
{
}
System.out.println(c+"  "+d);
}
}

Output:
D:\New folder>java Test
11  11
11  10

Note: Here you can see, in the First operation, even the first operand is false, still &(single AND) perform both operand while && perform only single
operand and display output.
--------------------------------------------------------------------------------

Operators: in tokens in java language fundamentals

4. Operators:

Operator is a symbol, it will perform a particular operation over the provided operands.

To design java application, java has provided the following operators:

1. Arithmetic Operators:

+,  -,  *,  /,  %,   ++,   --, ....

2. Assignment Operators:

=, +=, -=, *=, /=, %=

3. Comparison Operator:

==, !=, <, >, <=, >=

4. Boolean Logic Operator:

&, |, ^


5. Bitwise Logical Operator:

&(and), |(or), ^(xor), <<, >>

6. Ternary Operator:

Expre1? Expr2: Expr3

Note: if Expre1 is true then Expr2 execute and if false then Expr3 will execute.

7. Short circuit Operator:

&&(double and), ||(double or)

Monday, January 2, 2017

Keyword/ Reserve Words: in java

3. Keyword/ Reserve Words:

-------------------------------------------------------------------------------------------------------------
Keyword is a predefined word having both recognize and internal functionality.

Reserve word is a predefined word having only word recognize without the internal functionality.

EX: goto, const

To prepare java applications, java has provided the following keywords:

1. Data types & Return types:
byte, short, int, long, float, double, boolean, char, void

2. Access Modifiers:
public, protected, private, static, final, abstract, native, volatile, transient, synchronized, strictfp,...

3. Flow Controllers:
if, else, switch, case, default, for, while, do, continue, break, return,...

4. Class/Object Related Keywords:
class, extends, interface, implements, package, import, new, this, super, enum,....

5. Exception Handling Related Keywords:
throw, throws, try, catch, finally....