SlideShare a Scribd company logo
1 of 15
Java Naming conventions
• class name: It should start with uppercase letter
and be a noun e.g. String, Color, Button, System,
Thread etc.
• interface name: It should start with uppercase
letter and be an adjective e.g. Runnable,
Remote, ActionListener etc.
• method name: It should start with lowercase
letter and be a verb e.g. actionPerformed(),
main(), print(), println() etc.
• variable name: It should start with lowercase
letter e.g. firstName, orderNumber etc.
• package name: It should be in lowercase letter
e.g. java, lang, sql, util etc.
• constants name: It should be in uppercase
letter. e.g. RED, YELLOW, MAX_PRIORITY etc.
• class Student
• {
• int id;
• String name;
• public static void main(String args[])
• {
• Student s1=new Student();
• System.out.println(s1.id);
• System.out.println(s1.name);
• } }
• class Student{
• int id;
• String name;
• }
• class TestStudent1
• {
• public static void main(String args[]){
• Student s1=new Student();
• System.out.println(s1.id);
• System.out.println(s1.name);
• } }
• class Student{  
•  int rollno;  
•  String name;  
•  void insertRecord(int r, String n){  
•   rollno=r;  
•   name=n;  
•  }  
• void displayInformation()
• {System.out.println(rollno+" "+name);}  
• }  
•  class TestStudent4{  
•  public static void main(String args[]){  
•   Student s1=new Student();  
•   Student s2=new Student();  
•   s1.insertRecord(111,"Karan");  
•   s2.insertRecord(222,"Aryan");  
•   s1.displayInformation();  
•   s2.displayInformation();  
•  }  
• }  
• class Employee{  
•     int id;  
•     String name;  
•     float salary;  
•     void insert(int i, String n, float s) {  
•         id=i;  
•         name=n;  
•         salary=s;  
•     }  
•     void display()
{System.out.println(id+" "+name+" "+salary);}  
• }  
• public class TestEmployee {  
• public static void main(String[] args) {  
•     Employee e1=new Employee();  
•     Employee e2=new Employee();  
•     Employee e3=new Employee();  
•     e1.insert(101,"ajeet",45000);  
•     e2.insert(102,"irfan",25000);  
•     e3.insert(103,"nakul",55000);  
•     e1.display();  
•     e2.display();  
•     e3.display();  }  }  
• class Rectangle
• {  
•  int length;  
•  int width;  
•  void insert(int l, int w){  
•   length=l;  
•   width=w;  
•  }  
•  void calculateArea()
{System.out.println(length*width);}  }  
• class TestRectangle1
• {  
•  public static void main(String args[]){  
•   Rectangle r1=new Rectangle();  
•   Rectangle r2=new Rectangle();  
•   r1.insert(11,5);  
•   r2.insert(3,15);  
•   r1.calculateArea();  
•   r2.calculateArea();  
• }  }  
Constructor in Java
• Constructor in java is  a special type of
method that is used to initialize the object.
• Java  constructor  is invoked at the time of
object creation.  It  constructs  the  values  i.e. 
provides data for  the  object that is why it is 
known as constructor.
Rules for creating java constructor
There are basically two rules defined for the 
constructor.
• Constructor name must be same as its class 
name
• Constructor must have no explicit return type
Types of java constructors
• There are two types of constructors:
• Default constructor (no-arg constructor)
• Parameterized constructor
Example of default constructor
• class Bike1
• {
• Bike1()
• {
• System.out.println("Bike is created");}
• public static void main(String args[]){
• Bike1 b=new Bike1();
• } }
• class Student3{
• int id;
• String name;
• void display()
• {System.out.println(id+" "+name);}
• public static void main(String args[]){
• Student3 s1=new Student3();
• Student3 s2=new Student3();
• s1.display();
• s2.display();
• } }

More Related Content

What's hot (6)

Refinement Types for Haskell
Refinement Types for HaskellRefinement Types for Haskell
Refinement Types for Haskell
 
A quick python_tour
A quick python_tourA quick python_tour
A quick python_tour
 
Haskell for Scala-ists
Haskell for Scala-istsHaskell for Scala-ists
Haskell for Scala-ists
 
Introduction to Dependently Types: Idris
Introduction to Dependently Types: IdrisIntroduction to Dependently Types: Idris
Introduction to Dependently Types: Idris
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3
 
Professional-grade software design
Professional-grade software designProfessional-grade software design
Professional-grade software design
 

Similar to Java naming conventions

String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
Shahjahan Samoon
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
Shahjahan Samoon
 
Reading and writting
Reading and writtingReading and writting
Reading and writting
andreeamolnar
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
adityaraj7711
 

Similar to Java naming conventions (20)

Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
 
Java introduction
Java introductionJava introduction
Java introduction
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
 
Session 08 - OOP with Java - continued
Session 08 - OOP with Java - continuedSession 08 - OOP with Java - continued
Session 08 - OOP with Java - continued
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
 
Generics
GenericsGenerics
Generics
 
Reading and writting
Reading and writtingReading and writting
Reading and writting
 
Explain Classes and methods in java (ch04).ppt
Explain Classes and methods in java (ch04).pptExplain Classes and methods in java (ch04).ppt
Explain Classes and methods in java (ch04).ppt
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
 
Java
Java Java
Java
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
OOP with Java - continued
OOP with Java - continuedOOP with Java - continued
OOP with Java - continued
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Method overloading
Method overloadingMethod overloading
Method overloading
 

More from Lovely Professional University

web_server_browser.ppt
web_server_browser.pptweb_server_browser.ppt
web_server_browser.ppt
Lovely Professional University
 
Web Server.pptx
Web Server.pptxWeb Server.pptx
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
Lovely Professional University
 
Programming Language.ppt
Programming Language.pptProgramming Language.ppt
Programming Language.ppt
Lovely Professional University
 
Information System.pptx
Information System.pptxInformation System.pptx
Information System.pptx
Lovely Professional University
 
Applications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptxApplications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptx
Lovely Professional University
 
Application of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptxApplication of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptx
Lovely Professional University
 
Requiring your own files.pptx
Requiring your own files.pptxRequiring your own files.pptx
Requiring your own files.pptx
Lovely Professional University
 

More from Lovely Professional University (20)

The HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup languageThe HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup language
 
Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
Yargs Module
Yargs ModuleYargs Module
Yargs Module
 
NODEMON Module
NODEMON ModuleNODEMON Module
NODEMON Module
 
Getting Input from User
Getting Input from UserGetting Input from User
Getting Input from User
 
fs Module.pptx
fs Module.pptxfs Module.pptx
fs Module.pptx
 
Transaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptxTransaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptx
 
web_server_browser.ppt
web_server_browser.pptweb_server_browser.ppt
web_server_browser.ppt
 
Web Server.pptx
Web Server.pptxWeb Server.pptx
Web Server.pptx
 
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
 
Programming Language.ppt
Programming Language.pptProgramming Language.ppt
Programming Language.ppt
 
Information System.pptx
Information System.pptxInformation System.pptx
Information System.pptx
 
Applications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptxApplications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptx
 
Application of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptxApplication of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptx
 
Deploying your app.pptx
Deploying your app.pptxDeploying your app.pptx
Deploying your app.pptx
 
Setting up github and ssh keys.ppt
Setting up github and ssh keys.pptSetting up github and ssh keys.ppt
Setting up github and ssh keys.ppt
 
Adding a New Feature and Deploying.ppt
Adding a New Feature and Deploying.pptAdding a New Feature and Deploying.ppt
Adding a New Feature and Deploying.ppt
 
Requiring your own files.pptx
Requiring your own files.pptxRequiring your own files.pptx
Requiring your own files.pptx
 
Unit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptxUnit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptx
 
Yargs Module.pptx
Yargs Module.pptxYargs Module.pptx
Yargs Module.pptx
 

Recently uploaded

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Recently uploaded (20)

Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 

Java naming conventions

  • 1. Java Naming conventions • class name: It should start with uppercase letter and be a noun e.g. String, Color, Button, System, Thread etc. • interface name: It should start with uppercase letter and be an adjective e.g. Runnable, Remote, ActionListener etc. • method name: It should start with lowercase letter and be a verb e.g. actionPerformed(), main(), print(), println() etc.
  • 2. • variable name: It should start with lowercase letter e.g. firstName, orderNumber etc. • package name: It should be in lowercase letter e.g. java, lang, sql, util etc. • constants name: It should be in uppercase letter. e.g. RED, YELLOW, MAX_PRIORITY etc.
  • 3. • class Student • { • int id; • String name; • public static void main(String args[]) • { • Student s1=new Student(); • System.out.println(s1.id); • System.out.println(s1.name); • } }
  • 4. • class Student{ • int id; • String name; • } • class TestStudent1 • { • public static void main(String args[]){ • Student s1=new Student(); • System.out.println(s1.id); • System.out.println(s1.name); • } }
  • 5. • class Student{   •  int rollno;   •  String name;   •  void insertRecord(int r, String n){   •   rollno=r;   •   name=n;   •  }   • void displayInformation() • {System.out.println(rollno+" "+name);}   • }  
  • 6. •  class TestStudent4{   •  public static void main(String args[]){   •   Student s1=new Student();   •   Student s2=new Student();   •   s1.insertRecord(111,"Karan");   •   s2.insertRecord(222,"Aryan");   •   s1.displayInformation();   •   s2.displayInformation();   •  }   • }  
  • 7. • class Employee{   •     int id;   •     String name;   •     float salary;   •     void insert(int i, String n, float s) {   •         id=i;   •         name=n;   •         salary=s;   •     }   •     void display() {System.out.println(id+" "+name+" "+salary);}   • }  
  • 8. • public class TestEmployee {   • public static void main(String[] args) {   •     Employee e1=new Employee();   •     Employee e2=new Employee();   •     Employee e3=new Employee();   •     e1.insert(101,"ajeet",45000);   •     e2.insert(102,"irfan",25000);   •     e3.insert(103,"nakul",55000);   •     e1.display();   •     e2.display();   •     e3.display();  }  }  
  • 9. • class Rectangle • {   •  int length;   •  int width;   •  void insert(int l, int w){   •   length=l;   •   width=w;   •  }   •  void calculateArea() {System.out.println(length*width);}  }  
  • 10. • class TestRectangle1 • {   •  public static void main(String args[]){   •   Rectangle r1=new Rectangle();   •   Rectangle r2=new Rectangle();   •   r1.insert(11,5);   •   r2.insert(3,15);   •   r1.calculateArea();   •   r2.calculateArea();   • }  }  
  • 11. Constructor in Java • Constructor in java is  a special type of method that is used to initialize the object. • Java  constructor  is invoked at the time of object creation.  It  constructs  the  values  i.e.  provides data for  the  object that is why it is  known as constructor.
  • 13. Types of java constructors • There are two types of constructors: • Default constructor (no-arg constructor) • Parameterized constructor
  • 14. Example of default constructor • class Bike1 • { • Bike1() • { • System.out.println("Bike is created");} • public static void main(String args[]){ • Bike1 b=new Bike1(); • } }
  • 15. • class Student3{ • int id; • String name; • void display() • {System.out.println(id+" "+name);} • public static void main(String args[]){ • Student3 s1=new Student3(); • Student3 s2=new Student3(); • s1.display(); • s2.display(); • } }