SlideShare a Scribd company logo
Java Programming Fundamentals
•The basic structure in object-oriented
programming languages is a CLASS.
•Java programs are built using classes and
objects.
•A class is:
–a template or a blueprint
–Made up of ATTRIBUTES and BEHAVIOR
–Attributes are represented by variables and
behavior is revealed through methods
An example of a class (from Chapter 1)
–class Student
Student
name
age
course
studID
applyForEnrollment( )
payFees( )
class name
attributes / variables
behavior / methods
•Defining a class
In Java, a class is identified by a class name. To define
or declare a class:
class < ClassName > {
[ attribute/variable declarations ]
[ behavior/method declarations ]
}
•Conventions used
–Italicized words bounded by < > are programmer-
supplied
–Text in [ ] are optional
–Most object-oriented languages, such as Java, are
case-sensitive. Therefore, Student is different from
student.
Method
–Specifies the behavior(s) of a particular class, and is
defined within a class
–Contains a statement or set of statements that a
program must do or accomplish
–Identified by a method name, followed by a pair of
open and close parentheses
–It may or may not be bounded by a return statement
Defining a method
–To define or “declare” a method:
return-type < methodName > ( ) {
[statement 1];
[statement 2];
[return <variableName>]
}
•Problem:
–Write a program that would print out “I Love Java”
•Using the steps in program development from
chapter 1:
1.Problem Definition:
Print out “I Love Java”
2.Problem Analysis using HIPO Chart
INPUT PROCESS OUTPUT
“I Love Java” Print “I Love
Java”
printed “I Love
Java”
3.Program coding using java
1 public class GuirreLoveJava
2 /*
3 To display I LOVE JAVA
4 */
5 { public static void main(String[] args)
6 // prints the string “I LOVE JAVA” on the screen
7 { System.out.println(“I LOVE JAVA");
8 }
9 }
Steps in program coding using a text editor and
console:
1. Open a text editor such as Notepad or WordPad (for
Windows); vi for Linux or Unix.
2. Write or type your source code (as shown above) in
the text editor.
3. Save your file as: GuirreLoveJava.java. Don’t forget
that your file should have an extension of “.java”.
•4. Compile your program:
4a. In Windows, open another window in the MS-Dos
command prompt
4b. Go to the folder where your program
GuirreLoveJava.java is saved.
4c. To compile, type the command:
javac GuirreLoveJava.java
4d. Make sure there are no syntax (or typing) errors.
•5. Running your program:
5a. If the compilation from the previous step was
successful, a GuirreLoveJava.class file is created on
the current directory. Check to see if this file exists.
5b. To run your program, type the command:
java GuirreLoveJava
Explanation of the GuirreLoveJava program
•Line 1: The class name is “GuirreLoveJava”. Class
names start with a capital letter. Starting letters of
succeeding words are also capitalized.
• Lines 2 to 4: are comment lines describing what the
class does. These lines are skipped by the compiler.
•Line 5: A method named main( ) is declared inside the class.
• All applications must contain at least one main
method. Other methods can be declared but must not
be named “main”.
• When the program is run, main( ) is always the first
method to execute.
• All statements inside the main ( ) block are part of the
method
•Line 6: Another comment line describing what the main(
) method does
•Line 7: Prints out “GuirreLoveJava” on the screen
•Line 8: Ends the main( ) method
•Line 9: Ends the GuirreLoveJava class
Two types of errors occur when
compiling and running a program:
–Syntax Errors
–Runtime Errors
Syntax Errors
•Common errors in typing or in the use of some
keywords
•More complex syntax errors occur when certain
java object-oriented principles are violated
•When the java compiler detects these errors, it
displays error messages after the javac command
Runtime Errors
•Also called logic errors, these errors occur during
runtime and may or may not cause the program to
stop
•Some errors that do not cause the program to stop
are:
• Infinite loops
• Programs that display wrong outputs
Java Program Statements
–Inside the main ( ) method are statements that make
up the body of the program. When the program is run
these are executed by the Java Runtime Environment.
–Java program statements are terminated by a semi-
colon.
•A block is composed of several statements. A pair of curly
braces { } defines the scope of a block.
•The body of classes and methods are always defined
inside a block. This block defines the start and end points
of the class or method.
•Blocks can also be nested.
Comments
Programming statements that do not get compiled
and are not executed by the interpreter They are
written for documentation purposes
•3 types of comments
–Single line comments
–Multi-line comments
–Special javadoc comments
Single line (or C++ style) comments
start with //. All text after // are treated as comments
Example:
// This is an example of a single line comment
Multi-line (or C-style) comments
Are delimited by /* and */. All text between the two
delimiters are treated as comments. The comments can
span multiple lines.
Example:
/* This is an example of a comment spanning
multiple lines */
Special Javadoc comments
•Are used for generating an HTML documentation for
your java programs.
•It contains tags to add more information to your
comments. It can also span several lines.
•Example:
/** This is an example of a javadoc comments n for
generating an html documentation @author Claudio
Sanchez @version 1.3 */

More Related Content

PPSX
Seminar on java
PDF
Java Collection Interview Questions [Updated]
PPTX
8. sql
PDF
Enhanced switch statement in Java 14
PPT
Introduction to Google Apps Script
DOCX
ANGULAR JS LAB MANUAL(final) vtu2021 sch
Seminar on java
Java Collection Interview Questions [Updated]
8. sql
Enhanced switch statement in Java 14
Introduction to Google Apps Script
ANGULAR JS LAB MANUAL(final) vtu2021 sch

What's hot (9)

PDF
MVC in PHP
PDF
Classes and Nested Classes in Java
PPTX
Enum
PPT
Introduction to CSS
PDF
CLASS & OBJECT IN JAVA
PPTX
Inheritance and Polymorphism in java simple and clear
PDF
4.3 MySQL + PHP
PPTX
Java abstract class & abstract methods
PPT
Php Presentation
MVC in PHP
Classes and Nested Classes in Java
Enum
Introduction to CSS
CLASS & OBJECT IN JAVA
Inheritance and Polymorphism in java simple and clear
4.3 MySQL + PHP
Java abstract class & abstract methods
Php Presentation
Ad

Similar to Java Programming Fundamentals (20)

PPTX
OBJECT ORIENTED PROGRAMMING Unit2 second half.pptx
DOCX
Unit of competency
PPTX
Multi Threading- in Java WPS Office.pptx
PPT
Packages and interfaces
PPTX
Java Tutorial Lab 1
PPTX
Unit II Inheritance ,Interface and Packages.pptx
PPTX
Introduction to Java Programming
PPT
01slide
PPT
01slide
PPTX
PPTX
OOP with Java
PPT
Java for Mainframers
PPT
01slide
PPTX
flowchart demasdasddasdsadsadsadasoasd.pptx
PPT
2) java development
PPT
Basics of java 1
PPT
01slide (1)ffgfefge
PPTX
JAVA PROGRAMING NOTE FOR BEGINNERS 20242
PPTX
Object Oriented Programming unit 1 content for students
PPT
Classes and Objects
OBJECT ORIENTED PROGRAMMING Unit2 second half.pptx
Unit of competency
Multi Threading- in Java WPS Office.pptx
Packages and interfaces
Java Tutorial Lab 1
Unit II Inheritance ,Interface and Packages.pptx
Introduction to Java Programming
01slide
01slide
OOP with Java
Java for Mainframers
01slide
flowchart demasdasddasdsadsadsadasoasd.pptx
2) java development
Basics of java 1
01slide (1)ffgfefge
JAVA PROGRAMING NOTE FOR BEGINNERS 20242
Object Oriented Programming unit 1 content for students
Classes and Objects
Ad

More from Dr. Rosemarie Sibbaluca-Guirre (20)

PPTX
Korean Language: Culture 한국어 개요
PPTX
Korean Language Overview 한국어 개요
PPTX
Conjunction 접속사
PPTX
PPTX
Usage of Particles 입자의 사용
PPTX
Usage of Particles 입자의 사용
PPTX
Korean Word Order 한국어 단어 순서
PPTX
Korean Number 한국 번호
PPTX
ISAD 313-3_ TOOLS OF THE SYSTEM ANALYSIS.pptx
PPTX
ISAD 313-1_INTRODUCTION TO SYSTEMS.pptx
PPTX
ISAD 313-2_ SYSTEM ANALYSIS.pptx
PPTX
ISAD 313-4_ RESEARCH PROJECT.pptx
PPTX
ISAD 313-3_ SYSTEM FLOW.pptx
PPTX
ISAD 313-3_ MODELS.pptx
PPTX
ACCT11_9_Financial Position.pptx
PPTX
ACCT11_8_Equity.pptx
PPTX
ACCT11_7_Performance.pptx
PPTX
ACCT11_6_Worksheet.pptx
PPTX
ACCT11_5_Adjusting Entries.pptx
PPTX
ACCT11_4_Trial Balance.pptx
Korean Language: Culture 한국어 개요
Korean Language Overview 한국어 개요
Conjunction 접속사
Usage of Particles 입자의 사용
Usage of Particles 입자의 사용
Korean Word Order 한국어 단어 순서
Korean Number 한국 번호
ISAD 313-3_ TOOLS OF THE SYSTEM ANALYSIS.pptx
ISAD 313-1_INTRODUCTION TO SYSTEMS.pptx
ISAD 313-2_ SYSTEM ANALYSIS.pptx
ISAD 313-4_ RESEARCH PROJECT.pptx
ISAD 313-3_ SYSTEM FLOW.pptx
ISAD 313-3_ MODELS.pptx
ACCT11_9_Financial Position.pptx
ACCT11_8_Equity.pptx
ACCT11_7_Performance.pptx
ACCT11_6_Worksheet.pptx
ACCT11_5_Adjusting Entries.pptx
ACCT11_4_Trial Balance.pptx

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Onica Farming 24rsclub profitable farm business
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
Pharma ospi slides which help in ospi learning
PDF
English Language Teaching from Post-.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PDF
From loneliness to social connection charting
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Onica Farming 24rsclub profitable farm business
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Structure & Organelles in detailed.
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O7-L3 Supply Chain Operations - ICLT Program
The Final Stretch: How to Release a Game and Not Die in the Process.
Pharma ospi slides which help in ospi learning
English Language Teaching from Post-.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Renaissance Architecture: A Journey from Faith to Humanism
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
UPPER GASTRO INTESTINAL DISORDER.docx
How to Manage Starshipit in Odoo 18 - Odoo Slides
From loneliness to social connection charting
O5-L3 Freight Transport Ops (International) V1.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
Revamp in MTO Odoo 18 Inventory - Odoo Slides

Java Programming Fundamentals

  • 2. •The basic structure in object-oriented programming languages is a CLASS. •Java programs are built using classes and objects. •A class is: –a template or a blueprint –Made up of ATTRIBUTES and BEHAVIOR –Attributes are represented by variables and behavior is revealed through methods
  • 3. An example of a class (from Chapter 1) –class Student Student name age course studID applyForEnrollment( ) payFees( ) class name attributes / variables behavior / methods
  • 4. •Defining a class In Java, a class is identified by a class name. To define or declare a class: class < ClassName > { [ attribute/variable declarations ] [ behavior/method declarations ] }
  • 5. •Conventions used –Italicized words bounded by < > are programmer- supplied –Text in [ ] are optional –Most object-oriented languages, such as Java, are case-sensitive. Therefore, Student is different from student.
  • 6. Method –Specifies the behavior(s) of a particular class, and is defined within a class –Contains a statement or set of statements that a program must do or accomplish –Identified by a method name, followed by a pair of open and close parentheses –It may or may not be bounded by a return statement
  • 7. Defining a method –To define or “declare” a method: return-type < methodName > ( ) { [statement 1]; [statement 2]; [return <variableName>] }
  • 8. •Problem: –Write a program that would print out “I Love Java” •Using the steps in program development from chapter 1: 1.Problem Definition: Print out “I Love Java”
  • 9. 2.Problem Analysis using HIPO Chart INPUT PROCESS OUTPUT “I Love Java” Print “I Love Java” printed “I Love Java”
  • 10. 3.Program coding using java 1 public class GuirreLoveJava 2 /* 3 To display I LOVE JAVA 4 */ 5 { public static void main(String[] args) 6 // prints the string “I LOVE JAVA” on the screen 7 { System.out.println(“I LOVE JAVA"); 8 } 9 }
  • 11. Steps in program coding using a text editor and console: 1. Open a text editor such as Notepad or WordPad (for Windows); vi for Linux or Unix. 2. Write or type your source code (as shown above) in the text editor. 3. Save your file as: GuirreLoveJava.java. Don’t forget that your file should have an extension of “.java”.
  • 12. •4. Compile your program: 4a. In Windows, open another window in the MS-Dos command prompt 4b. Go to the folder where your program GuirreLoveJava.java is saved. 4c. To compile, type the command: javac GuirreLoveJava.java 4d. Make sure there are no syntax (or typing) errors.
  • 13. •5. Running your program: 5a. If the compilation from the previous step was successful, a GuirreLoveJava.class file is created on the current directory. Check to see if this file exists. 5b. To run your program, type the command: java GuirreLoveJava
  • 14. Explanation of the GuirreLoveJava program •Line 1: The class name is “GuirreLoveJava”. Class names start with a capital letter. Starting letters of succeeding words are also capitalized. • Lines 2 to 4: are comment lines describing what the class does. These lines are skipped by the compiler.
  • 15. •Line 5: A method named main( ) is declared inside the class. • All applications must contain at least one main method. Other methods can be declared but must not be named “main”. • When the program is run, main( ) is always the first method to execute. • All statements inside the main ( ) block are part of the method
  • 16. •Line 6: Another comment line describing what the main( ) method does •Line 7: Prints out “GuirreLoveJava” on the screen •Line 8: Ends the main( ) method •Line 9: Ends the GuirreLoveJava class
  • 17. Two types of errors occur when compiling and running a program: –Syntax Errors –Runtime Errors
  • 18. Syntax Errors •Common errors in typing or in the use of some keywords •More complex syntax errors occur when certain java object-oriented principles are violated •When the java compiler detects these errors, it displays error messages after the javac command
  • 19. Runtime Errors •Also called logic errors, these errors occur during runtime and may or may not cause the program to stop •Some errors that do not cause the program to stop are: • Infinite loops • Programs that display wrong outputs
  • 20. Java Program Statements –Inside the main ( ) method are statements that make up the body of the program. When the program is run these are executed by the Java Runtime Environment. –Java program statements are terminated by a semi- colon.
  • 21. •A block is composed of several statements. A pair of curly braces { } defines the scope of a block. •The body of classes and methods are always defined inside a block. This block defines the start and end points of the class or method. •Blocks can also be nested.
  • 22. Comments Programming statements that do not get compiled and are not executed by the interpreter They are written for documentation purposes •3 types of comments –Single line comments –Multi-line comments –Special javadoc comments
  • 23. Single line (or C++ style) comments start with //. All text after // are treated as comments Example: // This is an example of a single line comment
  • 24. Multi-line (or C-style) comments Are delimited by /* and */. All text between the two delimiters are treated as comments. The comments can span multiple lines. Example: /* This is an example of a comment spanning multiple lines */
  • 25. Special Javadoc comments •Are used for generating an HTML documentation for your java programs. •It contains tags to add more information to your comments. It can also span several lines. •Example: /** This is an example of a javadoc comments n for generating an html documentation @author Claudio Sanchez @version 1.3 */