SlideShare a Scribd company logo
4
Most read
6
Most read
7
Most read
Computer
Programming 2
Lesson 1 – JAVA BASIC SYNTAX
Prepared by: Analyn G. Regaton
Definition of
Java program
It can be defined as a collection of
objects that communicate via
invoking each other's methods.
Overview of
class, objects
and methods
Let us now briefly look into what do class, object, methods, and
instance variables mean.
 Object − Objects have states and behaviors. Example: A dog has
states - color, name, breed as well as behavior such as wagging
their tail, barking, eating. An object is an instance of a class.
 Class − A class can be defined as a template/blueprint that
describes the behavior/state that the object of its type supports.
 Methods − A method is basically a behavior. A class can contain
many methods. It is in methods where the logics are written,
data is manipulated and all the actions are executed.
 Instance Variables − Each object has its unique set of instance
variables. An object's state is created by the values assigned to
these instance variables.
BasicSyntax
 Case Sensitivity − Java is case sensitive, which means
identifier Hello and hello would have different meaning in Java.
 Class Names − For all class names the first letter should be in Upper Case.
If several words are used to form a name of the class, each inner word's
first letter should be in Upper Case.
Example: class MyFirstJavaClass
 Method Names − All method names should start with a Lower Case letter.
If several words are used to form the name of the method, then each
inner word's first letter should be in Upper Case.
Example: public void myMethodName()
 Program File Name − Name of the program file should exactly match
the class name.
Example: Assume 'MyFirstJavaProgram' is the class name. Then the file
should be saved as 'MyFirstJavaProgram.java’
 public static void main(String args[]) − Java program processing starts
from the main() method which is a mandatory part of every Java
program.
FIRSTJAVA
PROGRAM
Let us look at a simple code that will print the words Hello World.
JAVA
IDENTIFIER
Identifiers – are Names used for classes, variables, and methods .
In Java, there are several points to remember about identifiers. They
are as follows −
 All identifiers should begin with a letter (A to Z or a to z),
currency character ($) or an underscore (_).
 After the first character, identifiers can have any combination of
characters.
 A key word cannot be used as an identifier.
 Most importantly, identifiers are case sensitive.
Examples of legal identifiers: age, $salary, _value, __1_value.
Examples of illegal identifiers: 123abc, -salary. public, void
Note: More details in this
topic will tackle in the next
lesson
JAVA ENUM
 Enums were introduced in Java 5.0. Enums restrict a variable to
have one of only a few predefined values. The values in this
enumerated list are called enums.
 With the use of enums it is possible to reduce the number of bugs
in your code.
 For example, if we consider an application for a fresh juice shop, it
would be possible to restrict the glass size to small, medium, and
large. This would make sure that it would not allow anyone to order
any size other than small, medium, or large.
JAVA ENUM
The above example will produce the following result −
Output
Size: MEDIUM
Note − Enums can be declared as their own or inside a class. Methods,
variables, constructors can be defined inside enums as well.
JAVA
KEYWORDS
abstract assert boolean break
byte case catch char
class const continue default
do double else enum
extends final finally float
for goto if implements
import instanceof int interface
long native new package
private protected public return
short static strictfp super
switch synchronized this throw
throws transient try void
volatile while
The following list shows the reserved words in Java. These
reserved words may not be used as constant or variable or
any other identifier names.
Note: Remember this
keywords
JAVA
COMMENTS
Java supports single-line and multi-line comments very similar to C
and C++. All characters available inside any comment are ignored by
Java compiler.
public class MyFirstJavaProgram
{
/* This is my first java program.
This will print 'Hello World' as the output
* This is an example of multi-line comments.
*/
public static void main(String []args) {
// This is an example of single line comment
/* This is also an example of single line comment. */
System.out.println("Hello World");
}
}
Note : // and /* */ are comments
Output
Hello World

More Related Content

What's hot (20)

PPSX
Java Object Oriented Programming
University of Potsdam
 
PPTX
Structures in c language
Tanmay Modi
 
PPT
Ch 3 event driven programming
Chaffey College
 
PDF
Learn C# Programming - Decision Making & Loops
Eng Teong Cheah
 
PPT
Decision making and branching
Hossain Md Shakhawat
 
PDF
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
PPTX
for loop in java
Majid Ali
 
PPTX
_transaction_processing.pptx
HarshaVardhanReddy305916
 
PPTX
Er diagrams presentation
Akanksha Jaiswal
 
PPT
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
PPTX
Fundamentals of c programming
Chitrank Dixit
 
PPT
Event+driven+programming key+features
Faisal Aziz
 
PPT
C#.NET
gurchet
 
PDF
CS3270 – Database Systems Course Outline
Dilawar Khan
 
PDF
Immutable vs mutable data types in python
Learnbay Datascience
 
PPTX
Decision making in JAVA
Hamna_sheikh
 
PDF
python notes.pdf
RohitSindhu10
 
PPTX
Swap Administration in linux platform
ashutosh123gupta
 
PPTX
System Development Life Cycle (SDLC), Types of SDLC | Waterfall Model and Spi...
Uttar Tamang ✔
 
PPTX
Variables in C++, data types in c++
Neeru Mittal
 
Java Object Oriented Programming
University of Potsdam
 
Structures in c language
Tanmay Modi
 
Ch 3 event driven programming
Chaffey College
 
Learn C# Programming - Decision Making & Loops
Eng Teong Cheah
 
Decision making and branching
Hossain Md Shakhawat
 
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
for loop in java
Majid Ali
 
_transaction_processing.pptx
HarshaVardhanReddy305916
 
Er diagrams presentation
Akanksha Jaiswal
 
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
Fundamentals of c programming
Chitrank Dixit
 
Event+driven+programming key+features
Faisal Aziz
 
C#.NET
gurchet
 
CS3270 – Database Systems Course Outline
Dilawar Khan
 
Immutable vs mutable data types in python
Learnbay Datascience
 
Decision making in JAVA
Hamna_sheikh
 
python notes.pdf
RohitSindhu10
 
Swap Administration in linux platform
ashutosh123gupta
 
System Development Life Cycle (SDLC), Types of SDLC | Waterfall Model and Spi...
Uttar Tamang ✔
 
Variables in C++, data types in c++
Neeru Mittal
 

Similar to Computer programming 2 chapter 1 (20)

PDF
java
Kunal Sunesara
 
PPTX
Java syntax-and-grammars-oct8
MISSIASABTAL1
 
PPTX
Java basics
Ayshwarya Baburam
 
PDF
Object Oriented Principles
Sujit Majety
 
PDF
Java basic-syntax
javaicon
 
PDF
Java basic syntax
3trg
 
PPSX
Features of java technology
Prognoz Technologies Pvt. Ltd.
 
PDF
Java basic-syntax
Shahid Rasheed
 
PPTX
Basic syntax
Ducat India
 
PDF
2.Lesson Plan - Java Variables and Data types.pdf.pdf
AbhishekSingh757567
 
PPTX
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
İbrahim Kürce
 
PDF
Java unit 2
Shipra Swati
 
PPTX
Computer programming 2 Lesson 6
MLG College of Learning, Inc
 
PPTX
Modern_2.pptx for java
MayaTofik
 
DOCX
javaopps concepts
Nikhil Agrawal
 
PPTX
Basics of Java
Sherihan Anver
 
DOCX
java traning report_Summer.docx
GauravSharma164138
 
PPTX
Suga java training_with_footer
Sugavanam Natarajan
 
PPTX
Java_Roadmap.pptx
ssuser814cf2
 
PPTX
07 java variables
Zeeshan-Shaikh
 
Java syntax-and-grammars-oct8
MISSIASABTAL1
 
Java basics
Ayshwarya Baburam
 
Object Oriented Principles
Sujit Majety
 
Java basic-syntax
javaicon
 
Java basic syntax
3trg
 
Features of java technology
Prognoz Technologies Pvt. Ltd.
 
Java basic-syntax
Shahid Rasheed
 
Basic syntax
Ducat India
 
2.Lesson Plan - Java Variables and Data types.pdf.pdf
AbhishekSingh757567
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
İbrahim Kürce
 
Java unit 2
Shipra Swati
 
Computer programming 2 Lesson 6
MLG College of Learning, Inc
 
Modern_2.pptx for java
MayaTofik
 
javaopps concepts
Nikhil Agrawal
 
Basics of Java
Sherihan Anver
 
java traning report_Summer.docx
GauravSharma164138
 
Suga java training_with_footer
Sugavanam Natarajan
 
Java_Roadmap.pptx
ssuser814cf2
 
07 java variables
Zeeshan-Shaikh
 
Ad

More from MLG College of Learning, Inc (20)

PPTX
PC111.Lesson1
MLG College of Learning, Inc
 
PPTX
PC111-lesson1.pptx
MLG College of Learning, Inc
 
PPTX
PC LEESOON 6.pptx
MLG College of Learning, Inc
 
PPTX
PC 106 PPT-09.pptx
MLG College of Learning, Inc
 
PPTX
PC 106 PPT-07
MLG College of Learning, Inc
 
PPTX
PC 106 PPT-01
MLG College of Learning, Inc
 
PPTX
PC 106 Slide 04
MLG College of Learning, Inc
 
PPTX
PC 106 Slide no.02
MLG College of Learning, Inc
 
PPTX
pc-106-slide-3
MLG College of Learning, Inc
 
PPTX
PC 106 Slide 2
MLG College of Learning, Inc
 
PPTX
PC 106 Slide 1.pptx
MLG College of Learning, Inc
 
PDF
Db2 characteristics of db ms
MLG College of Learning, Inc
 
PDF
Db1 introduction
MLG College of Learning, Inc
 
Ad

Recently uploaded (20)

PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
CHILD RIGHTS AND PROTECTION QUESTION BANK
Dr Raja Mohammed T
 
PDF
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
CHILD RIGHTS AND PROTECTION QUESTION BANK
Dr Raja Mohammed T
 
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 

Computer programming 2 chapter 1

  • 1. Computer Programming 2 Lesson 1 – JAVA BASIC SYNTAX Prepared by: Analyn G. Regaton
  • 2. Definition of Java program It can be defined as a collection of objects that communicate via invoking each other's methods.
  • 3. Overview of class, objects and methods Let us now briefly look into what do class, object, methods, and instance variables mean.  Object − Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behavior such as wagging their tail, barking, eating. An object is an instance of a class.  Class − A class can be defined as a template/blueprint that describes the behavior/state that the object of its type supports.  Methods − A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.  Instance Variables − Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.
  • 4. BasicSyntax  Case Sensitivity − Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.  Class Names − For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example: class MyFirstJavaClass  Method Names − All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example: public void myMethodName()  Program File Name − Name of the program file should exactly match the class name. Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java’  public static void main(String args[]) − Java program processing starts from the main() method which is a mandatory part of every Java program.
  • 5. FIRSTJAVA PROGRAM Let us look at a simple code that will print the words Hello World.
  • 6. JAVA IDENTIFIER Identifiers – are Names used for classes, variables, and methods . In Java, there are several points to remember about identifiers. They are as follows −  All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_).  After the first character, identifiers can have any combination of characters.  A key word cannot be used as an identifier.  Most importantly, identifiers are case sensitive. Examples of legal identifiers: age, $salary, _value, __1_value. Examples of illegal identifiers: 123abc, -salary. public, void Note: More details in this topic will tackle in the next lesson
  • 7. JAVA ENUM  Enums were introduced in Java 5.0. Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums.  With the use of enums it is possible to reduce the number of bugs in your code.  For example, if we consider an application for a fresh juice shop, it would be possible to restrict the glass size to small, medium, and large. This would make sure that it would not allow anyone to order any size other than small, medium, or large.
  • 8. JAVA ENUM The above example will produce the following result − Output Size: MEDIUM Note − Enums can be declared as their own or inside a class. Methods, variables, constructors can be defined inside enums as well.
  • 9. JAVA KEYWORDS abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch synchronized this throw throws transient try void volatile while The following list shows the reserved words in Java. These reserved words may not be used as constant or variable or any other identifier names. Note: Remember this keywords
  • 10. JAVA COMMENTS Java supports single-line and multi-line comments very similar to C and C++. All characters available inside any comment are ignored by Java compiler. public class MyFirstJavaProgram { /* This is my first java program. This will print 'Hello World' as the output * This is an example of multi-line comments. */ public static void main(String []args) { // This is an example of single line comment /* This is also an example of single line comment. */ System.out.println("Hello World"); } } Note : // and /* */ are comments Output Hello World