Java Lecture1
Language Fundamentals
1. Identifiers
2. Reserve words
3. data types
4. Literals
5. Arrays
6. Types of variables
7. var-args method
8. main method
9. command line arguments
10. java coding standard
--------------------
1. Identifiers
a name in java program is called identifiers, which can be used for identification purpose it can be method name, class name, variable name or label name.
class Test#1#
{
public static void main#2#(String#3# ar#4#[])
{
int x#5#=10;
}
}
in this how many identifiers are there???
Rules for defining java identifiers
1. the only allowed character in java identifiers are ---> a to z, A to Z, 0 to 9, $ and _ if we are using any other character we will get compile time error.
example
total_number valid
total# invalid
2.identifiers cant starts with digit
total123 valid , 123total invalid
java identifiers are case sensitive offcourse java language itself considered as case sensitive programming language.
Example: --
class Test
{
int number= 10;
int Number =20;
int NUMBER=30;
}
we can differentiate with respect to case.
4. there is no length limit for java identifiers
but it is not recommended to take too lengthy identifiers
5. we cant use reserved word as identifiers
int x =10; valid
int if=20; invalid
6. all predefined java class name and interface names we can use as identifiers
Example:
class Test
{
public static void main(String ar[])
{
int String =888;
SOP(String); //valid
int Runnable = 999;
SOP(Runnable); //valid
}
}
even though it is valid but it is not a good programming practice because it reduces readability and creates confusion.
which of the following are valid java identifiers?
total_number
total# // invalid
123total // invalid
total123
ca$h
_$_$_$_$_$
all@hands // invalid
java2share
Integer
Int
int // invalid
==================================
Reserved words
In java some words are reserved to represent some meaning or functionality such type of words are called reserved words.
total 53 reserved words
3 reserved literals(true, false,null)
2 unused keywords(goto, const)
48 used keywords --- if, else, for, int.....
keywords for datatypes
byte, short, int, float, long, double, boolean, char(8)
keywords for flow control
if, else, switch, case, default, while, do, for, break, continue, return(11)
keywords for modifiers
public, private, protected, static, final, abstract, synchronized, native, strictfp, transient, volatile(11)
keywords for exception handling
try, catch, finally, throw, throws, assert(6)
class related keywords
class, interface, extends, implements, package, import(6)
object related keywords
new, instanceof, super, this(4)
other keywords
void - return type keywords(if any method wont return anything)
in java return type is mandatory if a method wont return anything then we have to declare that method with void return type but in c language return type is optional and default return type is int
unused keywords
goto - uses of goto created several problems in old languages and hence sun people banned this keyword in java
& const - use final instead of const
Note: goto and const are unused keywords and if we are trying to use we will get compile time error.
Reserved laterals:
true
false // values for Boolean data types
null // default value for object reference
enum keyword
we can use enum to defined a group of named constants
enum month{
jan, feb, march.....dec;
}
========================
conclusion
1. all 53 rserved words in java contains only lowercase alphabet symbols
2. in java we have only new keyword and there is no delete keyword in java because destruction of useless objects is the responsibility of garbage collector.
3. the following are new keywords in java - strictfp, assert, enum
Comments
Post a Comment