Java Introduction:
Java is an open-source programming language designed for
building applications across various platforms.
Purpose
of Communication:
- Human Communication: English language
- Machine Communication: Programming language
- to establish communication
b/w 2 things
- English -->
English lang
- Machine --->
Programming language
Program: A collection of statements used
to perform specific tasks.
- Example:
- Addition: 10+20=30
- Subtraction: 20−10=10
Java: An
Object-Oriented Programming Language
This means that in Java, everything is represented in the
form of objects and classes.
OOP
Features:
- Object & Class
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
Examples
of Object-Oriented Programming Languages:
- Java
- C#.NET
- Python
If any programming language supports the above OOP features,
it is considered an object-oriented programming language.
Platform
Independence:
Java is a
platform-independent language.
Platform: Any
operating system (e.g., Windows, Linux, macOS)
A.java (Java
Source Code)
- Run on Windows: Produces A Results (Same results)
- Run on Linux: Produces A Results (Same results)
- Run on macOS: Produces A Results (Same results)
When you compile and run a Java program, you get the same
results regardless of the operating system:
Platform
Dependent Languages:
For
example, C language is platform dependent:
- A.c (C Source Code)
- Run on Windows: Produces A Results
- Run on Linux: Produces B Results
Note: VBScript is specific to the
Windows operating system.
Java
Applications:
- Desktop Applications
- Examples: vlc.exe, Notepad (text file)
- Web-Based Applications
- Examples: amazon.com, facebook.com
- Mobile Applications (Android apps)
- Examples: WhatsApp, Amazon
- ERP Applications
- Example: Salesforce
- Automation Testing Tools
- Java can be used in various
automation testing tools.
FAQ: JDK,
JRE, JVM
JDK: Java Development Kit
- Used to develop and write
Java programs as well as run them.
- JDK is software.
JRE: Java Runtime Environment
- Used to run Java programs
only.
- Note: You cannot write or develop
Java programs using JRE.
- Can be installed
individually.
- When you install JDK, it
includes JRE by default.
- JDK contains JRE. JRE is
part of JDK.
JDK = JRE
+ JVM + LIB + BIN + etc.
FAQ: What is the difference
between JDK and JRE?
JVM : Java Virtual
Machine
A set of programs or specifications used to execute Java
programs.
Java was developed by James Gosling and his team at Sun
Microsystems.
Sun Microsystems was later acquired by Oracle Corporation in
2010.
JDK 11
Installation Guide:
- Download JDK 11:
- Visit the JDK 11 download
page: JDK 11 Archive Downloads.
- Click on the download link
for your operating system (Windows x64 in this case).
https://www.oracle.com/in/java/technologies/javase/jdk11-archive-downloads.html
Note : after
clicking download link > Select
checkbox 'I reviewed and accept the Oracle Technology Network License Agreement
for Oracle Java SE
' --> Click on the Download button.> Create Oracle account with y gmail and password > login with ur gmail > Navigate to your Downloads folder and locate jdk-11.0.15.1_windows-x64_bin.exe.>
Click download > it will download - "jdk-11.0.15.1_windows-x64_bin.exe"
Click jdk.exe file
from downloads folder> Click Next > Next >
Finish
Checking
if Java is Installed:
After
installation, you can check if Java is properly installed on your system:
C:\Program
Files\Java\jdk-11.0.15.1
- Open Command Prompt (CMD):
Pressing 'Windows' btn + R -->
It opens 'Run' window > Type 'cmd'
> clikc 'Ok' or Press enter button >
opens 'Cmd prompt window' in
black screen
java -version
ex:
C:\Users\Lenovo>java -version
java version "11.0.15.1" 2022-04-22 LTS
Java(TM) SE Runtime Environment 18.9 (build
11.0.15.1+2-LTS-10)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build
11.0.15.1+2-LTS-10, mixed mode)
Download
Eclipse:
- Visit the Eclipse Download
Page.
- Choose the appropriate
version for your operating system and download Eclipse IDE.
Open
Eclipse:
- Extract the downloaded
Eclipse package.
- Launch Eclipse by
double-clicking on the eclipse.exe (or
eclipse on Linux) file.
Create
Workspace:
- When Eclipse opens, it will
prompt you to select a workspace directory.
- Choose or create a new
directory where you want to store your Eclipse projects.
- Click Launch to open Eclipse with the
selected workspace.
Create
Project:
- Steps:
File >NEw > Other >
Search for JAva Project > Select 'Java Project > Click
"Next" > ' Give some "Project name" i.e "Nov182023JavaProject" >
finish or Next> Click Finish
button > click 'Dont create ' button > it creates new Project i.e
'Nov182023JavaProject" in 'package explorer' window in left side
If we expand Java project,
there are 2 folders available .
1. src
2.JRE System
Libraries
Check
Project Current Location in our system:
- Steps:
- Right-click on the project
(Nov182023JavaProject) in the Package Explorer.
- Select Properties (or press Alt + Enter).
- In the Properties dialog, navigate to the Resource section.
- Under Location, you can see the current
directory path where the project is stored, e.g., C:\brahma\Practise\SelniumPractiseNew\Nov2023WorkSpace\Nov182023JavaProject.
- Click the right arrow
button to open the folder in your system's file explorer.
HW Create 2 Java Projects in Eclipse and find the location of the project in ur
system ?
Keywords in Java:
To learn any language, we start with the alphabets: A, B, C.
· From
alphabets, we make words: Apple, Bat, etc.
· From words, we make sentences:
"I like an apple." (We
must follow grammar rules for valid sentences,
e.g., "Apple like I" is invalid
make stmt -
> I like an apple - -->
have to follow some grammar rules --> Syntax rules
Apple like I ---invalid stmt
I apple like
A computer system does not understand human language (e.g.,
English)
Java language statements are translated into machine-level
language (binary code: 001010101) that the system or processor understands.
System will not understand our English language --> java lang
stmts---> Machine Level Lang
(001010101) -- (Sys or Processor understands)
Keywords:
Definition:
- Keywords are predefined
words in the Java language.
- They are reserved words with
special meanings in Java, used for specific purposes.
Examples of Keywords:
· int:
Used to store integer numbers, e.g., 10, 20, -15.
· float:
Used to store decimal numbers with an 'f' suffix, e.g., 10.23f, 4.5f.
· double:
Used to store decimal numbers, e.g., 10.23, 4.5.
· char:
Used to store a single character, e.g., 'A', 'B'.
· boolean: Used to store boolean values,
true or false.
if --> k/w in java , can be used write if (condi)
stmt
else -->
for
while
break
class --> is k/w
in java lang-can be used to define/
write class
Syntax:
class someClassName
{
}
ex2: creating some
'employee' class
class employee
{
}
ex3: create student
class
class student
{
}
Note:
·
Without
writing/defining any class, we cannot write any Java program.
- If we want to write any Java
program, we must write/define a class.
Interface:
An interface is a keyword in Java used to define a contract that other
classes can implement.
syntax :
interface I1
{
}
public
static
void
...etc
Create Package and
Class:
A package
is a collection of classes and interfaces.
- class1 + Interface1
- class2 + Interface2
- class3 + Interface3
Create
Package:
Steps:
- Select the src folder.
- Right-click on the src folder.
- Select New > Package.
- Enter the name: package1.
- Click the Finish button.
This will
create a new package named package1 in the src folder.
Create
Class:
Steps:
- Select the package package1.
- Right-click on package1.
- Select New > Class.
- Enter a class name: class1.
- Click the Finish button.
This will
create a new class named class1 in the selected package package1.
Create Interface :
HW : write Navigation
steps how to create interface (same
as above)
HW Create 2 packages, 2 classes , 2 interfaces
Package: MyJavaPrograms --->
create some classes (A, B) + interfaces (I3,I4)
Package :
MySeleniumPrograms --> Create some classes(C1,C2) + interfaces (I5,I6)
No comments:
Post a Comment