Java Fundamentals Part-1
Java Fundamentals Part-1
Java Fundamentals
Java:
Java is a programming language, platform & technology.
Java is called as programming language because by using Java we can
write programs.
Platform:
It can be a software or hardware environment in which program runs.
C compiler converts unicode into bit code whereas Java
compiler converts unicode into byte code.
JVM:
JVM stands for Java Virtual Machine. It contains interpreter which
converts byte code into bit code.
Both compiler & interpreter are called translation softwares.
Differences between compiler & interpreter:
Compiler converts the whole program at a time whereas interpreter
converts line by line.
Compiler will produce the file whereas interpreter does not produce
the file.
C is a platform dependent whereas Java is a platform
independent.
Java is called as platform independent because programs
written in Java language can be executed on any platform.
Identifiers:
Identifier is a word and it is used to identify variables, methods, classes,
interfaces, packages, .. etc.,
Identifier can be a variable name, method name, class name, interface
name, package name, .. etc.,
Examples:
1) demo => Valid
2) Demo => Valid
3) DEMO => Valid
4) 2ndDemo => Not Valid
5) Demo2 => Valid
6) version#2 => Not Valid
7) version$2 => Valid
8) version_2 => Valid
9) version-2 => Not Valid
10) _5_ => Valid
11) _$2 => Valid
12) $_2 => Valid
13) 5_$ => Not Valid
Keywords:
A set of words reserved by language itself and those words are called
keywords.
Examples:
int, char, float, double, if, else, while, for, do, private, protected, public,
static, final, void, assert, enum, class, interface, package, ..etc.,
Literals:
A literal is a source code representation of a fixed value.
In Java, literals are divided into 6 categories:
1) Integer Literals:
Examples: 5, 9, 13, 467, 0, -2, -98, -987
2) Floating Point Literals:
Examples: 2.46, 0.08, -2.46, -999.3566
3) Character Literals:
Examples: 'a', 'x', 'A', 'Z', 'c'
4) String Literals:
Examples: "a", "hi", "hello", "welcome"
5) Boolean Literals:
Examples: true, false
6) Object Literal:
Example: null
Data Types:
A data type that determines what value variable can hold and what are
the operations can performed on variables.
In Java, data types are divided into 2 categories:
1) Primitive Data Types
2) Reference Data Types
Variables:
A variable is a container that contains data.
Declaration:
Syntax: DataType Variable;
Example: int x;
Assignment:
Syntax: Variable=Literal;
Example: x=10;
Initialization:
Syntax: DataType Variable=Literal;
Example: int x=10;
If the number is out of int range & within long range(long literal) then it
must be suffixed with l or L.
Every float literal must be suffixed with f or F;
ASCII Code: Digits starts with 48, Capital letters starts with 65 &
Small letters starts with 97.
By