SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
Fundamentals of JAVA
Dr. Kuppusamy .P
Associate Professor / SCOPE
Content
• Evolution of Java
• Java Architecture
• Syntax of Java Program
• Simple Java Program
• Naming Convention
• Comments
Dr. Kuppusamy P
Evolution of Java
• Java was the brainchild of:
• James Gosling
• Patrick Naughton
• Chris Warth
• Ed Frank
• Frank Sheridan
• The origin of Java is on fall of 1992, and was initially called
Oak
• Oak was renamed as Java in 1995
Goal
• Platform-neutral language used for embedded devices software
• Its portable
Dr. Kuppusamy P
Java Architecture
Dr. Kuppusamy P
Java Architecture
1. Create a java source code with .java extension
2. Compile the source code using java compiler which will create
bytecode file with .class extension
3. Class loader reads both the user defined and library classes into
the memory for execution
4. Bytecode verifier validates all the bytecodes are valid and do not
violate Java’s security restrictions
5. JVM reads bytecodes and translates into machine code for
execution. While execution of the program the code interacts to
the operating system and hardware
Dr. Kuppusamy P
5 phases of Java Programs
1. Edit - Use an editor to type Java program (Welcome.java)
2. Compile - translate Java program into an intermediate language
called bytecodes, understood by Java interpreter (javac
Welcome.java)
1. Use a compiler to create .class file, containing bytecodes (Welcome.class)
3. Loader – Use a class loader to read bytecodes from .class file into
memory
4. Verifier - Use a Bytecode verifier to make sure bytecodes are
valid and do not violate security restrictions
5. Execute - Java Virtual Machine (JVM) uses a combination of
interpretation and just-intime compilation to translate bytecodes
into machine language
• Applications are run on user's machine, i.e. executed by interpreter with java
command (java Welcome)
Dr. Kuppusamy P
Java Virtual Machine (JVM)
• The output of the compiler is bytecode
• The bytecodes are executed by JVM
• It is an interpreter which converts the byte code to machine specific
instructions and executes
• JVM is platform specific
Dr. Kuppusamy P
Java Virtual Machine (JVM)
• Most modern languages are designed to be compiled
• Compilation is a one-time exercise and executes faster
• Execution of compiled code over the Internet an impossibility
• Executable code always generated to a CPU-OS combination
• Interpreting a Java program into byte code facilitates its execution
in a wide variety of environments
Dr. Kuppusamy P
Java Virtual Machine (JVM)
• Only the JVM needs to be implemented for each platform
• Once the Java runtime package exists for a given system, any Java
program can run on it
• The JVM will differ from Platform to Platform and it is Platform
Specific
• All versions of JVM interpret the same Java byte code
• Interpreted code runs much slower compared to executable code
• The use of bytecode enables the Java runtime system to execute
programs much faster
• Java facilitates on-the-fly compilation of bytecode into native code
Dr. Kuppusamy P
Adaptive optimizer (JIT Compiler)
• Another type of execution engine is an adaptive optimizer
• Speed up the execution
• The virtual machine starts by interpreting bytecodes
• It also keeps a tab on the code that is running and identifies only the heavily used
areas
• The JVM compiles these heavily used areas of code into native code
• The rest of the code, which is not heavily used continues to be interpreted and
executed
Preprocessor
• Preprocessor is a javac plugin that plugs directly into your Java compiler and
runs as part of javac.
• Not needed to add intermediate build steps, manage source generation targets.
• It’s effing fast and allows to easily build multiple targets from a single codebase.
Dr. Kuppusamy P
Class Loader / Linker
Class Loader / Linker
• class loader is a part of the VM that is important from:
• A security standpoint
• Network mobility
• The class loader loads a compiled Java source file (.class files represented as
bytecode) into the Java Virtual Machine (JVM)
• The bootstrap class loader (linker) is responsible for loading the classes,
programmer defined classes as well as Java's API classes
Java .class file
1. Java class file is designed for
• platform independence
• network mobility
2. The class file is compiled to a target JVM, but independent of underlying host
platforms
3. The Java class file is a binary file that has the capability to run on any platform
Dr. Kuppusamy P
Syntax of Java program
public class Classname
{
public static void main(String args[])
{
Statements
…..
}
}
Dr. Kuppusamy P
Create source file: Classname .java
Compile: javac Classname .java
Execute: java Classname
static – only one copy of memory is allotted (created) for the method main().
public – This main method can access by all members like objects, classes, etc
void – main() is not returns anything
String args[] – Input given in the console considered as string arguments
Simple Java program
public class Mobilephone {
public static void main(String args[]) {
System.out.println(“Experience the PUBG..!”);
} }
Output:
“Experience the PUBG..!”
Dr. Kuppusamy P
Create source file: Mobilephone .java
Compile: javac Mobilephone .java
Execute: java Mobilephone
Java program - Naming Conventions
Class Names
• Class names should be nouns, simple and descriptive
• Noun could be in mixed case with the first letter of each internal word capitalized
• Eg: class Student, class TestStudent
Variable Names
• The variables are in mixed case with a lowercase first letter
• Variable names should not start with underscore _ or dollar sign $, even though
both are allowed
• Variable names should be small and meaningful
• One-character variable names should be avoided except for temporary variables
• Eg: int y, myWidth;
Method Names
• Methods should be verbs, in mixed case with the first letter lowercase, with the
first letter of each internal word capitalized
• Eg: void run(), void getColor()
Dr. Kuppusamy P
Java program - Comments
Block (Multi-line) Comments
• Block comments are used to provide descriptions of files, methods, data structures
and algorithms
• Block comments may be used at the beginning of each file and before each method
/*
Here is a block comment
*/
Single line Comment
• Single line comments can be written using // Single line
Dr. Kuppusamy P
Number of Variables Declaration per Line
• One declaration per line is recommended
int height;
int width;
is preferred over
int height, width;
• Do not declare different types on the same line
int height, width[]; // Not recommended
Dr. Kuppusamy P
References
Dr. Kuppusamy P
Herbert Schildt, “Java: The Complete Reference”, McGraw-Hill Education, Tenth edition,
2017.

Contenu connexe

Tendances

Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
Ravi_Kant_Sahu
 

Tendances (20)

Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Features of java
Features of javaFeatures of java
Features of java
 
core java
core javacore java
core java
 
Java
JavaJava
Java
 
Introduction to Basic Java Versions and their features
Introduction to Basic Java Versions and their featuresIntroduction to Basic Java Versions and their features
Introduction to Basic Java Versions and their features
 
History of java'
History of java'History of java'
History of java'
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaWhat Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
 
Features of java
Features of javaFeatures of java
Features of java
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Java PPT
Java PPTJava PPT
Java PPT
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
Basic of Java
Basic of JavaBasic of Java
Basic of Java
 
Java Development Kit (jdk)
Java Development Kit (jdk)Java Development Kit (jdk)
Java Development Kit (jdk)
 
JAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdfJAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdf
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
 

Similaire à Java introduction

PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
CDSukte
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
Murugesh33
 
Presentación rs232 java
Presentación rs232 javaPresentación rs232 java
Presentación rs232 java
John Rojas
 

Similaire à Java introduction (20)

Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java introduction
Java introductionJava introduction
Java introduction
 
1 java introduction
1 java introduction1 java introduction
1 java introduction
 
1 java intro
1 java intro1 java intro
1 java intro
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdf
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
Unit1 JAVA.pptx
Unit1 JAVA.pptxUnit1 JAVA.pptx
Unit1 JAVA.pptx
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Lec 3 01_aug13
Lec 3 01_aug13Lec 3 01_aug13
Lec 3 01_aug13
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
 
Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwords
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming
 
Presentación rs232 java
Presentación rs232 javaPresentación rs232 java
Presentación rs232 java
 

Plus de Kuppusamy P

Plus de Kuppusamy P (20)

Recurrent neural networks rnn
Recurrent neural networks   rnnRecurrent neural networks   rnn
Recurrent neural networks rnn
 
Deep learning
Deep learningDeep learning
Deep learning
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
Image enhancement
Image enhancementImage enhancement
Image enhancement
 
Feature detection and matching
Feature detection and matchingFeature detection and matching
Feature detection and matching
 
Image processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filtersImage processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filters
 
Flowchart design for algorithms
Flowchart design for algorithmsFlowchart design for algorithms
Flowchart design for algorithms
 
Algorithm basics
Algorithm basicsAlgorithm basics
Algorithm basics
 
Problem solving using Programming
Problem solving using ProgrammingProblem solving using Programming
Problem solving using Programming
 
Parts of Computer, Hardware and Software
Parts of Computer, Hardware and Software Parts of Computer, Hardware and Software
Parts of Computer, Hardware and Software
 
Strings in java
Strings in javaStrings in java
Strings in java
 
Java methods or Subroutines or Functions
Java methods or Subroutines or FunctionsJava methods or Subroutines or Functions
Java methods or Subroutines or Functions
 
Java arrays
Java arraysJava arrays
Java arrays
 
Java iterative statements
Java iterative statementsJava iterative statements
Java iterative statements
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Java data types
Java data typesJava data types
Java data types
 
Logistic regression in Machine Learning
Logistic regression in Machine LearningLogistic regression in Machine Learning
Logistic regression in Machine Learning
 
Anomaly detection (Unsupervised Learning) in Machine Learning
Anomaly detection (Unsupervised Learning) in Machine LearningAnomaly detection (Unsupervised Learning) in Machine Learning
Anomaly detection (Unsupervised Learning) in Machine Learning
 
Machine Learning Performance metrics for classification
Machine Learning Performance metrics for classificationMachine Learning Performance metrics for classification
Machine Learning Performance metrics for classification
 
Machine learning Introduction
Machine learning IntroductionMachine learning Introduction
Machine learning Introduction
 

Dernier

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

Java introduction

  • 1. Fundamentals of JAVA Dr. Kuppusamy .P Associate Professor / SCOPE
  • 2. Content • Evolution of Java • Java Architecture • Syntax of Java Program • Simple Java Program • Naming Convention • Comments Dr. Kuppusamy P
  • 3. Evolution of Java • Java was the brainchild of: • James Gosling • Patrick Naughton • Chris Warth • Ed Frank • Frank Sheridan • The origin of Java is on fall of 1992, and was initially called Oak • Oak was renamed as Java in 1995 Goal • Platform-neutral language used for embedded devices software • Its portable Dr. Kuppusamy P
  • 5. Java Architecture 1. Create a java source code with .java extension 2. Compile the source code using java compiler which will create bytecode file with .class extension 3. Class loader reads both the user defined and library classes into the memory for execution 4. Bytecode verifier validates all the bytecodes are valid and do not violate Java’s security restrictions 5. JVM reads bytecodes and translates into machine code for execution. While execution of the program the code interacts to the operating system and hardware Dr. Kuppusamy P
  • 6. 5 phases of Java Programs 1. Edit - Use an editor to type Java program (Welcome.java) 2. Compile - translate Java program into an intermediate language called bytecodes, understood by Java interpreter (javac Welcome.java) 1. Use a compiler to create .class file, containing bytecodes (Welcome.class) 3. Loader – Use a class loader to read bytecodes from .class file into memory 4. Verifier - Use a Bytecode verifier to make sure bytecodes are valid and do not violate security restrictions 5. Execute - Java Virtual Machine (JVM) uses a combination of interpretation and just-intime compilation to translate bytecodes into machine language • Applications are run on user's machine, i.e. executed by interpreter with java command (java Welcome) Dr. Kuppusamy P
  • 7. Java Virtual Machine (JVM) • The output of the compiler is bytecode • The bytecodes are executed by JVM • It is an interpreter which converts the byte code to machine specific instructions and executes • JVM is platform specific Dr. Kuppusamy P
  • 8. Java Virtual Machine (JVM) • Most modern languages are designed to be compiled • Compilation is a one-time exercise and executes faster • Execution of compiled code over the Internet an impossibility • Executable code always generated to a CPU-OS combination • Interpreting a Java program into byte code facilitates its execution in a wide variety of environments Dr. Kuppusamy P
  • 9. Java Virtual Machine (JVM) • Only the JVM needs to be implemented for each platform • Once the Java runtime package exists for a given system, any Java program can run on it • The JVM will differ from Platform to Platform and it is Platform Specific • All versions of JVM interpret the same Java byte code • Interpreted code runs much slower compared to executable code • The use of bytecode enables the Java runtime system to execute programs much faster • Java facilitates on-the-fly compilation of bytecode into native code Dr. Kuppusamy P
  • 10. Adaptive optimizer (JIT Compiler) • Another type of execution engine is an adaptive optimizer • Speed up the execution • The virtual machine starts by interpreting bytecodes • It also keeps a tab on the code that is running and identifies only the heavily used areas • The JVM compiles these heavily used areas of code into native code • The rest of the code, which is not heavily used continues to be interpreted and executed Preprocessor • Preprocessor is a javac plugin that plugs directly into your Java compiler and runs as part of javac. • Not needed to add intermediate build steps, manage source generation targets. • It’s effing fast and allows to easily build multiple targets from a single codebase. Dr. Kuppusamy P
  • 11. Class Loader / Linker Class Loader / Linker • class loader is a part of the VM that is important from: • A security standpoint • Network mobility • The class loader loads a compiled Java source file (.class files represented as bytecode) into the Java Virtual Machine (JVM) • The bootstrap class loader (linker) is responsible for loading the classes, programmer defined classes as well as Java's API classes Java .class file 1. Java class file is designed for • platform independence • network mobility 2. The class file is compiled to a target JVM, but independent of underlying host platforms 3. The Java class file is a binary file that has the capability to run on any platform Dr. Kuppusamy P
  • 12. Syntax of Java program public class Classname { public static void main(String args[]) { Statements ….. } } Dr. Kuppusamy P Create source file: Classname .java Compile: javac Classname .java Execute: java Classname static – only one copy of memory is allotted (created) for the method main(). public – This main method can access by all members like objects, classes, etc void – main() is not returns anything String args[] – Input given in the console considered as string arguments
  • 13. Simple Java program public class Mobilephone { public static void main(String args[]) { System.out.println(“Experience the PUBG..!”); } } Output: “Experience the PUBG..!” Dr. Kuppusamy P Create source file: Mobilephone .java Compile: javac Mobilephone .java Execute: java Mobilephone
  • 14. Java program - Naming Conventions Class Names • Class names should be nouns, simple and descriptive • Noun could be in mixed case with the first letter of each internal word capitalized • Eg: class Student, class TestStudent Variable Names • The variables are in mixed case with a lowercase first letter • Variable names should not start with underscore _ or dollar sign $, even though both are allowed • Variable names should be small and meaningful • One-character variable names should be avoided except for temporary variables • Eg: int y, myWidth; Method Names • Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized • Eg: void run(), void getColor() Dr. Kuppusamy P
  • 15. Java program - Comments Block (Multi-line) Comments • Block comments are used to provide descriptions of files, methods, data structures and algorithms • Block comments may be used at the beginning of each file and before each method /* Here is a block comment */ Single line Comment • Single line comments can be written using // Single line Dr. Kuppusamy P
  • 16. Number of Variables Declaration per Line • One declaration per line is recommended int height; int width; is preferred over int height, width; • Do not declare different types on the same line int height, width[]; // Not recommended Dr. Kuppusamy P
  • 17. References Dr. Kuppusamy P Herbert Schildt, “Java: The Complete Reference”, McGraw-Hill Education, Tenth edition, 2017.