0% found this document useful (0 votes)
2 views

java_4

The document outlines Java coding conventions, including naming conventions for classes, methods, variables, and constants. It also addresses common myths about Java programming, such as the necessity for class names and file names to match and the ability to have multiple classes in a single program. Examples are provided to illustrate these points, emphasizing best practices and clarifying misconceptions.

Uploaded by

Vaishnavi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java_4

The document outlines Java coding conventions, including naming conventions for classes, methods, variables, and constants. It also addresses common myths about Java programming, such as the necessity for class names and file names to match and the ability to have multiple classes in a single program. Examples are provided to illustrate these points, emphasizing best practices and clarifying misconceptions.

Uploaded by

Vaishnavi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

JEAD

Java Coding conventions

• Class names / Interface - Camel case starting with a UPPER CASE

• Method names / variable names – Camel case starting with “lower” case

• Constants – All UPER CASE letters with under-score as separator

- Santosh Katti, Department of Computer Applications, PESU


JEAD
Java Program structure

import java.lang.*; OR

import java.lang.System;

import java.lang.String;

class Test {

public static void main(String[] args) {

System.out.println(“Katti’s Java World”);

} }
- Santosh Katti, Department of Computer Applications, PESU
JEAD
Myths

• Class name and file name should be same

• One program cannot have multiple classes – compiler error

• Program with multiple classes causes error while saving

• Program can have multiple public classes

Demo S-38

- Santosh Katti, Department of Computer Applications, PESU


JEAD
Myths

// Myth-1 : Class name and file name should be same


// File name: ClassName.java
// But it is best practice to have filename and class name same for access
class FileName {
public static void main(String[] args){
int a='k’;
System.out.println("Value of variable 'a' is: "+a);
}
}
- Santosh Katti, Department of Computer Applications, PESU
JEAD
Myths

// Multiple classes are allowed in a single Java program


// Every class is compiled to create class files.
// This example creates 3 class files: A.class, B.class and C.class
// But only C.class is executable, No error if the file is saved in any other name
class A { }
class B{}
class C{ public static void main(String[] args) {
System.out.println("Multiple class in same program is allowed");
} }
- Santosh Katti, Department of Computer Applications, PESU

You might also like