SlideShare a Scribd company logo
2
Most read
11
Most read
14
Most read
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

PPSX
Modules and packages in python
PPT
Java operators
PPTX
How java differs from c and c++
PPTX
Data types in java
PPT
String Handling
PPTX
collection framework in java
PPTX
Data Types, Variables, and Operators
PPTX
Interface in java
Modules and packages in python
Java operators
How java differs from c and c++
Data types in java
String Handling
collection framework in java
Data Types, Variables, and Operators
Interface in java

What's hot (20)

PPTX
Object oriented programming in python
PPTX
Main method in java
PPT
String classes and its methods.20
PPTX
Strings in Java
PPTX
Constructor and Types of Constructors
PPTX
[OOP - Lec 07] Access Specifiers
PDF
Constructors and Destructors
PPTX
Interface in java ,multiple inheritance in java, interface implementation
PDF
Methods in Java
PPTX
String, string builder, string buffer
PPTX
Methods in java
PDF
Character Array and String
PPTX
Java Method, Static Block
PDF
Java Generics - by Example
PPTX
Static keyword ppt
PPSX
Collections - Lists, Sets
PPTX
Tokens in C++
PPTX
Inheritance in java
PPTX
Super keyword in java
PPTX
Arrays in Java
Object oriented programming in python
Main method in java
String classes and its methods.20
Strings in Java
Constructor and Types of Constructors
[OOP - Lec 07] Access Specifiers
Constructors and Destructors
Interface in java ,multiple inheritance in java, interface implementation
Methods in Java
String, string builder, string buffer
Methods in java
Character Array and String
Java Method, Static Block
Java Generics - by Example
Static keyword ppt
Collections - Lists, Sets
Tokens in C++
Inheritance in java
Super keyword in java
Arrays in Java
Ad

Viewers also liked (6)

PPTX
Introduction to java
PPTX
Stacks in Data Structure
PPT
Java static keyword
PPTX
PPTX
Method overloading
PPTX
Introduction to java
Stacks in Data Structure
Java static keyword
Method overloading
Ad

Similar to Java naming conventions (20)

PPTX
Java-U1-C_1.2.pptx its all about the java
PDF
Preexisting code, please useMain.javapublic class Main { p.pdf
PPT
Core Java
PPT
Core java concepts
PPTX
Unit3 part1-class
PPTX
java: basics, user input, data type, constructor
PDF
Can someone help me with this code When I run it, it stops after th.pdf
PDF
03_Objects and Classes in java.pdf
PPT
Defining classes-and-objects-1.0
PPTX
Ch des encryption chapter 6 king Khalid 06.pptx
DOCX
OOP Lab Report.docx
PPT
PPTX
Java Classes fact general wireless-19*5.pptx
PPS
Introduction to class in java
PPTX
Simple class and object examples in java
PPT
Sonu wiziq
PDF
Android course session 3 ( OOP ) part 1
PDF
HELP IN JAVACreate a main method and use these input files to tes.pdf
PDF
Java basic concept
PDF
Lecture2.pdf
Java-U1-C_1.2.pptx its all about the java
Preexisting code, please useMain.javapublic class Main { p.pdf
Core Java
Core java concepts
Unit3 part1-class
java: basics, user input, data type, constructor
Can someone help me with this code When I run it, it stops after th.pdf
03_Objects and Classes in java.pdf
Defining classes-and-objects-1.0
Ch des encryption chapter 6 king Khalid 06.pptx
OOP Lab Report.docx
Java Classes fact general wireless-19*5.pptx
Introduction to class in java
Simple class and object examples in java
Sonu wiziq
Android course session 3 ( OOP ) part 1
HELP IN JAVACreate a main method and use these input files to tes.pdf
Java basic concept
Lecture2.pdf

More from Lovely Professional University (20)

PPTX
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
PPTX
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
PPTX
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
PPTX
Programme Management & Project Evaluation
PPTX
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
PPTX
Introduction to Software Project Management:
PDF
The HyperText Markup Language or HTML is the standard markup language
PPTX
PPTX
PPTX
Getting Input from User
PPTX
PPTX
Transaction Processing in DBMS.pptx
PPT
web_server_browser.ppt
PPTX
PPTX
Number System.pptx
PPT
Programming Language.ppt
PPTX
Information System.pptx
PPTX
Applications of Computer Science in Pharmacy-1.pptx
PPTX
Application of Computers in Pharmacy.pptx
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
Programme Management & Project Evaluation
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
Introduction to Software Project Management:
The HyperText Markup Language or HTML is the standard markup language
Getting Input from User
Transaction Processing in DBMS.pptx
web_server_browser.ppt
Number System.pptx
Programming Language.ppt
Information System.pptx
Applications of Computer Science in Pharmacy-1.pptx
Application of Computers in Pharmacy.pptx

Recently uploaded (20)

PDF
PPT on Performance Review to get promotions
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
web development for engineering and engineering
PDF
Digital Logic Computer Design lecture notes
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
composite construction of structures.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
Project quality management in manufacturing
PPT
Mechanical Engineering MATERIALS Selection
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPT on Performance Review to get promotions
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
web development for engineering and engineering
Digital Logic Computer Design lecture notes
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
bas. eng. economics group 4 presentation 1.pptx
CH1 Production IntroductoryConcepts.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
composite construction of structures.pdf
Internet of Things (IOT) - A guide to understanding
CYBER-CRIMES AND SECURITY A guide to understanding
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Project quality management in manufacturing
Mechanical Engineering MATERIALS Selection
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS

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(); • } }