SlideShare a Scribd company logo
MGMโ€™s College of Engineering &
Technology, Kamothe.
Department of Computer Engineering
Subject: Object Oriented Programming with Java
(CSL304)
Second Year โ€“ Semester III
A.Y. โ€“ 2022-23
Subject In-charge: Prof. Vijay R Bhosale
Syllabus
Syllabus
OOP stands for Object-Oriented Programming.
๏‚— Procedural programming is about writing procedures or
methods that perform operations on the data, while
object-oriented programming is about creating objects
that contain both data and methods.
Object-oriented programming has several advantages
over procedural programming:
๏‚— OOP is faster and easier to execute
๏‚— OOP provides a clear structure for the programs
๏‚— OOP helps to keep the Java code DRY "Don't Repeat
Yourself", and makes the code easier to maintain,
modify and debug
๏‚— OOP makes it possible to create full reusable
applications with less code and shorter development
time
What are Classes and Objects?
๏‚— So, a class is a template for objects, and an object is an
instance of a class.
๏‚— When the individual objects are created, they inherit all the
variables and methods from the class.
What is Java?
Java is a popular programming language, created in
1995.
๏‚— It is owned by Oracle, and more than 3
billion devices run Java.
It is used for:
๏‚— Mobile applications (specially Android apps)
๏‚— Desktop applications
๏‚— Web applications
๏‚— Web servers and application servers
๏‚— Games
๏‚— Database connection
And much, much more!
Why Use Java?
๏‚— Java works on different platforms (Windows, Mac,
Linux, Raspberry Pi, etc.)
๏‚— It is one of the most popular programming language
in the world
๏‚— It is easy to learn and simple to use
๏‚— It is open-source and free
๏‚— It is secure, fast and powerful
๏‚— It has a huge community support (tens of millions of
developers)
๏‚— Java is an object oriented language which gives a
clear structure to programs and allows code to be
reused, lowering development costs
๏‚— As Java is close to C++ and C#, it makes it easy for
Java Install
๏‚— To check if you have Java installed on a Windows PC,
search in the start bar for Java or type the following in
Command Prompt (cmd.exe):
๏‚— If Java is installed, you will see something like this
(depending on version):
๏‚— If you do not have Java installed on your computer, you
can download it for free at oracle.com.
๏‚— Note: We can use โ€œnotepadโ€, โ€œnotepad++โ€ for writing
java code. However, it is possible to write Java in an
Integrated Development Environment, such as IntelliJ
IDEA, Netbeans or Eclipse, which are particularly useful
when managing larger collections of Java files.
Download Java
๏‚— https://www.oracle.com/java/technologies/javase-
jdk16-downloads.html
Run the downloaded file and click
next
Click next
Progress......
Progress.....
Java successfully installed.
1. Go to "System Properties"
(Can be found on Control Panel >
System and Security > System >
Advanced System Settings)
2. Click on the "Environment
variables" button under the
"Advanced" tab
3. Then, select the "Path" variable in
System variables and click on the
"Edit" button
4. Click on the "New" button and add the path where
Java is installed, followed by bin. By default, Java is
installed in C:Program FilesJavajdk-11.0.1 (If nothing
else was specified when you installed it).
In that case, You will have
to add a new path
with: C:Program Files
Javajdk-11.0.1bin
Then, click "OK",
and save the settings
5. At last, open Command Prompt
(cmd.exe) and type java -version to
see if Java is running on your
machine
Creating first Java file
๏‚— In Java, every application begins with a class name,
and that class must match the filename.
๏‚— Let's create our first Java file, called Main.java, which
can be done in any text editor (like Notepad).
๏‚— The file should contain a "Hello World" message, which
is written with the following code:
๏‚— Save the code in Notepad as "Main.java". Open
Command Prompt (cmd.exe), navigate to the directory
where you saved your file, and type "javac Main.java":
๏‚— Save the code in Notepad as "Main.java". Open
Command Prompt (cmd.exe), navigate to the directory
where you saved your file, and type "javac Main.java":
๏‚— This will compile your code. If there are no errors in the
code, the command prompt will take you to the next
line. Now, type "java Main" to run the file:
๏‚— The output will be:
Explanation
๏‚— Every line of code that runs in Java must be inside
a class.
๏‚— In our example, we named the class Main. A class
should always start with an uppercase first letter.
Note: Java is case-sensitive: "MyClass" and "myclass"
has different meaning.
๏‚— The name of the java file must match the class name.
When saving the file, save it using the class name and
add ".java" to the end of the filename.
The main Method
๏‚— The main() method is required and you will see it in
every Java program:
๏‚— Any code inside the main() method will be executed.
You don't have to understand the keywords before and
after main. You will get to know them bit by bit while
reading this tutorial.
๏‚— For now, just remember that every Java program has
a class name which must match the filename, and that
every program must contain the main() method.
System.out.println()
๏‚— Inside the main() method, we can use
the println() method to print a line of text to the
screen:
๏‚— Code:
๏‚— O/P:
๏‚— Note: The curly braces {} marks the beginning
and the end of a block of code.
๏‚— Note: Each code statement must end with a
Java Classes/Objects
๏‚— Java is an object-oriented programming language.
๏‚— Everything in Java is associated with classes and
objects, along with its attributes and methods. For
example: in real life, a car is an object. The car
has attributes, such as weight and color, and methods,
such as drive and brake.
๏‚— A Class is like an object constructor, or a "blueprint" for
creating objects.
Create a Class
๏‚— To create a class, use the keyword class:
Create an Object
๏‚— In Java, an object is created from a class. We have
already created the class named Main, so now we can
use this to create objects.
๏‚— To create an object of Main, specify the class name,
followed by the object name, and use the keyword new:
๏‚— Code:
๏‚— O/P:
We can create multiple objects of one class:
Code:
O/P:
๏‚— Using Multiple Classes
๏‚— You can also create an object of a class
and access it in another class. This is often
used for better organization of classes
(one class has all the attributes and methods,
while the other class holds the main() method
(code to be executed)).
๏‚— Remember that the name of the java file
should match the class name. In this example,
๏‚— we have created two files in the same
directory/folder:
1. Main.java
2. Second.java
๏‚— When both files have been compiled:
๏‚— Run the Second.java file: O/P:

More Related Content

Similar to OOPM Introduction.ppt

Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
sotlsoc
ย 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
J. C.
ย 
Java platform
Java platformJava platform
Java platform
BG Java EE Course
ย 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
Khurshid Asghar
ย 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
Madhura Bhalerao
ย 
Java interview question
Java interview questionJava interview question
Java interview question
simplidigital
ย 
Javanotes
JavanotesJavanotes
Javanotes
John Cutajar
ย 
1 2 java development
1 2 java development1 2 java development
1 2 java development
Ken Kretsch
ย 
R:\ap java\class slides\chapter 1\1 2 java development
R:\ap java\class slides\chapter 1\1 2 java developmentR:\ap java\class slides\chapter 1\1 2 java development
R:\ap java\class slides\chapter 1\1 2 java development
Ken Kretsch
ย 
Chapter 1
Chapter 1Chapter 1
Chapter 1
siragezeynu
ย 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Krishnaov
ย 
Java_presesntation.ppt
Java_presesntation.pptJava_presesntation.ppt
Java_presesntation.ppt
VGaneshKarthikeyan
ย 
INTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATIONINTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATION
Ajit Yadav
ย 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
vmadan89
ย 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
Pratima Parida
ย 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
Pratima Parida
ย 
OOP-Chap2.docx
OOP-Chap2.docxOOP-Chap2.docx
OOP-Chap2.docx
NaorinHalim
ย 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Ali Baba
ย 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdf
AdiseshaK
ย 
Java Programming
Java ProgrammingJava Programming
Java Programming
Anjan Mahanta
ย 

Similar to OOPM Introduction.ppt (20)

Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
ย 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
ย 
Java platform
Java platformJava platform
Java platform
ย 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
ย 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
ย 
Java interview question
Java interview questionJava interview question
Java interview question
ย 
Javanotes
JavanotesJavanotes
Javanotes
ย 
1 2 java development
1 2 java development1 2 java development
1 2 java development
ย 
R:\ap java\class slides\chapter 1\1 2 java development
R:\ap java\class slides\chapter 1\1 2 java developmentR:\ap java\class slides\chapter 1\1 2 java development
R:\ap java\class slides\chapter 1\1 2 java development
ย 
Chapter 1
Chapter 1Chapter 1
Chapter 1
ย 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
ย 
Java_presesntation.ppt
Java_presesntation.pptJava_presesntation.ppt
Java_presesntation.ppt
ย 
INTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATIONINTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATION
ย 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
ย 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
ย 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
ย 
OOP-Chap2.docx
OOP-Chap2.docxOOP-Chap2.docx
OOP-Chap2.docx
ย 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
ย 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdf
ย 
Java Programming
Java ProgrammingJava Programming
Java Programming
ย 

Recently uploaded

Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
ย 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
ย 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
ย 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
ย 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
ย 
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
ย 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
ย 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
ย 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
ย 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
ย 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
ย 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
ย 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
ย 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Vivekanand Anglo Vedic Academy
ย 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
ย 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
ย 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
ย 
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Nguyen Thanh Tu Collection
ย 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
ย 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
ย 

Recently uploaded (20)

Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
ย 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
ย 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
ย 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
ย 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
ย 
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Prรฉsentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
ย 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
ย 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
ย 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
ย 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
ย 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
ย 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
ย 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
ย 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
ย 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
ย 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
ย 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
ย 
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
ย 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
ย 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
ย 

OOPM Introduction.ppt

  • 1. MGMโ€™s College of Engineering & Technology, Kamothe. Department of Computer Engineering Subject: Object Oriented Programming with Java (CSL304) Second Year โ€“ Semester III A.Y. โ€“ 2022-23 Subject In-charge: Prof. Vijay R Bhosale
  • 2.
  • 3.
  • 4.
  • 7.
  • 8.
  • 9. OOP stands for Object-Oriented Programming. ๏‚— Procedural programming is about writing procedures or methods that perform operations on the data, while object-oriented programming is about creating objects that contain both data and methods. Object-oriented programming has several advantages over procedural programming: ๏‚— OOP is faster and easier to execute ๏‚— OOP provides a clear structure for the programs ๏‚— OOP helps to keep the Java code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug ๏‚— OOP makes it possible to create full reusable applications with less code and shorter development time
  • 10. What are Classes and Objects? ๏‚— So, a class is a template for objects, and an object is an instance of a class. ๏‚— When the individual objects are created, they inherit all the variables and methods from the class.
  • 11. What is Java? Java is a popular programming language, created in 1995. ๏‚— It is owned by Oracle, and more than 3 billion devices run Java. It is used for: ๏‚— Mobile applications (specially Android apps) ๏‚— Desktop applications ๏‚— Web applications ๏‚— Web servers and application servers ๏‚— Games ๏‚— Database connection And much, much more!
  • 12. Why Use Java? ๏‚— Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) ๏‚— It is one of the most popular programming language in the world ๏‚— It is easy to learn and simple to use ๏‚— It is open-source and free ๏‚— It is secure, fast and powerful ๏‚— It has a huge community support (tens of millions of developers) ๏‚— Java is an object oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs ๏‚— As Java is close to C++ and C#, it makes it easy for
  • 13. Java Install ๏‚— To check if you have Java installed on a Windows PC, search in the start bar for Java or type the following in Command Prompt (cmd.exe): ๏‚— If Java is installed, you will see something like this (depending on version): ๏‚— If you do not have Java installed on your computer, you can download it for free at oracle.com. ๏‚— Note: We can use โ€œnotepadโ€, โ€œnotepad++โ€ for writing java code. However, it is possible to write Java in an Integrated Development Environment, such as IntelliJ IDEA, Netbeans or Eclipse, which are particularly useful when managing larger collections of Java files.
  • 15. Run the downloaded file and click next
  • 20.
  • 21. 1. Go to "System Properties" (Can be found on Control Panel > System and Security > System > Advanced System Settings)
  • 22. 2. Click on the "Environment variables" button under the "Advanced" tab
  • 23. 3. Then, select the "Path" variable in System variables and click on the "Edit" button
  • 24. 4. Click on the "New" button and add the path where Java is installed, followed by bin. By default, Java is installed in C:Program FilesJavajdk-11.0.1 (If nothing else was specified when you installed it). In that case, You will have to add a new path with: C:Program Files Javajdk-11.0.1bin Then, click "OK", and save the settings
  • 25. 5. At last, open Command Prompt (cmd.exe) and type java -version to see if Java is running on your machine
  • 26. Creating first Java file ๏‚— In Java, every application begins with a class name, and that class must match the filename. ๏‚— Let's create our first Java file, called Main.java, which can be done in any text editor (like Notepad). ๏‚— The file should contain a "Hello World" message, which is written with the following code: ๏‚— Save the code in Notepad as "Main.java". Open Command Prompt (cmd.exe), navigate to the directory where you saved your file, and type "javac Main.java":
  • 27. ๏‚— Save the code in Notepad as "Main.java". Open Command Prompt (cmd.exe), navigate to the directory where you saved your file, and type "javac Main.java": ๏‚— This will compile your code. If there are no errors in the code, the command prompt will take you to the next line. Now, type "java Main" to run the file: ๏‚— The output will be:
  • 28. Explanation ๏‚— Every line of code that runs in Java must be inside a class. ๏‚— In our example, we named the class Main. A class should always start with an uppercase first letter. Note: Java is case-sensitive: "MyClass" and "myclass" has different meaning. ๏‚— The name of the java file must match the class name. When saving the file, save it using the class name and add ".java" to the end of the filename.
  • 29. The main Method ๏‚— The main() method is required and you will see it in every Java program: ๏‚— Any code inside the main() method will be executed. You don't have to understand the keywords before and after main. You will get to know them bit by bit while reading this tutorial. ๏‚— For now, just remember that every Java program has a class name which must match the filename, and that every program must contain the main() method.
  • 30. System.out.println() ๏‚— Inside the main() method, we can use the println() method to print a line of text to the screen: ๏‚— Code: ๏‚— O/P: ๏‚— Note: The curly braces {} marks the beginning and the end of a block of code. ๏‚— Note: Each code statement must end with a
  • 31. Java Classes/Objects ๏‚— Java is an object-oriented programming language. ๏‚— Everything in Java is associated with classes and objects, along with its attributes and methods. For example: in real life, a car is an object. The car has attributes, such as weight and color, and methods, such as drive and brake. ๏‚— A Class is like an object constructor, or a "blueprint" for creating objects. Create a Class ๏‚— To create a class, use the keyword class:
  • 32. Create an Object ๏‚— In Java, an object is created from a class. We have already created the class named Main, so now we can use this to create objects. ๏‚— To create an object of Main, specify the class name, followed by the object name, and use the keyword new: ๏‚— Code: ๏‚— O/P:
  • 33. We can create multiple objects of one class: Code: O/P:
  • 34. ๏‚— Using Multiple Classes ๏‚— You can also create an object of a class and access it in another class. This is often used for better organization of classes (one class has all the attributes and methods, while the other class holds the main() method (code to be executed)). ๏‚— Remember that the name of the java file should match the class name. In this example, ๏‚— we have created two files in the same directory/folder: 1. Main.java 2. Second.java ๏‚— When both files have been compiled: ๏‚— Run the Second.java file: O/P: