SlideShare a Scribd company logo
Chapter two Java
First Java Program
public class MyFirstJavaProgram{
/* This is my first java program.
* This will print 'Hello World' as the output
*/
public static void main(String[]args){
System.out.println("Hello World");// prints Hello World
}
}
Understanding first java program
Let's see what is the meaning of class, public, static, void, main, String[],
System.out.println().
• class keyword is used to declare a class in java.
• public keyword is an access modifier which represents visibility, it means it
is visible to all.
• static is a keyword, if we declare any method as static, it is known
as static method. The core advantage of static method is that there
is no need to create object to invoke the static method. The main
method is executed by the JVM, so it doesn't require to create
object to invoke the main method, so it saves memory.
Continue..
• void is the return type of the method, it means it doesn't return any
value.
• main represents startup of the program.
String[] args is used for command line argument. We will learn it later.
System.out.println() is used print statement. We will learn
about the internal working of System.out.println statement later.
Java API
An application programming interface (API), in the context of Java, is a
collection of prewritten packages, classes, and interfaces with their
respective methods, fields and constructors. Similar to a user interface,
which facilitates interaction between humans and computers, an API
serves as a software program interface facilitating interaction.
In Java, most basic programming tasks are performed by the API’s
classes and packages, which are helpful in minimizing the number of
lines written within pieces of code.
Continue..
Java Development Kit (JDK) is comprised of three basic components, as follows:
• Java compiler
• Java Virtual Machine (JVM)
• Java Application Programming Interface (API)
• The Java API, included with the JDK, describes the function of each of its
components. In Java programming, many of these components are pre-created
and commonly used. Thus, the programmer is able to apply prewritten code via
the Java API. After referring to the available API classes and packages, the
programmer easily invokes the necessary code classes and packages for
implementation.
Java Applet
• A Java Applet is a small Internet-based program.
• The applet is usually embedded in an HTML page on a Web site.
• It can be executed from within a browser.
Basic Syntax:
About Java programs, it is very important to keep in mind the following points.
• Case Sensitivity - Java is case sensitive, which means identifier Hello and hello
would have different
meaning in Java.
• Class Names - For all class names, the first letter should be in Upper Case.
If several words are used to form a name of the class, each inner word's first letter
should be in Upper Case.
Example class MyFirstJavaClass
• Method Names - All method names should start with a Lower Case letter.
Continue..
If several words are used to form the name of the method, then each inner
word's first letter should be in Upper Case. Example public void
myMethodName()
• Program File Name - Name of the program file should exactly match the
class name. When saving the file, you should save it using the class name
(Remember Java is case sensitive) and append '.java' to the end of the name
(if the file name and the class name do not match your program will not
compile).
• public static void main(String args[]) - Java program processing starts from
the main() method, which is a mandatory part of every Java program.
Java Identifiers:
All Java components require names. Names used for classes, variables and methods are
called identifiers, in Java, there are several points to remember about identifiers. They are
as follows:
• All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an
underscore (_).
• After the first character, identifiers can have any combination of characters.
• A keyword cannot be used as an identifier.
• Most importantly identifiers are case sensitive.
• Examples of legal identifiers : age, $salary, _value, __1_value.
• Examples of illegal identifiers: 123abc, -salary .
Variables
Variables are nothing but reserved memory locations to stores
values.
This means that when you create a variable you reserve some space in
memory.
Based on the data type of a variable, the operating system
allocates memory and decides what can be stored in the reserved
memory.
Therefore, by assigning different data types to variables, you can store
integers, decimals, or characters in these variables.
Data types
There are two data types available in Java:
• Primitive Data Types
• Reference/Object Data Types
Primitive Data Types:
There are eight primitive data types supported by Java. Primitive data
types are predefined by the language and named by a keyword. Let us
now look into detail about the eight primitive data types.
1.byte
• Is 8 bit .
• Minimum value is -128 (-2^7)
• Maximum value is 127 (inclusive)(2^7 -1)
• Default value is 0
• Example: byte a = 100 , byte b = -50
2.short:
• Short data type is a 16-bit.
• Minimum value is -32,768 (-2^15)
• Maximum value is 32,767 (inclusive) (2^15 -1)
• Default value is 0.
• Example: short s = 10000, short r = -20000
3.int
• Int data type is a 32-bit.
• Minimum value is - 2,147,483,648.(-2^31)
• Maximum value is 2,147,483,647(inclusive).(
• The default value is 0.
• Example: int a = 100000, int b = -200000
Long
• Long data type is a 64-bit.
• Minimum value is -9,223,372,036,854,775,808.(-2^63)
• Maximum value is 9,223,372,036,854,775,807 (inclusive).
• (2^63 -1).
• Default value is 0L.
• Example: long a = 100000L, int b = -200000L
Float
• Float data type is a single-precision 32-bit.
• Default value is 0.0f.
• Example: float f1 = 234.5f
double
• double data type is a double-precision 64-bit.
• Default value is 0.0d.
• Example: double d1 = 123.4
character
• char data type is a single 16-bit Unicode character.
• Char data type is used to store any character.
• Example: char letterA ='A'
Boolean
• boolean data type represents one bit of information.
• There are only two possible values: true and false.
• This data type is used for simple flags that track true/false
conditions.
• Default value is false.
• Example: boolean one = true
Referenced Data types
Reference variables are created using defined constructors of the
classes. They are used to access objects. These variables are declared
to be of a specific type that cannot be changed. For example,Employee,
Puppy etc.
Class objects, and various type of array variables come under reference
data type.
Default value of any reference variable is null.
Example: Animal animal = new Animal("giraffe");
Thank You
Ad

More Related Content

What's hot (17)

Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
indiangarg
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
Pushpendra Tyagi
 
Oop java
Oop javaOop java
Oop java
Minal Maniar
 
Core java
Core javaCore java
Core java
kasaragaddaslide
 
Java basics variables
 Java basics   variables Java basics   variables
Java basics variables
JoeReddieMedia
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Singsys Pte Ltd
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
Ahmad Idrees
 
Java basic concept
Java basic conceptJava basic concept
Java basic concept
University of Potsdam
 
Unit 1
Unit 1Unit 1
Unit 1
LOVELY PROFESSIONAL UNIVERSITY
 
Introduction to java and oop
Introduction to java and oopIntroduction to java and oop
Introduction to java and oop
baabtra.com - No. 1 supplier of quality freshers
 
Core java
Core javaCore java
Core java
Shivaraj R
 
Learning core java
Learning core javaLearning core java
Learning core java
Abhay Bharti
 
Java Basics
Java BasicsJava Basics
Java Basics
Dhanunjai Bandlamudi
 
Short notes of oop with java
Short notes of oop with javaShort notes of oop with java
Short notes of oop with java
Mohamed Fathy
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 

Similar to Chapter 2 java (20)

Full CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java languageFull CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java language
ssuser2963071
 
Java
JavaJava
Java
Zeeshan Khan
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
AssignmentjsnsnshshusjdnsnshhzudjdndndjdAssignmentjsnsnshshusjdnsnshhzudjdndndjd
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
#_ varible function
#_ varible function #_ varible function
#_ varible function
abdullah al mahamud rosi
 
Java introduction
Java introductionJava introduction
Java introduction
The icfai university jaipur
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 
Java subject for the degree BCA students
Java subject for the degree BCA studentsJava subject for the degree BCA students
Java subject for the degree BCA students
NithinKuditinamaggi
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
SadhanaParameswaran
 
Java Tokens in java program . pptx
Java Tokens in  java program   .    pptxJava Tokens in  java program   .    pptx
Java Tokens in java program . pptx
CmDept
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
sunny khan
 
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
gkgupta1115
 
OOP-Chap2.docx
OOP-Chap2.docxOOP-Chap2.docx
OOP-Chap2.docx
NaorinHalim
 
Jacarashed-1746968053-300050282-Java.ppt
Jacarashed-1746968053-300050282-Java.pptJacarashed-1746968053-300050282-Java.ppt
Jacarashed-1746968053-300050282-Java.ppt
DilipDas70
 
Object Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for studentsObject Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for students
ASHASITTeaching
 
Java UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptx
Java UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptxJava UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptx
Java UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptx
hofon47654
 
2. Introduction to Java for engineering stud
2. Introduction to Java for engineering stud2. Introduction to Java for engineering stud
2. Introduction to Java for engineering stud
vyshukodumuri
 
Unit-1_GHD.pptxguguigihihihihihihoihihhi
Unit-1_GHD.pptxguguigihihihihihihoihihhiUnit-1_GHD.pptxguguigihihihihihihoihihhi
Unit-1_GHD.pptxguguigihihihihihihoihihhi
40NehaPagariya
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
rishi ram khanal
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
Jayfee Ramos
 
TheBasics of java and comparision with c and c++.pptx
TheBasics of java and comparision with c and c++.pptxTheBasics of java and comparision with c and c++.pptx
TheBasics of java and comparision with c and c++.pptx
balasuriya695
 
Full CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java languageFull CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java language
ssuser2963071
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
AssignmentjsnsnshshusjdnsnshhzudjdndndjdAssignmentjsnsnshshusjdnsnshhzudjdndndjd
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 
Java subject for the degree BCA students
Java subject for the degree BCA studentsJava subject for the degree BCA students
Java subject for the degree BCA students
NithinKuditinamaggi
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
SadhanaParameswaran
 
Java Tokens in java program . pptx
Java Tokens in  java program   .    pptxJava Tokens in  java program   .    pptx
Java Tokens in java program . pptx
CmDept
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
sunny khan
 
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
Java Unit-1.1 chunri kyu shuru kar rh koi si je di of du th n high ch ka dh h...
gkgupta1115
 
Jacarashed-1746968053-300050282-Java.ppt
Jacarashed-1746968053-300050282-Java.pptJacarashed-1746968053-300050282-Java.ppt
Jacarashed-1746968053-300050282-Java.ppt
DilipDas70
 
Object Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for studentsObject Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for students
ASHASITTeaching
 
Java UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptx
Java UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptxJava UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptx
Java UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptx
hofon47654
 
2. Introduction to Java for engineering stud
2. Introduction to Java for engineering stud2. Introduction to Java for engineering stud
2. Introduction to Java for engineering stud
vyshukodumuri
 
Unit-1_GHD.pptxguguigihihihihihihoihihhi
Unit-1_GHD.pptxguguigihihihihihihoihihhiUnit-1_GHD.pptxguguigihihihihihihoihihhi
Unit-1_GHD.pptxguguigihihihihihihoihihhi
40NehaPagariya
 
TheBasics of java and comparision with c and c++.pptx
TheBasics of java and comparision with c and c++.pptxTheBasics of java and comparision with c and c++.pptx
TheBasics of java and comparision with c and c++.pptx
balasuriya695
 
Ad

More from Ahmad sohail Kakar (20)

Lec 1 network types
Lec 1 network typesLec 1 network types
Lec 1 network types
Ahmad sohail Kakar
 
Lec 1 introduction
Lec 1 introductionLec 1 introduction
Lec 1 introduction
Ahmad sohail Kakar
 
Active directory restoration
Active directory restorationActive directory restoration
Active directory restoration
Ahmad sohail Kakar
 
Active directory backup
Active directory backupActive directory backup
Active directory backup
Ahmad sohail Kakar
 
Seii unit7 component-level-design
Seii unit7 component-level-designSeii unit7 component-level-design
Seii unit7 component-level-design
Ahmad sohail Kakar
 
Seii unit6 software-testing-techniques
Seii unit6 software-testing-techniquesSeii unit6 software-testing-techniques
Seii unit6 software-testing-techniques
Ahmad sohail Kakar
 
Seii unit5 ui_design
Seii unit5 ui_designSeii unit5 ui_design
Seii unit5 ui_design
Ahmad sohail Kakar
 
Seii unit4 software_process
Seii unit4 software_processSeii unit4 software_process
Seii unit4 software_process
Ahmad sohail Kakar
 
Se ii unit3-architectural-design
Se ii unit3-architectural-designSe ii unit3-architectural-design
Se ii unit3-architectural-design
Ahmad sohail Kakar
 
Se ii unit2-software_design_principles
Se ii unit2-software_design_principlesSe ii unit2-software_design_principles
Se ii unit2-software_design_principles
Ahmad sohail Kakar
 
Se ii unit1-se_ii_intorduction
Se ii unit1-se_ii_intorductionSe ii unit1-se_ii_intorduction
Se ii unit1-se_ii_intorduction
Ahmad sohail Kakar
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
Ahmad sohail Kakar
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
Ahmad sohail Kakar
 
Chapter 9 java
Chapter 9 javaChapter 9 java
Chapter 9 java
Ahmad sohail Kakar
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
Ahmad sohail Kakar
 
Chapter 7 java
Chapter 7 javaChapter 7 java
Chapter 7 java
Ahmad sohail Kakar
 
Chapter 6 java
Chapter 6 javaChapter 6 java
Chapter 6 java
Ahmad sohail Kakar
 
Chapter 5 java
Chapter 5 javaChapter 5 java
Chapter 5 java
Ahmad sohail Kakar
 
Chapter 4 java
Chapter 4 javaChapter 4 java
Chapter 4 java
Ahmad sohail Kakar
 
Chapter 3 java
Chapter 3 javaChapter 3 java
Chapter 3 java
Ahmad sohail Kakar
 
Ad

Recently uploaded (20)

How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 

Chapter 2 java

  • 2. First Java Program public class MyFirstJavaProgram{ /* This is my first java program. * This will print 'Hello World' as the output */ public static void main(String[]args){ System.out.println("Hello World");// prints Hello World } }
  • 3. Understanding first java program Let's see what is the meaning of class, public, static, void, main, String[], System.out.println(). • class keyword is used to declare a class in java. • public keyword is an access modifier which represents visibility, it means it is visible to all. • static is a keyword, if we declare any method as static, it is known as static method. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesn't require to create object to invoke the main method, so it saves memory.
  • 4. Continue.. • void is the return type of the method, it means it doesn't return any value. • main represents startup of the program. String[] args is used for command line argument. We will learn it later. System.out.println() is used print statement. We will learn about the internal working of System.out.println statement later.
  • 5. Java API An application programming interface (API), in the context of Java, is a collection of prewritten packages, classes, and interfaces with their respective methods, fields and constructors. Similar to a user interface, which facilitates interaction between humans and computers, an API serves as a software program interface facilitating interaction. In Java, most basic programming tasks are performed by the API’s classes and packages, which are helpful in minimizing the number of lines written within pieces of code.
  • 6. Continue.. Java Development Kit (JDK) is comprised of three basic components, as follows: • Java compiler • Java Virtual Machine (JVM) • Java Application Programming Interface (API) • The Java API, included with the JDK, describes the function of each of its components. In Java programming, many of these components are pre-created and commonly used. Thus, the programmer is able to apply prewritten code via the Java API. After referring to the available API classes and packages, the programmer easily invokes the necessary code classes and packages for implementation.
  • 7. Java Applet • A Java Applet is a small Internet-based program. • The applet is usually embedded in an HTML page on a Web site. • It can be executed from within a browser.
  • 8. Basic Syntax: About Java programs, it is very important to keep in mind the following points. • Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java. • Class Names - For all class names, the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example class MyFirstJavaClass • Method Names - All method names should start with a Lower Case letter.
  • 9. Continue.. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example public void myMethodName() • Program File Name - Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile). • public static void main(String args[]) - Java program processing starts from the main() method, which is a mandatory part of every Java program.
  • 10. Java Identifiers: All Java components require names. Names used for classes, variables and methods are called identifiers, in Java, there are several points to remember about identifiers. They are as follows: • All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). • After the first character, identifiers can have any combination of characters. • A keyword cannot be used as an identifier. • Most importantly identifiers are case sensitive. • Examples of legal identifiers : age, $salary, _value, __1_value. • Examples of illegal identifiers: 123abc, -salary .
  • 11. Variables Variables are nothing but reserved memory locations to stores values. This means that when you create a variable you reserve some space in memory. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables.
  • 12. Data types There are two data types available in Java: • Primitive Data Types • Reference/Object Data Types
  • 13. Primitive Data Types: There are eight primitive data types supported by Java. Primitive data types are predefined by the language and named by a keyword. Let us now look into detail about the eight primitive data types.
  • 14. 1.byte • Is 8 bit . • Minimum value is -128 (-2^7) • Maximum value is 127 (inclusive)(2^7 -1) • Default value is 0 • Example: byte a = 100 , byte b = -50
  • 15. 2.short: • Short data type is a 16-bit. • Minimum value is -32,768 (-2^15) • Maximum value is 32,767 (inclusive) (2^15 -1) • Default value is 0. • Example: short s = 10000, short r = -20000
  • 16. 3.int • Int data type is a 32-bit. • Minimum value is - 2,147,483,648.(-2^31) • Maximum value is 2,147,483,647(inclusive).( • The default value is 0. • Example: int a = 100000, int b = -200000
  • 17. Long • Long data type is a 64-bit. • Minimum value is -9,223,372,036,854,775,808.(-2^63) • Maximum value is 9,223,372,036,854,775,807 (inclusive). • (2^63 -1). • Default value is 0L. • Example: long a = 100000L, int b = -200000L
  • 18. Float • Float data type is a single-precision 32-bit. • Default value is 0.0f. • Example: float f1 = 234.5f
  • 19. double • double data type is a double-precision 64-bit. • Default value is 0.0d. • Example: double d1 = 123.4
  • 20. character • char data type is a single 16-bit Unicode character. • Char data type is used to store any character. • Example: char letterA ='A'
  • 21. Boolean • boolean data type represents one bit of information. • There are only two possible values: true and false. • This data type is used for simple flags that track true/false conditions. • Default value is false. • Example: boolean one = true
  • 22. Referenced Data types Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example,Employee, Puppy etc. Class objects, and various type of array variables come under reference data type. Default value of any reference variable is null. Example: Animal animal = new Animal("giraffe");