SlideShare a Scribd company logo
1 of 11
Download to read offline
1
9/10/2003 Statements 1
Basic Java Syntax
• The java language will be described by
working through its features:
– Variable types and expressions.
– Selection and iteration.
– Classes.
– Exceptions.
• Small sample programs will be provided to
illustrate how each feature is used.
9/10/2003 Statements 2
Program Structure
• A program in java consists of one or more
class definitions. One of these classes must
define a method main(), which is where the
program starts running
// A Java Hello World Program
public class HelloWorld {
public static void main( String args[] ) {
System.out.println( "Hello World" );
}
}
2
9/10/2003 Statements 3
Comments
• Comments come in three forms:
// single line comments
/* multi
line
comment
*/
/** a
* Javadoc
* comment
*/
9/10/2003 Statements 4
Javadoc
• A tool that comes with the JDK that
produces html-based documentation from
java source code.
• Within a Javadoc comment, various tags
can appear which allow additional
information to be processed.
• Each tag is marked by an @ symbol and
should start on a new line.
3
9/10/2003 Statements 5
Javadoc Tags
Tag Description
@author Name the author(s) of the code:
@author Paul Tymann
@author Paul Tymann, Jim Gosling
@deprecated Indicates that the following method will be removed in future versions
@exception Information on exceptions thrown by a method
@param Provide information about method and constructor parameters. The tag is followed by a
parameter name and a comment
@param count number of elements
@return Return value for non-void methods
@see Provide cross reference to another class, interface, method, variable or URL.
@see java.lang.Integer
@since When a particular feature was included (i.e. since when it has been available)
@since JDK 1.0
@version Version information about the current revision of the code being documentated
9/10/2003 Statements 6
Example
/**
* A class that manages a circle given the radius
* @see java.lang.Math
* @version 1.0
* @author Paul Tymann
*/
public class Circle {
private double radius;
/**
* Constructor for a circle.
*
* @param radius radius of the circle being created. Must be
* positive and greater than 0.
*
*/
public Circle( double radius ) {
this.radius = radius;
}
}
4
9/10/2003 Statements 7
The Result
• The result is a set of HTML pages.
• The documentation that is produced is meant to be
part of the overall documentation that comes with
the JDK.
• The 1.1 version of Javadoc did not support local
modifications to the java documentation well.
• A much improved version of Javadoc is provided
with java2.
9/10/2003 Statements 8
Statement
• The statement is the main building block
from which code sequences are constructed.
• Statements are executed in the order listed
and are always terminated by a semicolon.
expr;
or
{ expr1; expr2; … exprn; }
5
9/10/2003 Statements 9
The if Statement
• Syntax:
• Note you can layout code in any way you want.
if ( booleanExpression ) statement
or
if ( booleanExpression )
statement
else
statement
9/10/2003 Statements 10
The switch statement
• Syntax:
• As in C, break statements are needed to
jump out of a switch statement.
• The default case is optional.
switch ( expression ) {
case char/byte/short/int constant : statementSequence
…
default: statementSequence
6
9/10/2003 Statements 11
Example
int z;
switch ( i ) {
case 1:
z = 1;
break;
case 2:
z = 2;
case 3:
z = 3;
break;
default:
z = 0;
}
9/10/2003 Statements 12
The while Loop
• Syntax:
while ( booleanExpression )
statement
7
9/10/2003 Statements 13
The do Loop
• Syntax:
do
statement
while ( booleanExpression );
9/10/2003 Statements 14
The for Loop
• Syntax:
• Each of the expressions is optional, the
semicolons are not.
• A for loop is basically a while loop with
initialization and updating thrown in.
for ( initExpr; booleanExpr; updateExpr )
statement
8
9/10/2003 Statements 15
Transfer Statements
• The break statement can occur anywhere within
a switch, for, while or do statement and
causes execution to jump to the next statement.
• The continue statement can occur anywhere
within a for, while or do statement and causes
execution to jump to the end of the loop body.
• The return statement causes the execution of
the current method, with control returning to the
caller.
9/10/2003 Statements 16
Objects
• An object is a structure that represents a state and
knows methods to manipulate it. The structure
components are called instance variables.
• Given a class, one normally creates objects.
• Objects are created dynamically with operator new
which in turn calls a constructor method to
initialize the instance variables.
• Methods mostly access the instance variables of
the receiver.
9
9/10/2003 Statements 17
Java Classes
• The Java system comes with an extensive
set of classes from which you may create
objects.
• Lets start with a familiar class String.
• To find out what you can do to java strings
you need to refer to the documentation that
comes with the JDK.
9/10/2003 Statements 18
Name.java
// A simple program that exercises some basic methods
// in the String class. Note: Strings are constant.
public class Name {
public static void main( String args[] ) {
String name;
int midLoc;
name = "Paul";
name = name.concat( " Tymann" );
midLoc = name.indexOf( " " );
name = name.substring( 0, midLoc ) + " Thomas" +
name.substring( midLoc );
System.out.println( name );
for (int i=0; i<name.length() && name.charAt(i) != ' '; i++ )
System.out.println( name.charAt(i) );
}
}
10
9/10/2003 Statements 19
Reverse.java
// This program reverses a given string
public class Reverse {
public static void main( String args[] ) {
String orig = "Hello World";
String reverse = "";
for (int i=0; i<orig.length(); i++)
reverse = orig.charAt( i ) + reverse;
System.out.println( reverse );
}
}
9/10/2003 Statements 20
StringBuffer
• The String class provides string objects
that cannot be changed.
• The StringBuffer class provides
mutable string objects.
11
9/10/2003 Statements 21
Reverse2
// Another way to reverse a string
public class Reverse2 {
public static void main( String args[] ) {
StringBuffer rev = new StringBuffer ( “Hello World” );
char tmp;
for (int i=0,j=rev.length()-1; i<j; i++,j-- ) {
tmp = rev.charAt( i );
rev.setCharAt(i, rev.charAt(j) );
rev.setCharAt(j, tmp );
}
System.out.println( rev );
}
}
9/10/2003 Statements 22
Palin
// This program checks a given string to see if it is a palindrome
public class Palin {
public static void main( String args[] ) {
String orig = "mom”, reverse = "";
// Reverse it
for (int i=0; i<orig.length(); i++)
reverse = orig.charAt( i ) + reverse;
// Now check it ( note that orig == reverse does not work )
if (orig.equalsIgnoreCase(reverse))
System.out.println( "Palindrome" );
else
System.out.println( "Not a palindrome" );
}
}

More Related Content

What's hot (19)

Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Migrating to JUnit 5
Migrating to JUnit 5Migrating to JUnit 5
Migrating to JUnit 5
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Java constructors
Java constructorsJava constructors
Java constructors
 
C++
C++C++
C++
 
2. 엔티티 매핑(entity mapping) 2 3 롬복(lombok)소개-2
2. 엔티티 매핑(entity mapping) 2 3 롬복(lombok)소개-22. 엔티티 매핑(entity mapping) 2 3 롬복(lombok)소개-2
2. 엔티티 매핑(entity mapping) 2 3 롬복(lombok)소개-2
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to Java
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
Commenting in Agile Development
Commenting in Agile DevelopmentCommenting in Agile Development
Commenting in Agile Development
 
Elements of Java Language - Continued
Elements of Java Language - Continued Elements of Java Language - Continued
Elements of Java Language - Continued
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Sedna XML Database System: Internal Representation
Sedna XML Database System: Internal RepresentationSedna XML Database System: Internal Representation
Sedna XML Database System: Internal Representation
 

Viewers also liked

Final Presentation JParker9
Final Presentation JParker9 Final Presentation JParker9
Final Presentation JParker9 jparker09
 
Pica para el aborto legal
Pica para el aborto legalPica para el aborto legal
Pica para el aborto legalIADERE
 
Tcc versao-final-paloma-jacinto-da-silva-polo-orós-sem.-vii (1)
Tcc versao-final-paloma-jacinto-da-silva-polo-orós-sem.-vii (1)Tcc versao-final-paloma-jacinto-da-silva-polo-orós-sem.-vii (1)
Tcc versao-final-paloma-jacinto-da-silva-polo-orós-sem.-vii (1)Samuel Icasa
 
Desregulación financiera y endeudamiento
Desregulación financiera y endeudamientoDesregulación financiera y endeudamiento
Desregulación financiera y endeudamientoIADERE
 
Ritma Teknoloji Yazılım Firması Sunum
Ritma Teknoloji Yazılım Firması Sunum Ritma Teknoloji Yazılım Firması Sunum
Ritma Teknoloji Yazılım Firması Sunum Ritma Teknoloji
 
Resumen ejecutivo: el impacto asimétrico de la aceleración inflacionaria en A...
Resumen ejecutivo: el impacto asimétrico de la aceleración inflacionaria en A...Resumen ejecutivo: el impacto asimétrico de la aceleración inflacionaria en A...
Resumen ejecutivo: el impacto asimétrico de la aceleración inflacionaria en A...IADERE
 
Continuidades y rupturas entre el régimen neoliberal de 1976-2001 y la poscon...
Continuidades y rupturas entre el régimen neoliberal de 1976-2001 y la poscon...Continuidades y rupturas entre el régimen neoliberal de 1976-2001 y la poscon...
Continuidades y rupturas entre el régimen neoliberal de 1976-2001 y la poscon...IADERE
 
Empleo Público y Desarrollo Tecnológico
Empleo Público y Desarrollo TecnológicoEmpleo Público y Desarrollo Tecnológico
Empleo Público y Desarrollo TecnológicoIADERE
 
AUTOCONVOCATORIA DEL CONGRESO: SE PUEDE Y SE DEBE
AUTOCONVOCATORIA DEL CONGRESO: SE PUEDE Y SE DEBEAUTOCONVOCATORIA DEL CONGRESO: SE PUEDE Y SE DEBE
AUTOCONVOCATORIA DEL CONGRESO: SE PUEDE Y SE DEBEIADERE
 
Wicker park Project n
Wicker park Project nWicker park Project n
Wicker park Project njparker09
 
KK Wind Solutions presentation on Control System Retrofit
KK Wind Solutions presentation on Control System RetrofitKK Wind Solutions presentation on Control System Retrofit
KK Wind Solutions presentation on Control System RetrofitRené Balle
 
Hidraulica de humberto villegas gardea
Hidraulica de  humberto villegas gardeaHidraulica de  humberto villegas gardea
Hidraulica de humberto villegas gardeaSemfac De Los Santos
 
FlySpaces Pitchdeck AUG2016
FlySpaces Pitchdeck AUG2016FlySpaces Pitchdeck AUG2016
FlySpaces Pitchdeck AUG2016Nicole Adarme
 
Coworking in Southeast Asia 2016
Coworking in Southeast Asia 2016Coworking in Southeast Asia 2016
Coworking in Southeast Asia 2016Nicole Adarme
 

Viewers also liked (17)

Final Presentation JParker9
Final Presentation JParker9 Final Presentation JParker9
Final Presentation JParker9
 
Pica para el aborto legal
Pica para el aborto legalPica para el aborto legal
Pica para el aborto legal
 
Tcc versao-final-paloma-jacinto-da-silva-polo-orós-sem.-vii (1)
Tcc versao-final-paloma-jacinto-da-silva-polo-orós-sem.-vii (1)Tcc versao-final-paloma-jacinto-da-silva-polo-orós-sem.-vii (1)
Tcc versao-final-paloma-jacinto-da-silva-polo-orós-sem.-vii (1)
 
Graphic Designer
Graphic DesignerGraphic Designer
Graphic Designer
 
Desregulación financiera y endeudamiento
Desregulación financiera y endeudamientoDesregulación financiera y endeudamiento
Desregulación financiera y endeudamiento
 
Ritma Teknoloji Yazılım Firması Sunum
Ritma Teknoloji Yazılım Firması Sunum Ritma Teknoloji Yazılım Firması Sunum
Ritma Teknoloji Yazılım Firması Sunum
 
Resumen ejecutivo: el impacto asimétrico de la aceleración inflacionaria en A...
Resumen ejecutivo: el impacto asimétrico de la aceleración inflacionaria en A...Resumen ejecutivo: el impacto asimétrico de la aceleración inflacionaria en A...
Resumen ejecutivo: el impacto asimétrico de la aceleración inflacionaria en A...
 
Continuidades y rupturas entre el régimen neoliberal de 1976-2001 y la poscon...
Continuidades y rupturas entre el régimen neoliberal de 1976-2001 y la poscon...Continuidades y rupturas entre el régimen neoliberal de 1976-2001 y la poscon...
Continuidades y rupturas entre el régimen neoliberal de 1976-2001 y la poscon...
 
Empleo Público y Desarrollo Tecnológico
Empleo Público y Desarrollo TecnológicoEmpleo Público y Desarrollo Tecnológico
Empleo Público y Desarrollo Tecnológico
 
Talent Bridges
Talent BridgesTalent Bridges
Talent Bridges
 
AUTOCONVOCATORIA DEL CONGRESO: SE PUEDE Y SE DEBE
AUTOCONVOCATORIA DEL CONGRESO: SE PUEDE Y SE DEBEAUTOCONVOCATORIA DEL CONGRESO: SE PUEDE Y SE DEBE
AUTOCONVOCATORIA DEL CONGRESO: SE PUEDE Y SE DEBE
 
Wicker park Project n
Wicker park Project nWicker park Project n
Wicker park Project n
 
KK Wind Solutions presentation on Control System Retrofit
KK Wind Solutions presentation on Control System RetrofitKK Wind Solutions presentation on Control System Retrofit
KK Wind Solutions presentation on Control System Retrofit
 
Hidraulica de humberto villegas gardea
Hidraulica de  humberto villegas gardeaHidraulica de  humberto villegas gardea
Hidraulica de humberto villegas gardea
 
Fitur xibo
Fitur xiboFitur xibo
Fitur xibo
 
FlySpaces Pitchdeck AUG2016
FlySpaces Pitchdeck AUG2016FlySpaces Pitchdeck AUG2016
FlySpaces Pitchdeck AUG2016
 
Coworking in Southeast Asia 2016
Coworking in Southeast Asia 2016Coworking in Southeast Asia 2016
Coworking in Southeast Asia 2016
 

Similar to java Statements

Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongVu Huy
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongGrokking VN
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into JavaTom Johnson
 
Unit of competency
Unit of competencyUnit of competency
Unit of competencyloidasacueza
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT studentsPartnered Health
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Christos Manios
 
Basics of Java Concurrency
Basics of Java ConcurrencyBasics of Java Concurrency
Basics of Java Concurrencykshanth2101
 
Java design patterns
Java design patternsJava design patterns
Java design patternsShawn Brito
 
Lecture 5 interface.pdf
Lecture  5 interface.pdfLecture  5 interface.pdf
Lecture 5 interface.pdfAdilAijaz3
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for MainframersRich Helton
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7Deniz Oguz
 
More topics on Java
More topics on JavaMore topics on Java
More topics on JavaAhmed Misbah
 

Similar to java Statements (20)

Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen Luong
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into Java
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
#_ varible function
#_ varible function #_ varible function
#_ varible function
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...
 
Spring
SpringSpring
Spring
 
Basics of Java Concurrency
Basics of Java ConcurrencyBasics of Java Concurrency
Basics of Java Concurrency
 
Java design patterns
Java design patternsJava design patterns
Java design patterns
 
C++primer
C++primerC++primer
C++primer
 
Lecture 5 interface.pdf
Lecture  5 interface.pdfLecture  5 interface.pdf
Lecture 5 interface.pdf
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Java
JavaJava
Java
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
 
Java Basics
Java BasicsJava Basics
Java Basics
 
More topics on Java
More topics on JavaMore topics on Java
More topics on Java
 
Design patterns
Design patternsDesign patterns
Design patterns
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 

Recently uploaded (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 

java Statements

  • 1. 1 9/10/2003 Statements 1 Basic Java Syntax • The java language will be described by working through its features: – Variable types and expressions. – Selection and iteration. – Classes. – Exceptions. • Small sample programs will be provided to illustrate how each feature is used. 9/10/2003 Statements 2 Program Structure • A program in java consists of one or more class definitions. One of these classes must define a method main(), which is where the program starts running // A Java Hello World Program public class HelloWorld { public static void main( String args[] ) { System.out.println( "Hello World" ); } }
  • 2. 2 9/10/2003 Statements 3 Comments • Comments come in three forms: // single line comments /* multi line comment */ /** a * Javadoc * comment */ 9/10/2003 Statements 4 Javadoc • A tool that comes with the JDK that produces html-based documentation from java source code. • Within a Javadoc comment, various tags can appear which allow additional information to be processed. • Each tag is marked by an @ symbol and should start on a new line.
  • 3. 3 9/10/2003 Statements 5 Javadoc Tags Tag Description @author Name the author(s) of the code: @author Paul Tymann @author Paul Tymann, Jim Gosling @deprecated Indicates that the following method will be removed in future versions @exception Information on exceptions thrown by a method @param Provide information about method and constructor parameters. The tag is followed by a parameter name and a comment @param count number of elements @return Return value for non-void methods @see Provide cross reference to another class, interface, method, variable or URL. @see java.lang.Integer @since When a particular feature was included (i.e. since when it has been available) @since JDK 1.0 @version Version information about the current revision of the code being documentated 9/10/2003 Statements 6 Example /** * A class that manages a circle given the radius * @see java.lang.Math * @version 1.0 * @author Paul Tymann */ public class Circle { private double radius; /** * Constructor for a circle. * * @param radius radius of the circle being created. Must be * positive and greater than 0. * */ public Circle( double radius ) { this.radius = radius; } }
  • 4. 4 9/10/2003 Statements 7 The Result • The result is a set of HTML pages. • The documentation that is produced is meant to be part of the overall documentation that comes with the JDK. • The 1.1 version of Javadoc did not support local modifications to the java documentation well. • A much improved version of Javadoc is provided with java2. 9/10/2003 Statements 8 Statement • The statement is the main building block from which code sequences are constructed. • Statements are executed in the order listed and are always terminated by a semicolon. expr; or { expr1; expr2; … exprn; }
  • 5. 5 9/10/2003 Statements 9 The if Statement • Syntax: • Note you can layout code in any way you want. if ( booleanExpression ) statement or if ( booleanExpression ) statement else statement 9/10/2003 Statements 10 The switch statement • Syntax: • As in C, break statements are needed to jump out of a switch statement. • The default case is optional. switch ( expression ) { case char/byte/short/int constant : statementSequence … default: statementSequence
  • 6. 6 9/10/2003 Statements 11 Example int z; switch ( i ) { case 1: z = 1; break; case 2: z = 2; case 3: z = 3; break; default: z = 0; } 9/10/2003 Statements 12 The while Loop • Syntax: while ( booleanExpression ) statement
  • 7. 7 9/10/2003 Statements 13 The do Loop • Syntax: do statement while ( booleanExpression ); 9/10/2003 Statements 14 The for Loop • Syntax: • Each of the expressions is optional, the semicolons are not. • A for loop is basically a while loop with initialization and updating thrown in. for ( initExpr; booleanExpr; updateExpr ) statement
  • 8. 8 9/10/2003 Statements 15 Transfer Statements • The break statement can occur anywhere within a switch, for, while or do statement and causes execution to jump to the next statement. • The continue statement can occur anywhere within a for, while or do statement and causes execution to jump to the end of the loop body. • The return statement causes the execution of the current method, with control returning to the caller. 9/10/2003 Statements 16 Objects • An object is a structure that represents a state and knows methods to manipulate it. The structure components are called instance variables. • Given a class, one normally creates objects. • Objects are created dynamically with operator new which in turn calls a constructor method to initialize the instance variables. • Methods mostly access the instance variables of the receiver.
  • 9. 9 9/10/2003 Statements 17 Java Classes • The Java system comes with an extensive set of classes from which you may create objects. • Lets start with a familiar class String. • To find out what you can do to java strings you need to refer to the documentation that comes with the JDK. 9/10/2003 Statements 18 Name.java // A simple program that exercises some basic methods // in the String class. Note: Strings are constant. public class Name { public static void main( String args[] ) { String name; int midLoc; name = "Paul"; name = name.concat( " Tymann" ); midLoc = name.indexOf( " " ); name = name.substring( 0, midLoc ) + " Thomas" + name.substring( midLoc ); System.out.println( name ); for (int i=0; i<name.length() && name.charAt(i) != ' '; i++ ) System.out.println( name.charAt(i) ); } }
  • 10. 10 9/10/2003 Statements 19 Reverse.java // This program reverses a given string public class Reverse { public static void main( String args[] ) { String orig = "Hello World"; String reverse = ""; for (int i=0; i<orig.length(); i++) reverse = orig.charAt( i ) + reverse; System.out.println( reverse ); } } 9/10/2003 Statements 20 StringBuffer • The String class provides string objects that cannot be changed. • The StringBuffer class provides mutable string objects.
  • 11. 11 9/10/2003 Statements 21 Reverse2 // Another way to reverse a string public class Reverse2 { public static void main( String args[] ) { StringBuffer rev = new StringBuffer ( “Hello World” ); char tmp; for (int i=0,j=rev.length()-1; i<j; i++,j-- ) { tmp = rev.charAt( i ); rev.setCharAt(i, rev.charAt(j) ); rev.setCharAt(j, tmp ); } System.out.println( rev ); } } 9/10/2003 Statements 22 Palin // This program checks a given string to see if it is a palindrome public class Palin { public static void main( String args[] ) { String orig = "mom”, reverse = ""; // Reverse it for (int i=0; i<orig.length(); i++) reverse = orig.charAt( i ) + reverse; // Now check it ( note that orig == reverse does not work ) if (orig.equalsIgnoreCase(reverse)) System.out.println( "Palindrome" ); else System.out.println( "Not a palindrome" ); } }