Quality coding Standards
Naming Rules
a) Declare name for a class in Java class Book
classs EnglishBook
class Car
class Student
class StudentTranscript
b) Variables/function Name
int book
int englisBook
int enonomyOfAmerica
int car
int student
int studentTranscript
c) Constants (AllUpper)
final int A=5;
final int SHOAIB=5;
final int ECONOMYOFPAKISTAN=34;
.....................................
Indentation in Java Programming
class Test{
}
void f (){
}
while (a>b){
}
.....................................
Data Types in Java
1- int (4 bytes) short (2 byte) long (8)
2- float (4bytes) 2.5f
float a=2.5f;
3- double (8 bytes) 2.5
4- byte ( 1 byte)
5- char (2 bytes) unicode ( Range 0 to 65536)
'a' '\n'
'\uxxxx' '\u2345'
'\u' Followed by exactly four hexadecimal digits
6- boolean (true, false)
.....................................
Type Conversion in Java Two Methods
a) Coercion
b) Casting
1- Coercion
Implicit type conversion by compiler
int a=5;
float b=a;//promotion
double g=2.5;
int y=g;//demotion (data loss)
// not allowed
float a=2.5; //demotion
//not allowed
2- Casting
Explicit type conversion by programmer
double b=2.5;
int x=(int)b;
....................................
Practice 1
class Test{
public static void main(String o[]) {
float a=2.5;
}
}
...................................
Practice 2
class Test{
public static void main(String o[]) {
float a=2.5f;
}
}
.....................................
Practice 3
class Test{
public static void main(String o[]) {
float a=2.5f;
int b=a;
}
}
.........................
Practice 4
class Test{
public static void main(String o[]) {
float a=2.5f;
int b=(int)a;
}
}
....................................
Some Hint from C++
void main() {
int i=1;
int sum=0;
while(i<=3){
float j;
cin>>j;
sum=sum+j;
i++;
}
cout<<sum;
}
Naming Rules
a) Declare name for a class in Java class Book
classs EnglishBook
class Car
class Student
class StudentTranscript
b) Variables/function Name
int book
int englisBook
int enonomyOfAmerica
int car
int student
int studentTranscript
c) Constants (AllUpper)
final int A=5;
final int SHOAIB=5;
final int ECONOMYOFPAKISTAN=34;
.....................................
Indentation in Java Programming
class Test{
}
void f (){
}
while (a>b){
}
.....................................
Data Types in Java
1- int (4 bytes) short (2 byte) long (8)
2- float (4bytes) 2.5f
float a=2.5f;
3- double (8 bytes) 2.5
4- byte ( 1 byte)
5- char (2 bytes) unicode ( Range 0 to 65536)
'a' '\n'
'\uxxxx' '\u2345'
'\u' Followed by exactly four hexadecimal digits
6- boolean (true, false)
.....................................
Type Conversion in Java Two Methods
a) Coercion
b) Casting
1- Coercion
Implicit type conversion by compiler
int a=5;
float b=a;//promotion
double g=2.5;
int y=g;//demotion (data loss)
// not allowed
float a=2.5; //demotion
//not allowed
2- Casting
Explicit type conversion by programmer
double b=2.5;
int x=(int)b;
....................................
Practice 1
class Test{
public static void main(String o[]) {
float a=2.5;
}
}
...................................
Practice 2
class Test{
public static void main(String o[]) {
float a=2.5f;
}
}
.....................................
Practice 3
class Test{
public static void main(String o[]) {
float a=2.5f;
int b=a;
}
}
.........................
Practice 4
class Test{
public static void main(String o[]) {
float a=2.5f;
int b=(int)a;
}
}
....................................
Some Hint from C++
void main() {
int i=1;
int sum=0;
while(i<=3){
float j;
cin>>j;
sum=sum+j;
i++;
}
cout<<sum;
}
Comments
Post a Comment