Java lessons learned - Naming Convention, Variables,Data Types, Arrays

Data Types – 2 types 
  • Variables must always declared with a name and a type.
Naming conventions for JAVA units
  • Class - First letter CAPS  for each new word   ex : SavingGoal
  • Function(method) - First Letter SMALL ex : updateSavings()
  • Variable - First Letter SMALL ex :  Dog tommyHigh
  • Packages - all SMALL letters ex : 
  • Constructors -  First letter CAPS  for each new word (like class)  ex : SavingGoal
 
1.Primitive Variables
         Ex : int x = 8 ;
Type         Bit-Depth          Value-Range               Default value 
boolean     JVM specific          true,false                       false
char           16 bits                    0 to 65535
byte           8 bits                     -128 to 127
short         16 bits                   -32768 to 32767
int              32bits                   -2147483648 to 2147483647
long           64 bits                  -huge to huge
float          32 bits                    varies
double      64 bits                    varies

2.Reference Varibales

Ex :      Dog myDog = new Dog();

The value of the variable is bits representing a way to get to a specific object 
(.) Dot operatore is used to refer the value in reference variable.
It's default value is null when not referening any object.

Arrays - it is always an object.
ex: nums = new int[7];
Once you declared an array, you can't put anything in it except things that are of the declared array type.
However you can put a byte into an int array. it is implicit widening.

  • Class - is a blueprint for an object.
  • Description for JVM to make object is nothing but a class.
  • Class consists instances (instance variables) and methods.
  • Mark instance variables private
  • Mark getters and setters public(get and set methods)
  • Instance variables always gets default value.
  • Local variables(variables in methods) do NOT get a default value.Compiler reports error for this.
  • Use == to compare two primitives or two references ex : int a = 4; int b = 4; if (a == b) print x;
  • USe the equals() method to see if two different objects are equal(such as two different String objects).
  • Java uses pass by value - " pass by value is passing by copy".


1 comments to "Java lessons learned - Naming Convention, Variables,Data Types, Arrays"

  • In your post "Java Lessons Learned" under the section 'Naming conventions for JAVA units'
    you were talking about First letter CAPS for each new word ex : SavingGoal.
    This style is known as Camel Case.
    For more http://en.wikipedia.org/wiki/CamelCase ;-)

Post a Comment

Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")

Popular Posts

Enter your email address:

Buffs ...

Tags


Powered by WidgetsForFree

Archives