Installing Java Development Kit (JDK) and Setting Up
the Environment
What is JDK?
JDK (Java Development Kit) is a software development
environment used for developing Java applications and
applets. It includes the Java Runtime Environment (JRE), an
interpreter/loader (Java), a compiler (javac), an archiver
(jar), a documentation generator (Javadoc), and other tools
needed in Java development.
Installing JDK:
. Go to the official Oracle website
(https://www.oracle.com/java/technologies/javase-jdk15-
downloads.html) and download the latest version of JDK.
. After downloading, open the installer and follow the
instructions to install JDK on your system.
. Once installation is complete, verify the installation by
opening a command prompt (Windows) or terminal
(Mac/Linux) and typing the following command:
java -version
javac -version
The output should display the version number of Java and
javac, indicating that JDK is installed properly.
Setting Up the Environment:
After installing JDK, the next step is to set up the
environment. This involves setting the PATH and JAVA_HOME
variables.
Windows:
. Right-click on "Computer" or "This PC" and select
"Properties."
,. Click on "Advanced system settings" and then click on the
"Environment Variables" button.
. Under "User variables," click on "New" and add a variable
named JAVA_HOME with the value set to the installation path of
JDK (e.g., C:\Program Files\Java\jdk-15.0.2).
. Under "System variables," scroll down and find
the PATH variable. Select it and click on "Edit."
. Add the following value in the "Variable value"
field: %JAVA_HOME%\bin;
. Click on "OK" to close all windows and save the changes.
Mac/Linux:
. Open a terminal and open the .bash_profile or .zshrc file
using a text editor (e.g., nano ~/.bash_profile).
. Add the following lines to the file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-
15.0.2.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
Replace jdk-15.0.2 with the version number of JDK installed
on your system.
. Save the file and close the text editor.
. Restart the terminal and verify the environment variables by
typing the following command:
echo $JAVA_HOME
echo $PATH
The output should display the installation path of JDK and
the bin directory included in the PATH variable.
Conclusion:
After following the above steps, you have successfully
installed JDK and set up the environment. You can now start
developing Java applications and applets using the tools
included in JDK.
In Java, there are two types of data types: primitive and
reference. Primitive data types are predefined by the language
and include:
,. boolean: represents a single binary value, either true or false.
Example:
boolean isRaining = true;
. char: represents a single character, enclosed in single quotes.
Example:
char initial = 'J';
. byte: represents a 8-bit signed integer value, between -128 and
127.
Example:
byte grade = 85;
. short: represents a 16-bit signed integer value, between -32,768
and 32,767.
Example:
short year = 2023;
Working with Non-Primitive
Data Types in Java
Classes: blueprint for creating objects (e.g. String, Scanner,
JFrame)
Interfaces: defines a set of methods that a class can
implement
Arrays: a collection of elements of the same type
Enums: a type of class with a set of predefined constants
Declaring and Initializing Variables in
Java
Just like you would with primitive data types, you can declare
variables that reference non-primitive data types. You need to
use the keyword new to create instances (objects) of non-
primitive data types, and assign them to your variables. For
example:
String name = new String("John Doe");
Date today = new Date();
, Understanding Java Syntax and Basic
Programming Concepts
To work with non-primitive data types, it is essential to have a
good understanding of Java syntax and basic programming
concepts. This includes logical operators, exception handling,
functions and methods, conditional statements, loops, and
operators.
Understanding Exception Handling in
Java Programming
Exceptions are events that interrupt the normal flow of
instruction execution in a program. Exception handling is the
process of handling these error events in Java. Exception
handling is an essential concept when working with non-primitive
data types in Java.
Logical Operators and Their
Applications in Java
Logical operators are used to create complex conditions in Java.
Logical operators and conditional statements are the foundation
of if statements and loops.
Exploring Functions and Methods in
Java Programming
Functions (also known as methods) are used to perform specific
actions in Java. They are crucial to writing reusable and
organized code.
Creating and Using Methods in Java
Classes
Methods in Java can be created and used in classes to perform
specific actions. When creating methods, you need to define the
method's return type, name, parameters, and code block.
Working with Conditional Statements
and Loops in Java
Conditional statements and loops are essential to writing
programs that make decisions and repeat actions. This includes
if statements, switch statements, for loops, while loops, and do-
while loops.