Skip to main content

PROGRAMMING IN JAVA ||UNIT 1- DECLARATIONS AND ACCESS CONTROL||JAVA IDENTIFIERS & KEYWORDS

 II BCA - CORE PAPER 3

PROGRAMMING IN JAVA

UNIT 1- DECLARATIONS AND ACCESS CONTROL

JAVA IDENTIFIERS & KEYWORDS



Java Identifiers

  • ·        An Identifiers is a name given to program elements such as class, variable, field, method, or constructor.
  • ·        In Java programming language an identifier is a sequence of alphabets or digits.
  • ·        The two aspects of Java identifiers are

o   Legal identifiers: The rules the compiler uses to determine whether a name is legal.

o   Oracle's Java Code Conventions:  Oracle's recommendations for naming classes, variables, and methods.

Legal Identifiers

  • Technically, legal identifiers must be composed of only Unicode characters, numbers, currency symbols, and connecting characters (such as underscores).
  • The rules for Legal Identifiers:

o   Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore (_).

o   Identifiers cannot start with a digit!

o   After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.

o   There is no limit to the number of characters an identifier can contain.

o   You can't use a Java keyword as an identifier.

o   Identifiers in Java are case-sensitive; For Example , foo and FOO are two different identifiers.

Examples of legal identifiers follow:

o   int _a;

o   int $c;

o   int ______2_w;

o   int _$;

o   int this_is_a_very_detailed_name_for_an_identifier;

The following are illegal identifiers:

o   int :b;

o   int -d;

o   int e#;

o   int .f;

o   int 7g;

Oracle's Java Code Conventions

  • Oracle has created a set of coding standards for Java and published those standards in a document titled as "Java Code Conventions", which is available at java.oracle.com.
  • The naming standards that Oracle recommends are,

1.      Classes and interfaces :

o   The first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase (a format that's sometimes called "CamelCase").

o   For classes, the names should typically be nouns. Here are some examples:

§  Dog

§  Account

§  PrintWriter

o   For interfaces, the names should typically be adjectives, like these:

§  Runnable

§  Serializable

2.    Methods:

o   The first letter should be lowercase, and then normal CamelCase rules should be used. In addition, the names should typically be verb-noun pairs.

o   For example:

§  getBalance

§  doCalculation

§  setCustomerName

3.    Variables:

o   Like methods, the CamelCase format should be used, but starting with a lowercase letter. Oracle recommends short, meaningful names, which sounds good to us.

o   Some examples:

§  buttonWidth

§  accountBalance

§  myString

4.    Constants:

o    Java constants are created by marking variables static and final.

o   They should be named using uppercase letters with underscore characters as separators:

§  MIN_HEIGHT

Java Keywords

·        Keywords are predefined, reserved words used in Java programming that have special meanings to the compiler.

·        For example:

int rollno;

 

·        Here, int is a keyword. It indicates that the variable “rollno” is of integer type.

·        Keywords cannot be used as variable name (or identifiers) as they are part of the Java programming language syntax.

·        The complete list of all keywords in Java programming.

Java Keywords List

abstract

assert

boolean

break

byte

case

catch

char

class

const

continue

default

do

double

else

enum

extends

final

finally

float

for

goto

if

implements

import

instanceof

int

interface

long

native

new

package

private

protected

public

return

short

static

strictfp

super

switch

synchronized

this

throw

throws

transient

try

void

volatile

while

 

 

Popular posts from this blog

XML TECHNOLGY FAMILY #3 - Advantages of XML Over HTML, EDI, Databases

Advantages of XML Over HTML , EDI , Databases

Java Program to implement inheritance || Java Programming Lab Exercise 2.1

  IMPLEMENTATION OF INHERITANCE What is Inheritance ? Ø   The process by which one class acquires the properties(data members) and functionalities(methods) of another class is called  inheritance . Ø   The aim of inheritance is to provide the reusability of code so that a class has to write only the unique features and rest of the common properties and functionalities can be extended from the another class. Aim:             To write a java program to implement the concept of inheritance. Procedure: Open text editor(notepad) Create a base class called “StudentBase” Declare & define department, collegeName as private data members of string datatype. Since the private data members cannot be   accessed directly, we are using public getter & setter methods   to access the private members of base class Create a derived class called “StudentDerive” that extends the base class “StudentBase” Declare & define regNo, sName as default data members of string datatype.