SlideShare a Scribd company logo
5
Structure of a Java Program
Most read
6
Documentation Section:
 It includes the comments that improve the readability of the
program.
 It consists comments in Java that describe the purpose of the
program, author name, date and time of program creation.
 This section is optional and comments may appear anywhere
in the program.
Java programming language supports three types of
comments..
 Single line Comment (or end-of line comment)
 It starts with a double slash symbol (//) and terminates at the end
of the current line.
Ex: // sum of two numbers
 Multi-line Comment
/* a multi-line comment is declared like this
and can have multiple lines as a comment */
 Documentation Comment
 /** a documentation comment starts with a delimiter and ends
with */
Most read
7
Package Statement
 A package is a collection of classes, interfaces and sub-
packages.
 A sub package contains collection of classes, interfaces and
sub-sub packages etc.
 There is a provision in Java that allows you to declare your
classes in a collection called package.
 There can be only one package statement in a Java program.
 It must appear as the first statement in the source code file
before any class or interface declaration.
 This statement is optional,
Syntax: package package_name;
Example: package student;
 This statement declares that all the classes and interfaces
defined in this source file are a part of the student package.
java.lang.*;
package is imported by default and this package is
known as default package.
Most read
JAVA
P.Prathibha
Topics for Today’s Session
Differences between C,
C++ & Java
Structure of a Java
Program
Differences between C, C++ and Java
Feature C C++ Java
Programming
Paradigm
Procedural
language
Object-Oriented
Programming (OOP)
Pure Object
Oriented Oriented
Origin
Based on assembly
language
Based on C language Based on C and C++
Developer
Dennis Ritchie in
1972
Bjarne Stroustrup in
1979
James Gosling in
1991
Translator Compiler only Compiler only
Interpreted language
(Compiler + interpreter)
Platform
Dependency
Platform Dependent Platform Dependent
Platform
Independent
Code execution Direct Direct Executed by JVM
Approach Top-down Bottom-up Bottom-up
File generation .exe files .exe files .class files
Pre-processor
directives
Support header files
(#include, #define)
Supported (#header,
#define)
Use Packages
(import)
keywords 32 keywords 63 keywords 50 keywords
Contd..
Feature C C++ Java
Datatypes (union,
structure)
Supported Supported Not supported
Inheritance No inheritance Supported
Supported except
Multiple inheritance
Overloading No overloading
Support Function overloading
(Polymorphism)
Operator overloading is
not supported
Pointers Supported Supported Not supported
Allocation Use malloc, calloc Use new, delete Garbage collector
Exception Handling Not supported Supported Supported
Templates Not supported Supported Not supported
Destructors
No constructor
neither destructor
Supported Not supported
Multithreading/
Interfaces
Not supported Not supported Supported
Database
connectivity
Not supported Not supported Supported
Storage Classes
Supported ( auto,
extern )
Supported ( auto, extern ) Not supported
Structure of a Java Program
Documentation Section:
 It includes the comments that improve the readability of the
program.
 It consists comments in Java that describe the purpose of the
program, author name, date and time of program creation.
 This section is optional and comments may appear anywhere
in the program.
Java programming language supports three types of
comments..
 Single line Comment (or end-of line comment)
 It starts with a double slash symbol (//) and terminates at the end
of the current line.
Ex: // sum of two numbers
 Multi-line Comment
/* a multi-line comment is declared like this
and can have multiple lines as a comment */
 Documentation Comment
 /** a documentation comment starts with a delimiter and ends
with */
Package Statement
 A package is a collection of classes, interfaces and sub-
packages.
 A sub package contains collection of classes, interfaces and
sub-sub packages etc.
 There is a provision in Java that allows you to declare your
classes in a collection called package.
 There can be only one package statement in a Java program.
 It must appear as the first statement in the source code file
before any class or interface declaration.
 This statement is optional,
Syntax: package package_name;
Example: package student;
 This statement declares that all the classes and interfaces
defined in this source file are a part of the student package.
java.lang.*;
package is imported by default and this package is
known as default package.
Import Statement
 Many predefined classes are stored in packages in Java, an
import statement is used to refer to the classes stored in other
packages.
 An import statement is always written after the package
statement but it has to be before any class declaration.
 You can import a specific class or all the classes of the
package.
 Many classes can be imported in a single program and hence
multiple import statements can be written.
import java.util.Date; //imports the date class
import java.applet.*; //imports all the classes from the java applet package
Interface Section
 This section is used to specify an interface in Java.
 It is an optional section which is mainly used to implement
multiple inheritance in Java
 An interface is similar to a class but contains only constants
and method declarations.
 An Interfaces cannot be instantiated.
 They can only be implemented by classes or extended by other
interfaces.
Interface shape{
void draw(int length, int bredth);
void show();
}
Class Definition
 Java program may contain multiple class definition.
 Classes are primary feature of Java program.
 The classes are used to map real world problems.
 classes defines the information about the user-defined classes
in a program.
 A class is a collection of variables and methods that operate on
the fields.
 Every program in Java will have at least one class with the main
method.
class Addition
{
void add(String args[])
{
int a=2, b=3, c;
c=a+b;
System.out.println(c);
}
}
Main Method Class
 Execution of a Java application starts from the main method.
 In other words, its an entry point for the class or program that
starts in Java Run-time.
 The main () method which is from where the execution of program
actually starts and follow the statements in the order specified.
 The main method can create objects, evaluate expressions, and invoke
other methods and much more.
 On reaching the end of main, the program terminates and control
passes back to the operating system.
 The class section is mandatory.
// Program to display message on the screen
class HelloJava {
public static void main(String args[])
{
System.out.println("Hello Harsha");
} }
Summary
 In this lesson you learnt about
 Java
 Differences between C , C++ and Java
 Structure of Java Program
Structure of java program  diff c- cpp and java

More Related Content

What's hot (20)

Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
Madishetty Prathibha
 
Java program structure
Java program structureJava program structure
Java program structure
shalinikarunakaran1
 
OOP java
OOP javaOOP java
OOP java
xball977
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
Madishetty Prathibha
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
Shiv Mehmi
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
Vinod Kumar
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
VINOTH R
 
Packages in java
Packages in javaPackages in java
Packages in java
Elizabeth alexander
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
Operators in java
Operators in javaOperators in java
Operators in java
AbhishekMondal42
 
Static Members-Java.pptx
Static Members-Java.pptxStatic Members-Java.pptx
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
Strings
StringsStrings
Strings
naslin prestilda
 
JVM
JVMJVM
JVM
baabtra.com - No. 1 supplier of quality freshers
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 

Similar to Structure of java program diff c- cpp and java (20)

Multi Threading- in Java WPS Office.pptx
Multi Threading- in Java WPS Office.pptxMulti Threading- in Java WPS Office.pptx
Multi Threading- in Java WPS Office.pptx
ManasaMR2
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
Godwin585235
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]
Palak Sanghani
 
JAVA_BASICS.ppt
JAVA_BASICS.pptJAVA_BASICS.ppt
JAVA_BASICS.ppt
VGaneshKarthikeyan
 
Unit2 java
Unit2 javaUnit2 java
Unit2 java
mrecedu
 
Present the syntax of Java Introduce the Java
Present the syntax of Java Introduce the JavaPresent the syntax of Java Introduce the Java
Present the syntax of Java Introduce the Java
ssuserfd620b
 
java ppt for basic intro about java and its
java ppt for basic intro about java and itsjava ppt for basic intro about java and its
java ppt for basic intro about java and its
kssandhu875
 
Java - A parent language and powerdul for mobile apps.
Java -  A parent language and powerdul for mobile apps.Java -  A parent language and powerdul for mobile apps.
Java - A parent language and powerdul for mobile apps.
dhimananshu130803
 
Java intro
Java introJava intro
Java intro
Sonam Sharma
 
Java01
Java01Java01
Java01
Remon Hanna
 
Java01
Java01Java01
Java01
Dhaval Patel
 
Core_java_ppt.ppt
Core_java_ppt.pptCore_java_ppt.ppt
Core_java_ppt.ppt
SHIBDASDUTTA
 
Java
JavaJava
Java
QUAID-E-AWAM UNIVERSITY OF ENGINEERING, SCIENCE & TECHNOLOGY, NAWABSHAH, SINDH, PAKISTAN
 
Java_presesntation.ppt
Java_presesntation.pptJava_presesntation.ppt
Java_presesntation.ppt
VGaneshKarthikeyan
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
SouravGhosh305827
 
mukul Dubey.pptx
mukul Dubey.pptxmukul Dubey.pptx
mukul Dubey.pptx
CodeHome
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
ROGNationYT
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
ShivamChaturvedi67
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
FakeBuddy2
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
MansiDongare2
 
Ad

More from Madishetty Prathibha (11)

Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - Introduction
Madishetty Prathibha
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
Madishetty Prathibha
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Madishetty Prathibha
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
Operators in java
Operators in javaOperators in java
Operators in java
Madishetty Prathibha
 
Types of datastructures
Types of datastructuresTypes of datastructures
Types of datastructures
Madishetty Prathibha
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
Madishetty Prathibha
 
Introduction to data structures (ss)
Introduction to data structures (ss)Introduction to data structures (ss)
Introduction to data structures (ss)
Madishetty Prathibha
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
Java features
Java  features Java  features
Java features
Madishetty Prathibha
 
Introduction of java
Introduction  of javaIntroduction  of java
Introduction of java
Madishetty Prathibha
 
Ad

Recently uploaded (20)

Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 

Structure of java program diff c- cpp and java

  • 2. Topics for Today’s Session Differences between C, C++ & Java Structure of a Java Program
  • 3. Differences between C, C++ and Java Feature C C++ Java Programming Paradigm Procedural language Object-Oriented Programming (OOP) Pure Object Oriented Oriented Origin Based on assembly language Based on C language Based on C and C++ Developer Dennis Ritchie in 1972 Bjarne Stroustrup in 1979 James Gosling in 1991 Translator Compiler only Compiler only Interpreted language (Compiler + interpreter) Platform Dependency Platform Dependent Platform Dependent Platform Independent Code execution Direct Direct Executed by JVM Approach Top-down Bottom-up Bottom-up File generation .exe files .exe files .class files Pre-processor directives Support header files (#include, #define) Supported (#header, #define) Use Packages (import) keywords 32 keywords 63 keywords 50 keywords
  • 4. Contd.. Feature C C++ Java Datatypes (union, structure) Supported Supported Not supported Inheritance No inheritance Supported Supported except Multiple inheritance Overloading No overloading Support Function overloading (Polymorphism) Operator overloading is not supported Pointers Supported Supported Not supported Allocation Use malloc, calloc Use new, delete Garbage collector Exception Handling Not supported Supported Supported Templates Not supported Supported Not supported Destructors No constructor neither destructor Supported Not supported Multithreading/ Interfaces Not supported Not supported Supported Database connectivity Not supported Not supported Supported Storage Classes Supported ( auto, extern ) Supported ( auto, extern ) Not supported
  • 5. Structure of a Java Program
  • 6. Documentation Section:  It includes the comments that improve the readability of the program.  It consists comments in Java that describe the purpose of the program, author name, date and time of program creation.  This section is optional and comments may appear anywhere in the program. Java programming language supports three types of comments..  Single line Comment (or end-of line comment)  It starts with a double slash symbol (//) and terminates at the end of the current line. Ex: // sum of two numbers  Multi-line Comment /* a multi-line comment is declared like this and can have multiple lines as a comment */  Documentation Comment  /** a documentation comment starts with a delimiter and ends with */
  • 7. Package Statement  A package is a collection of classes, interfaces and sub- packages.  A sub package contains collection of classes, interfaces and sub-sub packages etc.  There is a provision in Java that allows you to declare your classes in a collection called package.  There can be only one package statement in a Java program.  It must appear as the first statement in the source code file before any class or interface declaration.  This statement is optional, Syntax: package package_name; Example: package student;  This statement declares that all the classes and interfaces defined in this source file are a part of the student package. java.lang.*; package is imported by default and this package is known as default package.
  • 8. Import Statement  Many predefined classes are stored in packages in Java, an import statement is used to refer to the classes stored in other packages.  An import statement is always written after the package statement but it has to be before any class declaration.  You can import a specific class or all the classes of the package.  Many classes can be imported in a single program and hence multiple import statements can be written. import java.util.Date; //imports the date class import java.applet.*; //imports all the classes from the java applet package
  • 9. Interface Section  This section is used to specify an interface in Java.  It is an optional section which is mainly used to implement multiple inheritance in Java  An interface is similar to a class but contains only constants and method declarations.  An Interfaces cannot be instantiated.  They can only be implemented by classes or extended by other interfaces. Interface shape{ void draw(int length, int bredth); void show(); }
  • 10. Class Definition  Java program may contain multiple class definition.  Classes are primary feature of Java program.  The classes are used to map real world problems.  classes defines the information about the user-defined classes in a program.  A class is a collection of variables and methods that operate on the fields.  Every program in Java will have at least one class with the main method. class Addition { void add(String args[]) { int a=2, b=3, c; c=a+b; System.out.println(c); } }
  • 11. Main Method Class  Execution of a Java application starts from the main method.  In other words, its an entry point for the class or program that starts in Java Run-time.  The main () method which is from where the execution of program actually starts and follow the statements in the order specified.  The main method can create objects, evaluate expressions, and invoke other methods and much more.  On reaching the end of main, the program terminates and control passes back to the operating system.  The class section is mandatory. // Program to display message on the screen class HelloJava { public static void main(String args[]) { System.out.println("Hello Harsha"); } }
  • 12. Summary  In this lesson you learnt about  Java  Differences between C , C++ and Java  Structure of Java Program