3. Some PCs might have Java already installed.
To check if you have Java installed on a
Windows PC, type the following in Command
Prompt (cmd.exe):
C:UsersYour Name>java -version
If Java is installed, you will see something like
this (depending on version):
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build
11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build
11.0.1+13-LTS, mixed mode)
Continued…
4. If you do not have Java installed on your computer, you
can download JDK(Java development Kit) for free
from oracle.com.
Install the JDK.
After Installation , Setting Path for Java.
Step: 1 Right click on My Computer icon and select properties.
Or
Go to "System Properties" (Can be found on Control Panel > System
and Security > System > Advanced System Settings)
7. Step:4 Then, select the "Path" variable in System
variables and click on the "Edit" button.
Click on the "New" button and add the path where Java is
installed, followed by bin. By default, Java is installed
in C:Program FilesJava……
8. You will have to add a new path with: C:Program
FilesJava…… and press OK.
At last, open Command Prompt (cmd.exe) and
type java -version to see if Java is running on your
machine.
9. To write your Java programs, you will need a text
editor.
Notepad − On Windows machine, you can use any
simple text editor like Notepad (Recommended for
this tutorial), TextPad.
Netbeans − A Java IDE that is open-source and free
which can be downloaded
from https://www.netbeans.org/index.html.
Eclipse − A Java IDE developed by the eclipse open-
source community and can be downloaded
from https://www.eclipse.org/.
11. Explanation :
class: class is a keyword is used to declare classes in java.
public: It is an access specifiers. Public means this
function is visible to all.
static: static is used to make a function static. To execute
a static function you do not have to create an Object
of the class. The main () method here is called by
jvm, without creating any object for class.
void: void is return type, meaning this function will not
return anything.
main(): This is the method which is executed hence all logic
must be inside the main() method. If a java class is
not having a main() method, it causes compilation
error.
System.out.println(): This is used to print anything on the
consol like printf()in
Continued…
12. Steps to compile and Run FirstJava Program
Step: 1 Open a text editor like Notepad and write the
code of First Java Program.
Step: 2 save the file as FirstJava.java
Step: 3 Open command prompt and go to the
directory where you saved your first java
program.
13. Step: 4 Type javac FirstJava.java then enter to
compile the program.
Step: 5 Now Type java FirstJava on command prompt
the enter to run program.
14. “Each and every smallest individual unit in a
program is known as tokens.”
The keywords, identifiers, constants, string
literals, and operators are examples of
tokens. Punctuation characters such as brackets
[ ], braces { }, parentheses ( ), and commas (,)
are also tokens.
15. “A variable is a container which holds the value while
the Java program is executed. A variable is assigned
with a data type.”
There are three types of variables in Java:
1) local variable 2) Instance variable 3) static variable
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.
Continued…
16. 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.
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.
18. “ Data types specify the different sizes and values
that can be stored in the variable.”
There are two types of data types in Java:
1) Primitive data types (PDT)
2) Non-primitive data types (NPDT)
1) Primitive data types :
A primitive data type specifies the size and type of
variable values, and it has no additional methods.
Continued…
19. There are eight primitive data types in Java:
Continued…
Data Type Size Description
byte 1 byte Stores whole numbers from -128 to 127
short 2 bytes Stores whole numbers from -32,768 to 32,767
int 4 bytes Stores whole numbers from -2,147,483,648 to
2,147,483,647
long 8 bytes Stores whole numbers from -
9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
float 4 bytes Stores fractional numbers. Sufficient for
storing 6 to 7 decimal digits
double 8 bytes Stores fractional numbers. Sufficient for
storing 15 decimal digits
boolean 1 bit Stores true or false values
char 2 bytes Stores a single character/letter or ASCII
values
20. 2) Non-primitive data types :
“ Non-primitive data types are called reference
types because they refer to objects.”
( Examples : Strings, Arrays, Classes, Interface, etc.)
Difference between (PDT) and (NPDT) are:
PDT are predefined in Java. NPDT are created by the
programmer and is not defined by Java (except for String).
NPDT can be used to call methods to perform certain
operations, while PDT cannot.
A PDT has always a value, while NPDT can be null.
A PDT starts with a lowercase letter, while NPDT starts with an
uppercase letter.
The size of a PDT depends on the data type, while NPDT have
all the same size.
21. Class : start with the uppercase letter.
Ex:-(public class Employee)
Interface : start with the uppercase letter.
Ex:-(interface Printable )
Method : start with lowercase letter.
Ex:- main(), print(), println().
Variable : start with a lowercase letter.
1) It should not start with the special characters like &
(ampersand), $ (dollar), _ (underscore).
2) Multiple words, start it with the lowercase letter
followed by an uppercase letter such as firstName.
Constant : uppercase letters such as RED, YELLOW.