Archive for the ‘java basics’ Category

variable

Posted: December 17, 2014 in java basics

Variable is just like container that holds some content or value in it. It has its own rage or size and type.

 

variables in java

java variable

 

________________________________________________________________________________

constant

Posted: December 17, 2014 in java basics

Constants:-  as the name sought these are fixed values which can never be change.

Example:

final int MAX_AGE=29;

“final” keyword is used to declare a constant in java.

________________________________________________________________________________

keywords

Posted: December 17, 2014 in java basics
Tags:

keywords:- Keywords are reserved words which has some special meaning for the compiler.  they can not be used as identifiers. if so, compiler will show error.

Example

if, goto, while, for etc.

 

Complete list of java keywords

java keywords

java keywords

 

________________________________________________________________________________


data types can be categorized into two category and so variable.

  • Primitive Type and
  • Reference Type

Primitive Type – Primitives are like the cups at the Coffee-House They come in different sizes and each has name like small , big, medium. Java primitives come in different sizes and name. You must declare a variable with a specific type.

Example

byte x=10; // Take 1 byte in memory

short y=500; // Take 2 bytes in memory

int a=40000; // Take 4 bytes in memory

data types

data types

 

Primitive Data Types List

In Java, primitives come in different sizes with different names. When you declare a variable in Java, you must declare with a specific type.

data type size list

java primitive

 

Reference type

A Reference variable holds bits that represents a way to access an object. It doesn’t hold the object itself, but it holds something like reference address to the object. Reference type does not have size or bit depth.

java reference type

reference type

 

_______________________________________________________________________________

java coding conventions

Posted: December 17, 2014 in java basics

Class and Interfaces – The First letter should be capital, and first letter of the inner words should be Capital.

Example : Account

PrintWriter

Emp

Runnable

Methods – The First Letter should be lowercase, and then normal camelCase rules should be used. Name should be noun-verb pairs.

Example

getBalance

setCustomerName

Variables – Same rule as Method Rule.

Example

buttonWidth

myString

Constants – All in Uppercase.

Example

MIN_HEIGHT

________________________________________________________________________________

Identifiers

Posted: December 17, 2014 in java basics
Tags: ,

Identifier is a name given to a class, variable, constant or method.

Rules for Declaring a Legal Identifier:

  1.  Identifier must start with a letter, $, _. Cannot start with number.
  2.  After the first letter, contain numeric.
  3.  No Limit to the number of characters an identifier can contain.
  4.  Cannot use keyword in identifier name.
  5.  Identifiers are case-sensitive.

Example of legal identifiers

int _a;

int $count;

int ____ag_e;

int _$;

int detaild_name_for_identifier;

 

Example of illegal identifiers

int :a;

int -count;

int age#;

int .first;

int 3s;