SlideShare a Scribd company logo
Introduction to Java
Why Java?
•It’s the current “hot” language
•It’s almost entirely object-oriented
•It has a vast library of predefined objects and
operations
•It’s more platform independent
• this makes it great for Web programming
•It’s more secure
•It isn’t C++
Applets, Servlets and
Applications
•An applet is designed to be embedded in a Web
page, and run by a browser
•Applets run in a sandbox with numerous
restrictions; for example, they can’t read files
and then use the network
•A servlet is designed to be run by a web server
•An application is a conventional program
Java Virtual Machine
•The .class files generated by the compiler are not
executable binaries
• so Java combines compilation and interpretation
•Instead, they contain “byte-codes” to be executed by
the Java Virtual Machine
• other languages have done this, e.g. UCSD Pascal
•This approach provides platform independence, and
greater security
HelloWorld
• Note that String is built in
• println is a member function for the System.out class
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Comments are almost like C++
• /* This kind of comment can span
multiple lines */
• // This kind is to the end of the
line
• /**
* This kind of comment is a
special
* ‘javadoc’ style comment
*/
Primitive data types are like C
Main data types are int, double,
boolean, char
Also have byte, short, long, float
boolean has values true and false
Declarations look like C, for example,
double x, y;
int count = 0;
Expressions are like C
•Assignment statements mostly look like those in C; you
can use =, +=, *= etc.
•Arithmetic uses the familiar + - * / %
•Java also has ++ and --
•Java has boolean operators && || !
•Java has comparisons < <= == != >= >
•Java does not have pointers or pointer arithmetic
Control statements are like C
if (x < y) smaller = x;
if (x < y){ smaller=x;sum += x;}
else { smaller = y; sum += y; }
while (x < y) { y = y - x; }
do { y = y - x; } while (x < y)
for (int i = 0; i < max; i++)
sum += i;
what is a class?
•A class consists of
• a collection of fields, or variables, very much like the
named fields of a struct
• all the operations (called methods) that can be
performed on those fields
• can be instantiated
•A class describes objects and operations defined
on those objects
Name conventions
• Java is case-sensitive; maxval, maxVal, and MaxVal are three different
names
• Class names begin with a capital letter
• All other names begin with a lowercase letter
• Subsequent words are capitalized: theBigOne
• Underscores are not used in names
• These are very strong conventions!
An example of a class
class Person {
String name;
int age;
void birthday ( ) {
age++;
System.out.println (name + ' is
now ' + age);
}
}
Creating and using an object
•Person john;
john = new Person ( );
john.name = "John Smith";
john.age = 37;
•Person mary = new Person ( );
mary.name = "Mary Brown";
mary.age = 33;
mary.birthday ( );
An array is an object
• Person mary = new Person ( );
• int myArray[ ] = new int[5];
• or:
• int myArray[ ] = {1, 4, 9, 16, 25};
• String languages [ ] = {"Prolog", "Java"};

More Related Content

What's hot (15)

PPTX
Learn VB.NET at ASIT
ASIT
 
PPT
Uklug2012 yellow and blue stream
Frank van der Linden
 
PPT
Cetpa dotnet taining
sharmamohan13989
 
PDF
Stairway to scala flyer
dickwall
 
PPTX
Building reactive systems with Akka
Kristof Jozsa
 
PPTX
I18nize Scala programs à la gettext
Ngoc Dao
 
PDF
Ceylon introduction by Stéphane Épardaud
UnFroMage
 
PDF
Ceylon SDK by Stéphane Épardaud
UnFroMage
 
PPTX
Use notes objects in memory and other useful java tips for xpages development
Frank van der Linden
 
PDF
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
PPTX
C++ in object oriented programming
Saket Khopkar
 
PPTX
Java Tutorial Lab 3
Berk Soysal
 
PPTX
Java Tutorial Lab 6
Berk Soysal
 
Learn VB.NET at ASIT
ASIT
 
Uklug2012 yellow and blue stream
Frank van der Linden
 
Cetpa dotnet taining
sharmamohan13989
 
Stairway to scala flyer
dickwall
 
Building reactive systems with Akka
Kristof Jozsa
 
I18nize Scala programs à la gettext
Ngoc Dao
 
Ceylon introduction by Stéphane Épardaud
UnFroMage
 
Ceylon SDK by Stéphane Épardaud
UnFroMage
 
Use notes objects in memory and other useful java tips for xpages development
Frank van der Linden
 
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
C++ in object oriented programming
Saket Khopkar
 
Java Tutorial Lab 3
Berk Soysal
 
Java Tutorial Lab 6
Berk Soysal
 

Similar to Introduction to java programming (20)

PPTX
Java programmingjsjdjdjdjdjdjdjdjdiidiei
rajputtejaswa12
 
PPT
Java01
mosewoodward24
 
PPT
Java01
Prakash Mani
 
PPT
Java01
mosewoodward24
 
PPT
Java01
Sanjeev Tripathi
 
PPT
java01.pptbvuyvyuvvvvvvvvvvvvvvvvvvvvyft
nagendrareddy104104
 
PPT
Java Simple Introduction in single course
binzbinz3
 
PPT
java-corporate-training-institute-in-mumbai
vibrantuser
 
PPT
Java - A parent language and powerdul for mobile apps.
dhimananshu130803
 
PPT
Java01
Dhaval Patel
 
PPT
java ppt for basic intro about java and its
kssandhu875
 
PPT
java_ notes_for__________basic_level.ppt
amisharawat149
 
PPT
Present the syntax of Java Introduce the Java
ssuserfd620b
 
PPT
java01.ppt
JyoGen
 
PPTX
mukul Dubey.pptx
CodeHome
 
PPT
java01.ppt
FakeBuddy2
 
PPT
java01.ppt
ssuser73c6451
 
PPT
java01.ppt
MENACE4
 
PPT
java01.ppt
MansiDongare2
 
PPT
java01.ppt
priyanshugautam46
 
Java programmingjsjdjdjdjdjdjdjdjdiidiei
rajputtejaswa12
 
Java01
Prakash Mani
 
java01.pptbvuyvyuvvvvvvvvvvvvvvvvvvvvyft
nagendrareddy104104
 
Java Simple Introduction in single course
binzbinz3
 
java-corporate-training-institute-in-mumbai
vibrantuser
 
Java - A parent language and powerdul for mobile apps.
dhimananshu130803
 
Java01
Dhaval Patel
 
java ppt for basic intro about java and its
kssandhu875
 
java_ notes_for__________basic_level.ppt
amisharawat149
 
Present the syntax of Java Introduce the Java
ssuserfd620b
 
java01.ppt
JyoGen
 
mukul Dubey.pptx
CodeHome
 
java01.ppt
FakeBuddy2
 
java01.ppt
ssuser73c6451
 
java01.ppt
MENACE4
 
java01.ppt
MansiDongare2
 
java01.ppt
priyanshugautam46
 
Ad

More from ASIT Education (20)

PPTX
COMMON PROBLEMS FACING WITH TABLETS
ASIT Education
 
PPTX
Simple hardware problems facing in pc's
ASIT Education
 
DOCX
Amc square IT services
ASIT Education
 
PPT
learn JAVA at ASIT with a placement assistance.
ASIT Education
 
PPT
Learn my sql at amc square learning
ASIT Education
 
PPT
Learn joomla at amc square learning
ASIT Education
 
PPT
learn ANDROID at AMC Square Learning
ASIT Education
 
PPT
Learn spring at amc square learning
ASIT Education
 
PPT
Learn cpp at amc square learning
ASIT Education
 
PPT
Learn perl in amc square learning
ASIT Education
 
PPT
Learn c sharp at amc square learning
ASIT Education
 
PPT
Learn Ruby Programming in Amc Square Learning
ASIT Education
 
PPT
learn sharepoint at AMC Square learning
ASIT Education
 
PPT
Introduction to software testing
ASIT Education
 
PPTX
C programmimng basic.ppt
ASIT Education
 
PPT
Ruby programming introduction
ASIT Education
 
PPT
Introduction to vm ware
ASIT Education
 
PPT
Introduction to software testing
ASIT Education
 
PPT
Introduction to phython programming
ASIT Education
 
PPTX
Introduction to internet
ASIT Education
 
COMMON PROBLEMS FACING WITH TABLETS
ASIT Education
 
Simple hardware problems facing in pc's
ASIT Education
 
Amc square IT services
ASIT Education
 
learn JAVA at ASIT with a placement assistance.
ASIT Education
 
Learn my sql at amc square learning
ASIT Education
 
Learn joomla at amc square learning
ASIT Education
 
learn ANDROID at AMC Square Learning
ASIT Education
 
Learn spring at amc square learning
ASIT Education
 
Learn cpp at amc square learning
ASIT Education
 
Learn perl in amc square learning
ASIT Education
 
Learn c sharp at amc square learning
ASIT Education
 
Learn Ruby Programming in Amc Square Learning
ASIT Education
 
learn sharepoint at AMC Square learning
ASIT Education
 
Introduction to software testing
ASIT Education
 
C programmimng basic.ppt
ASIT Education
 
Ruby programming introduction
ASIT Education
 
Introduction to vm ware
ASIT Education
 
Introduction to software testing
ASIT Education
 
Introduction to phython programming
ASIT Education
 
Introduction to internet
ASIT Education
 
Ad

Recently uploaded (20)

PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
community health nursing question paper 2.pdf
Prince kumar
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 

Introduction to java programming

  • 2. Why Java? •It’s the current “hot” language •It’s almost entirely object-oriented •It has a vast library of predefined objects and operations •It’s more platform independent • this makes it great for Web programming •It’s more secure •It isn’t C++
  • 3. Applets, Servlets and Applications •An applet is designed to be embedded in a Web page, and run by a browser •Applets run in a sandbox with numerous restrictions; for example, they can’t read files and then use the network •A servlet is designed to be run by a web server •An application is a conventional program
  • 4. Java Virtual Machine •The .class files generated by the compiler are not executable binaries • so Java combines compilation and interpretation •Instead, they contain “byte-codes” to be executed by the Java Virtual Machine • other languages have done this, e.g. UCSD Pascal •This approach provides platform independence, and greater security
  • 5. HelloWorld • Note that String is built in • println is a member function for the System.out class public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
  • 6. Comments are almost like C++ • /* This kind of comment can span multiple lines */ • // This kind is to the end of the line • /** * This kind of comment is a special * ‘javadoc’ style comment */
  • 7. Primitive data types are like C Main data types are int, double, boolean, char Also have byte, short, long, float boolean has values true and false Declarations look like C, for example, double x, y; int count = 0;
  • 8. Expressions are like C •Assignment statements mostly look like those in C; you can use =, +=, *= etc. •Arithmetic uses the familiar + - * / % •Java also has ++ and -- •Java has boolean operators && || ! •Java has comparisons < <= == != >= > •Java does not have pointers or pointer arithmetic
  • 9. Control statements are like C if (x < y) smaller = x; if (x < y){ smaller=x;sum += x;} else { smaller = y; sum += y; } while (x < y) { y = y - x; } do { y = y - x; } while (x < y) for (int i = 0; i < max; i++) sum += i;
  • 10. what is a class? •A class consists of • a collection of fields, or variables, very much like the named fields of a struct • all the operations (called methods) that can be performed on those fields • can be instantiated •A class describes objects and operations defined on those objects
  • 11. Name conventions • Java is case-sensitive; maxval, maxVal, and MaxVal are three different names • Class names begin with a capital letter • All other names begin with a lowercase letter • Subsequent words are capitalized: theBigOne • Underscores are not used in names • These are very strong conventions!
  • 12. An example of a class class Person { String name; int age; void birthday ( ) { age++; System.out.println (name + ' is now ' + age); } }
  • 13. Creating and using an object •Person john; john = new Person ( ); john.name = "John Smith"; john.age = 37; •Person mary = new Person ( ); mary.name = "Mary Brown"; mary.age = 33; mary.birthday ( );
  • 14. An array is an object • Person mary = new Person ( ); • int myArray[ ] = new int[5]; • or: • int myArray[ ] = {1, 4, 9, 16, 25}; • String languages [ ] = {"Prolog", "Java"};