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

EVOLVING ROLE OF SOFTWARE

EVOLVING ROLE OF SOFTWARE Software is both a product and a vehicle for delivering a product.

OPERATING SYSTEM || UNIT III || Memory Management - Basic Concept of Memory - Address Binding - Logical & Physical Address Space

  OPERATING SYSTEM UNIT III Memory Management ·          Memory Management is the process of coordinating and controlling the memory in a computer, Blocks are assigning portions that are assigned to various running programs in order to optimize the overall performance of the system. Computer Memory ·          Computer memory can be defined as a collection of some data represented in the binary format. ·          On the basis of various functions, memory can be classified into various categories. We will discuss each one of them later in detail. ·          A computer device that is capable to store any information or data temporally or permanently is called storage device. Need for Memory Management in OS Memory management technique is needed for the following reasons: Allocate and de-allocate memor...

Operating System || Unit I || Process Management

  Operating System Unit I Process Management Introduction to Process: A program in execution is called a process. The execution of a process must progress in a sequential fashion. In order to complete its task, process needs the computer resources. A process can be defined as an entity which represents the basic unit of work to be implemented in the system. The operating system has to manage all the processes which require the same resource at the same time , in a convenient and efficient way. The Process Management Involves, Scheduling processes and threads on the CPUs. Creating and deleting both user and system processes. Suspending and resuming processes. Providing mechanisms for process synchronization. Providing mechanisms for process communication. Process Architecture A program becomes a process, when it is loaded into the memory. A process in memory can be divided in 4 sect...