7. Primitive Types • The Java programming language defines eight primitive types: Logical boolean Textual char Integral byte, short, int, and long Floating double and float
8.
9.
10.
11.
12. Integral – byte, short, int, and long Integral data types have the following ranges: Integer Length Name or Type Range 8 bits byte -2^7 to 2^7-1 16 bits short -2^15 to 2^15 -1 32 bits int -2^31 to 2^31 -1 64 bits long -2^63 to 2^63 -1
27. Java Coding Conventions • Packages: package banking.domain; • Classes: The first letter should be capitalized and if several words are linked together , the first letter of inner word should be uppercase,class name should typically be noun. For example Dog, Account, PrintWriter • Interfaces: The first letter should be capitalized and if several words are linked together , the first letter of inner word should be uppercase,interface n ame should typically be adjective For example Runnable, Serializable
28. Java Coding Conventions • Methods: The first letter should be lowercase, and then normal, the name should typically be verb-noun pairs. For example getBalance, doCalculation, setCustomerName • Variables: The first letter should be lowercase, and then normal For example currentCustomer • Constants: Java constants are created by marking variables static and final. They should be named using uppercase letter with underscore as separator. HEAD_COUNT MAXIMUM_SIZE
29. Access Modifiers Modifiers are Java Keywords that give the compiler information about the nature of code ,data or classes. Access modifiers are public , private and protected .
30.
31.
32.
33.
34.
35.
36.
37.
38. Abstract class vs. Interface Interface Abstract class A class may implement A class may extend several interfaces. only one abstract class. An interface cannot An abstract class can provide any code at all provide complete code, default code Static final constants only Both instance and static constants are possible.
39. If you add a new method to If you add a new method to an an interface, you must track abstract class, you have the down all implementations option of providing a default of that interface in the universe implementation of it. Then all and provide them with a concrete existing code will continue to implementation of that method. work without change. An interface implementation The existing class must be may be added to any existing rewritten to extend only from class. the abstract class.
40.
41. Example Ecstatic.java Class Ecstati c{ static{ System.out.println(“Hello”); } static int x=0; Ecstati c(){ x++; } }
42.
43. Via class name Ecstatic e1=new Ecstatic(); Ecstatic e2=new Ecstatic(); Ecstatic.x=100; Ecstatic.x=200; reallyImportantVariable=Ecstatic.x; //set to 200 Note • With static methods there is no this.If a static method need to access a non static variable it must specify the instance of the class that own the variable . • S tatic method cannot be overridden to be non static. Example StaticOverride.java
44.
45.
46. Transient This modifier applies only to variables. The transient variable is not stored as a part of its object persistent state. Sometimes object contain extremely sensitive information class WealthyCustomer extends Customer implements Serializable{ private float $wealth; private String accessCode; }
47.
48.
49.
50. Summary Modifier Class Variable Method Constructor public yes yes yes yes protected no yes yes yes default yes yes yes yes private no yes yes yes final yes yes yes no abstract yes no yes no static no yes yes no native no no yes no transient no yes no no volatile no yes no no synchronized no no yes no