SlideShare a Scribd company logo
1 of 5
Download to read offline
INTRODUCTION TO JAVA PROGRAMMING LANGUAGE
UNIT-2
[Naming Conventions in Java. Data types in Java, Literals]
Naming Conventions in Java
Java naming convention is a rule to follow as you decide what to name your identifiers such as
class, package, variable, constant, method etc. But, it is not forced to follow. So, it is known as
convention not rule.
Below are some naming conventions of for java programming language, which must be followed
while developing software in java for good maintenance and readability of code. Java uses
CamelCase as a practice for writing names of methods, variables, classes, packages and constants.
If name is combined with two words, second word will start with uppercase letter always e.g.
actionPerformed(), firstName, etc.
1. Classes and Interfaces:
● Class names should be nouns, in mixed case with the first letter of each internal word
capitalized. Interfaces name should also be capitalized just like class names.
● Use whole words and must avoid acronyms and abbreviations.
Examples:
class CseStudent
Interface FootBall
2. Methods :
● Methods should be verbs, in mixed case with the first letter lowercase and with the first
letter of each internal word capitalized.
Examples:
void speedUp(int increment)
3. Variables :
● Variable names should be short yet meaningful.
● Should not start with underscore(‘_’) or dollar sign ‘$’ characters.
● Should be mnemonic i.e, designed to indicate the intent of its use.
● One-character variable names should be avoided except for temporary variables, such as
i, j, k, m, and n for integers; c, d, and e for characters.
Examples:
int rollNo;
4. Constant variables:
● Should be all uppercase with words separated by underscores (“_”).
● There are various constants used in predefined classes like Float, Long, String etc.
Examples:
static final int MIN_WIDTH = 4;
Provided By Shipra Swati
INTRODUCTION TO JAVA PROGRAMMING LANGUAGE
5. Packages:
● The prefix of a unique package name is always written in all-lowercase ASCII lettersand
should be one of the top-level domain names, like com, edu, gov, mil, net, org.
● Subsequent components of the package name vary according to an organization’s own
internal naming conventions.
Examples:
com.sun.eng
Data Types in java
Data type is a special type of keyword which is useful for allocating sufficient memory for that data.
In other words, Java Data Types are the classification, to identify one of various types of data such
as real number, integer, floating point or boolean. That determines the possible values for that
particular type and the operations that can be done on values of that type.
So, Java data types are in various forms to store the different types of information. These Java data
types are mainly classified into 2 types.
(a) Primitive Data Types and
(b) Non-Primitive Data Types.
Java data types can not be modified once they declared.
Provided By Shipra Swati
INTRODUCTION TO JAVA PROGRAMMING LANGUAGE
The primitive data types in Java are also called as Fundamental data types or Basic data types. In
primitive, Java data types are mainly classified into four types. They are Integer Data Types In Java,
Floating-Point Data Types In Java, Character Data Types in Java and Boolean Data Types in Java.
Following table shows the details related to primitive data types:
In Non-Primitive, Java data types are further classified into three types. User defined data type is
one of these Non-primitive Java data types. According to the requirement we can choose the
appropriate type in Java data types.
There are three types of variables in java:
• local variable
• instance variable
• static variable
1) Local Variable: A variable which is declared inside the method is called local variable.
2) Instance Variable: A variable which is declared inside the class but outside the method, is called
instance variable. It is not declared as static.
3) Static variable: A variable that is declared as static is called static variable. It cannot be local.
Provided By Shipra Swati
INTRODUCTION TO JAVA PROGRAMMING LANGUAGE
Literals
Literals in Java are a sequence of characters (digits, letters, and other characters) that represent
constant values to be stored in variables. Java language specifies five major types of literals.
1. Integer Literals: Java has several integer literals: int, long, byte, and short. We can specify
the integers either in decimal, hexadecimal or octal format. To indicate a decimal format
put the left most digit as nonzero. Similarly use the prefix ox to indicate hexadecimal and to
indicate the octal format put a zero digit followed by the digits 0 to 7.
Examples:
int decimal = 100;
int octal = 0144;
int hexa = 0x64;
An integer literal larger than an int can hold is automatically considered to be of the type
long. You also can indicate that a literal should be a long integer by adding the letter L (L or
l) to the number.
2. Floating-point Literals: Floating-point literals use a period character (.) for the decimal
point. Java has two kinds of floating-point numbers: float and double. The default type when
you write a floating-point literal is double. However, the suffix F (or f) is appended to
designate the data type of a floating-point literal as float.
Examples:
double myGPA = 2.25;
float piValue = 3.1415927F;
We can also specify a floating-point literal in scientific notation using Exponent (E or e). For
instance: the double literal 0.0314E2 is interpreted as: 0.0314 *10² (i.e 3.14).
3. Character Literals: Character literals are expressed by a single character surrounded by
single quotation marks, such as 'a', '#', and '3'. Some character literals represent characters
that are not readily printable or accessible through a keyboard. Following Table lists the
special codes that can represent these special characters as well as characters from the
Unicode character set. The letter d in the octal, hex, and Unicode escape codes represents a
number or a hexadecimal digit (a–f or A–F).
Escape Meaning
n New line
t Tab
b Backspace
r Carriage return
f Formfeed
 Backslash
' Single quotation mark
" Double quotation mark
d Octal
xd Hexadecimal
ud Unicode character
Provided By Shipra Swati
INTRODUCTION TO JAVA PROGRAMMING LANGUAGE
4. String Literals: The set of characters in represented as String literals in Java. Always use
"double quotes" for String literals. A string in Java is an object rather than being a basic data
type, and strings are not stored in arrays as they are in languages such as C. There are few
methods provided in Java to combine strings, modify strings and to know whether to strings
have the same value.
Example:
String myString = "How are you?";
5. Boolean Literals: The values true and false are also treated as literals in Java programming.
When we assign a value to a boolean variable, we can only use these two values.
Example
boolean chosen = true;
Provided By Shipra Swati

More Related Content

What's hot

Jason yousef ssis expressions - no notes
Jason yousef   ssis expressions - no notesJason yousef   ssis expressions - no notes
Jason yousef ssis expressions - no notesjasonyousef
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Deepak Singh
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1İbrahim Kürce
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ FundamentalsSubhasis Nayak
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#Prasanna Kumar SM
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler designRiazul Islam
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++NIDA HUSSAIN
 
Oop concepts classes_objects
Oop concepts classes_objectsOop concepts classes_objects
Oop concepts classes_objectsWilliam Olivier
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
 

What's hot (20)

7. name binding and scopes
7. name binding and scopes7. name binding and scopes
7. name binding and scopes
 
Jason yousef ssis expressions - no notes
Jason yousef   ssis expressions - no notesJason yousef   ssis expressions - no notes
Jason yousef ssis expressions - no notes
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++
 
Structure and Enum in c#
Structure and Enum in c#Structure and Enum in c#
Structure and Enum in c#
 
concept of oops
concept of oopsconcept of oops
concept of oops
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Variables
VariablesVariables
Variables
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ Fundamentals
 
Data types IN JAVA
Data types IN JAVAData types IN JAVA
Data types IN JAVA
 
Java Programming
Java Programming Java Programming
Java Programming
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler design
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
C plusplus
C plusplusC plusplus
C plusplus
 
Oop concepts classes_objects
Oop concepts classes_objectsOop concepts classes_objects
Oop concepts classes_objects
 
Basic of java 2
Basic of java  2Basic of java  2
Basic of java 2
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Regular expression (compiler)
Regular expression (compiler)Regular expression (compiler)
Regular expression (compiler)
 
Identifiers and keywords
Identifiers and keywordsIdentifiers and keywords
Identifiers and keywords
 

Similar to Java unit 2

Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and OperatorsMarwa Ali Eissa
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesTabassumMaktum
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm Madishetty Prathibha
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxSaqlainYaqub1
 
Overview of java Language-3.pdf
Overview of java Language-3.pdfOverview of java Language-3.pdf
Overview of java Language-3.pdfkumari36
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGEPRASANYA K
 
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 languagessuser2963071
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)IJERD Editor
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)IJERD Editor
 
CHAPTER 3 - VALUE AND DATA TYPES LECTURE 1.pdf
CHAPTER 3 - VALUE AND DATA TYPES LECTURE 1.pdfCHAPTER 3 - VALUE AND DATA TYPES LECTURE 1.pdf
CHAPTER 3 - VALUE AND DATA TYPES LECTURE 1.pdfarbazkhan950274
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java MayaTofik
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocksİbrahim Kürce
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming conceptsandeshjadhav28
 

Similar to Java unit 2 (20)

Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
java
java java
java
 
Java_Roadmap.pptx
Java_Roadmap.pptxJava_Roadmap.pptx
Java_Roadmap.pptx
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologies
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptx
 
Overview of java Language-3.pdf
Overview of java Language-3.pdfOverview of java Language-3.pdf
Overview of java Language-3.pdf
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
 
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
 
7-Java Language Basics Part1
7-Java Language Basics Part17-Java Language Basics Part1
7-Java Language Basics Part1
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
CHAPTER 3 - VALUE AND DATA TYPES LECTURE 1.pdf
CHAPTER 3 - VALUE AND DATA TYPES LECTURE 1.pdfCHAPTER 3 - VALUE AND DATA TYPES LECTURE 1.pdf
CHAPTER 3 - VALUE AND DATA TYPES LECTURE 1.pdf
 
C tokens
C tokensC tokens
C tokens
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming concept
 

More from Shipra Swati

Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process SchedulingShipra Swati
 
Operating System-Concepts of Process
Operating System-Concepts of ProcessOperating System-Concepts of Process
Operating System-Concepts of ProcessShipra Swati
 
Operating System-Introduction
Operating System-IntroductionOperating System-Introduction
Operating System-IntroductionShipra Swati
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Shipra Swati
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Shipra Swati
 
Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6Shipra Swati
 
Fundamental of Information Technology
Fundamental of Information TechnologyFundamental of Information Technology
Fundamental of Information TechnologyShipra Swati
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process SynchronizationShipra Swati
 

More from Shipra Swati (20)

Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Operating System-Concepts of Process
Operating System-Concepts of ProcessOperating System-Concepts of Process
Operating System-Concepts of Process
 
Operating System-Introduction
Operating System-IntroductionOperating System-Introduction
Operating System-Introduction
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
 
Java unit 14
Java unit 14Java unit 14
Java unit 14
 
Java unit 12
Java unit 12Java unit 12
Java unit 12
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
 
Java unit 3
Java unit 3Java unit 3
Java unit 3
 
Java unit 1
Java unit 1Java unit 1
Java unit 1
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7
 
Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6
 
Fundamental of Information Technology
Fundamental of Information TechnologyFundamental of Information Technology
Fundamental of Information Technology
 
Disk Management
Disk ManagementDisk Management
Disk Management
 
File Systems
File SystemsFile Systems
File Systems
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 

Recently uploaded

Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 

Java unit 2

  • 1. INTRODUCTION TO JAVA PROGRAMMING LANGUAGE UNIT-2 [Naming Conventions in Java. Data types in Java, Literals] Naming Conventions in Java Java naming convention is a rule to follow as you decide what to name your identifiers such as class, package, variable, constant, method etc. But, it is not forced to follow. So, it is known as convention not rule. Below are some naming conventions of for java programming language, which must be followed while developing software in java for good maintenance and readability of code. Java uses CamelCase as a practice for writing names of methods, variables, classes, packages and constants. If name is combined with two words, second word will start with uppercase letter always e.g. actionPerformed(), firstName, etc. 1. Classes and Interfaces: ● Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Interfaces name should also be capitalized just like class names. ● Use whole words and must avoid acronyms and abbreviations. Examples: class CseStudent Interface FootBall 2. Methods : ● Methods should be verbs, in mixed case with the first letter lowercase and with the first letter of each internal word capitalized. Examples: void speedUp(int increment) 3. Variables : ● Variable names should be short yet meaningful. ● Should not start with underscore(‘_’) or dollar sign ‘$’ characters. ● Should be mnemonic i.e, designed to indicate the intent of its use. ● One-character variable names should be avoided except for temporary variables, such as i, j, k, m, and n for integers; c, d, and e for characters. Examples: int rollNo; 4. Constant variables: ● Should be all uppercase with words separated by underscores (“_”). ● There are various constants used in predefined classes like Float, Long, String etc. Examples: static final int MIN_WIDTH = 4; Provided By Shipra Swati
  • 2. INTRODUCTION TO JAVA PROGRAMMING LANGUAGE 5. Packages: ● The prefix of a unique package name is always written in all-lowercase ASCII lettersand should be one of the top-level domain names, like com, edu, gov, mil, net, org. ● Subsequent components of the package name vary according to an organization’s own internal naming conventions. Examples: com.sun.eng Data Types in java Data type is a special type of keyword which is useful for allocating sufficient memory for that data. In other words, Java Data Types are the classification, to identify one of various types of data such as real number, integer, floating point or boolean. That determines the possible values for that particular type and the operations that can be done on values of that type. So, Java data types are in various forms to store the different types of information. These Java data types are mainly classified into 2 types. (a) Primitive Data Types and (b) Non-Primitive Data Types. Java data types can not be modified once they declared. Provided By Shipra Swati
  • 3. INTRODUCTION TO JAVA PROGRAMMING LANGUAGE The primitive data types in Java are also called as Fundamental data types or Basic data types. In primitive, Java data types are mainly classified into four types. They are Integer Data Types In Java, Floating-Point Data Types In Java, Character Data Types in Java and Boolean Data Types in Java. Following table shows the details related to primitive data types: In Non-Primitive, Java data types are further classified into three types. User defined data type is one of these Non-primitive Java data types. According to the requirement we can choose the appropriate type in Java data types. There are three types of variables in java: • local variable • instance variable • static variable 1) Local Variable: A variable which is declared inside the method is called local variable. 2) Instance Variable: A variable which is declared inside the class but outside the method, is called instance variable. It is not declared as static. 3) Static variable: A variable that is declared as static is called static variable. It cannot be local. Provided By Shipra Swati
  • 4. INTRODUCTION TO JAVA PROGRAMMING LANGUAGE Literals Literals in Java are a sequence of characters (digits, letters, and other characters) that represent constant values to be stored in variables. Java language specifies five major types of literals. 1. Integer Literals: Java has several integer literals: int, long, byte, and short. We can specify the integers either in decimal, hexadecimal or octal format. To indicate a decimal format put the left most digit as nonzero. Similarly use the prefix ox to indicate hexadecimal and to indicate the octal format put a zero digit followed by the digits 0 to 7. Examples: int decimal = 100; int octal = 0144; int hexa = 0x64; An integer literal larger than an int can hold is automatically considered to be of the type long. You also can indicate that a literal should be a long integer by adding the letter L (L or l) to the number. 2. Floating-point Literals: Floating-point literals use a period character (.) for the decimal point. Java has two kinds of floating-point numbers: float and double. The default type when you write a floating-point literal is double. However, the suffix F (or f) is appended to designate the data type of a floating-point literal as float. Examples: double myGPA = 2.25; float piValue = 3.1415927F; We can also specify a floating-point literal in scientific notation using Exponent (E or e). For instance: the double literal 0.0314E2 is interpreted as: 0.0314 *10² (i.e 3.14). 3. Character Literals: Character literals are expressed by a single character surrounded by single quotation marks, such as 'a', '#', and '3'. Some character literals represent characters that are not readily printable or accessible through a keyboard. Following Table lists the special codes that can represent these special characters as well as characters from the Unicode character set. The letter d in the octal, hex, and Unicode escape codes represents a number or a hexadecimal digit (a–f or A–F). Escape Meaning n New line t Tab b Backspace r Carriage return f Formfeed Backslash ' Single quotation mark " Double quotation mark d Octal xd Hexadecimal ud Unicode character Provided By Shipra Swati
  • 5. INTRODUCTION TO JAVA PROGRAMMING LANGUAGE 4. String Literals: The set of characters in represented as String literals in Java. Always use "double quotes" for String literals. A string in Java is an object rather than being a basic data type, and strings are not stored in arrays as they are in languages such as C. There are few methods provided in Java to combine strings, modify strings and to know whether to strings have the same value. Example: String myString = "How are you?"; 5. Boolean Literals: The values true and false are also treated as literals in Java programming. When we assign a value to a boolean variable, we can only use these two values. Example boolean chosen = true; Provided By Shipra Swati