Skip to main content

Posts

Showing posts from April, 2013

Naming Conventions and Indentation in Java

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) ..................

Java Basics Quick Review with examples

Java Programming Language High Level Strongly Typed means no automatic type conversions in java like C++ Case Sensitive Successor of c++ Pure Object Oriented Language  Hello World Problem in java class Test{ public static void main(String a[]) { System.out.println("Hello World");  } } More than one Classes class Test1{ void print () { System.out.println("Test class"); } } class Test{ public static void main(String a[]) { Test1 t=new Test1(); t.print();  } } Rule of Thumb: Don't write extra functions in driver class  Extra function and data in driver class  class Test{ int sq(int p){    return p*p; } public static void main(String a[]) {     Test t = new Test(); System.out.println(t.sq(4));  } } .................................. call without object instantiation .................................. class Test{ static int sq(int p){    return p*p; } public static void main(String a[]) { System.out.println