0% found this document useful (0 votes)
182 views11 pages

Fundamentals of Programming in Java

This document discusses Java programming fundamentals including naming conventions, identifiers, keywords, writing a first Java program, compiling and executing Java code, and access specifiers. Key points covered are: class names use initial capital letters for each word while method names capitalize each word except the first; identifiers can include letters, numbers and underscores; keywords are reserved and cannot be used as names; and access specifiers determine visibility of classes, methods and members within and across packages.

Uploaded by

soham
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
0% found this document useful (0 votes)
182 views11 pages

Fundamentals of Programming in Java

This document discusses Java programming fundamentals including naming conventions, identifiers, keywords, writing a first Java program, compiling and executing Java code, and access specifiers. Key points covered are: class names use initial capital letters for each word while method names capitalize each word except the first; identifiers can include letters, numbers and underscores; keywords are reserved and cannot be used as names; and access specifiers determine visibility of classes, methods and members within and across packages.

Uploaded by

soham
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 11

CSE310: Programming in Java

Fundamentals of Programming in Java

By
Ravi Kant Sahu
Asst. Professor, LPU
Naming Conventions
All the letters of an identifier in Java should be in lower case
Except:

Class Names: First letter of each word in the identifier should be


capitalized.

Method Names: First letter of each word in the identifier should be


capitalized except the first word.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Identifiers
A name in a program is called an identifier.

Identifiers can be used to denote classes, methods, variables,


and labels.

An identifier may be any descriptive sequence of uppercase


and lowercase letters, numbers, or the underscore and
dollar-sign characters.
Example: number, Number, sum_$, bingo, $$_100

Note: Identifiers must not begin with a number.


Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Keywords
Keywords are reserved identifiers that are predefined in the
language.

Cannot be used as names for a variable, class, or method.

All the keywords are in lowercase.

There are 50 keywords currently defined in the Java language.

The keywords const and goto are reserved but not used.

true, false, and null are also reserved.


Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Java Keywords
abstract char else goto long return throw

assert class enum if native short throws

boolean const extends implements new static this

break continue final import package strictfp transient

byte default finally instanceof private super void

case do float int protected switch try

catch double for interface public synchronize while and


d volatile
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Writing Your First Java Program

• class MyJavaProgram
• {
• public static void main(String args[])
{
System.out.println(“Have fun in Java…”);
}
• }

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Compiling and Executing Java Program
Step-1: Save your file with .java extension.
• Example: Program1.java

NOTE: If the class is public then the file name MUST BE same as
the name of the class.

Step-2: Compile your .Java file using javac compiler from the
location where the file is saved.

javac Program1.java

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Compiling and Executing Java Program

Step-3: Execute your java class which contains the following


method: public static void main(String args[]) {}

java MyJavaProgram

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Access Specifiers
Specifier Sub class Non-Sub class Sub class Non-Sub class
(Same (Same (Different (Different
Package) Package) Package) Package)

public Yes Yes Yes Yes

protected Yes Yes Yes No

default Yes Yes No No

private No No No No

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Important Points
 A user defined outer class can be either public or default. We can
not define a private or protected class.

 One file can have multiple classes/interfaces but out of them


only one can be public.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)

You might also like