Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between x++ and x= x+1 in Java programming
x++ automatically handles the type casting where as x= x + 1 needs typecasting in case of x is not an int variable. See the example below.
Example
public class Tester {
public static void main(String args[]) {
byte b = 2;
//Type casting is required
//as 1 is int and b is byte variable
b = (byte) (b + 1);
System.out.println(b);
byte b1 = 2;
//Implcit type casting by the compiler
b1++;
System.out.println(b1);
}
}
Output
3 3
Advertisements