Java Fundamental2
Java Fundamental2
CLASS- 2
Identifiers, variables, keywords
Anshuman Dixit
First Java Program
To create a simple java program, you need to
create a class that contains the main method.
The requirements for Java programs:
• For executing any java program, you need to
install the JDK if you don't have installed
it, download the JDK and install it.
• Set path of the jdk/bin directory.
• Create the java program
• Compile and run the java program
Anshuman Dixit
Parameters used in Java Program
• class keyword is used to declare a class in java.
• public keyword is an access modifier which represents
visibility. It means it is visible to all.
• static is a keyword. If we declare any method as static,
it is known as the static method. The core advantage of
the static method is that there is no need to create an
object to invoke the static method. The main method is
executed by the JVM, so it doesn't require to create an
object to invoke the main method. So it saves memory.
• void is the return type of the method. It means it
doesn't return any value.
• main represents the starting point of the program.
• String[] args is used for command line argument.
• System.out.println() is used to print statement..
Anshuman Dixit
Java Identifiers
Indentifies are basically a name in java program
for identify the objects.
It can be a class name, variable name or method
name.
There are following rules to define java
identifiers:
• Only allowed characters can be the part of
java identifiers, such as:
a to z, A to Z, 0 to 9 and $ (dollar symbol).
Anshuman Dixit
Java Identifiers
• Identifiers can’t start with digits.
• Identifiers are case sensitive.
• There is no length limit for identifiers but not
recommended to take too lengthy identifiers.
• Any keyword can’t be used as identifiers.
• Pre defined class names and interface names
can be used as identifiers.
• From java 9 version, _ is a keyword, so can’t
be used as identifiers.
Anshuman Dixit
Java Variables
A variable is a container which holds the value while
the Java program is executed. A variable is
assigned with a data type.
Variable is a name of memory location.
There are three types of variables in java:
1. Local Variable: A variable declared inside the
body of the method is called local variable. You
can use this variable only within that method
and the other methods in the class aren't even
aware that the variable exists.
A local variable cannot be defined with "static"
keyword.
Anshuman Dixit
Java Variables
2. Instance Variable: A variable declared inside the
class but outside the body of the method, is called
instance variable. It is not declared as static.
It is called instance variable because its value is
instance specific and is not shared among instances.
3. Static variable: A variable which is declared as static
is called static variable. It cannot be local. You can
create a single copy of static variable and share
among all the instances of the class. Memory
allocation for static variable happens only once when
the class is loaded in the memory.
Anshuman Dixit
Java Keywords
Java keywords are also known as reserved words.
Keywords are particular words which acts as a key to a
code. These are predefined words by Java so it
cannot be used as a variable or object name.
Keywords are those words, which meaning is already
know by compiler.
Java contains 48 keywords and each word has its own
importance and functionality.
Anshuman Dixit
Java Keywords
Abstract Boolean Break Byte Case Catch
Anshuman Dixit
• Data types
Anshuman Dixit