1 / 25

Lecture 2

Lecture 2. Introduction to Java Programming. Java Class Format. public class userDefinedName { public static void main(String[] args){ } }. 2.2 Primitive Data Types. Lexical Elements. Keywords Literals Identifiers Operators Punctuation. Keywords.

cindy
Download Presentation

Lecture 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 2 Introduction to Java Programming

  2. Java Class Format public class userDefinedName {public static void main(String[] args){}}

  3. 2.2 Primitive Data Types

  4. Lexical Elements • Keywords • Literals • Identifiers • Operators • Punctuation

  5. Keywords abstract default if private this boolean do implements protected throw break double import public throws byte else instanceof return transient case extends int short try catch final interface static void char finally long strictfp volatile class float native super while const for new switch continue goto package synchronized • Can not be used for any other purpose • All lowercase letters

  6. Literal • A literal is the source code representation of a value of a primitive type or the String type Data typeLiteral Examplesint -4501 double 35.271d char ‘b’ boolean true String “Hello World”

  7. variable names class names constants Identifiers • An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. An identifier cannot have the same spelling as a keyword or boolean literal. Example identifierssumprodroot1isLeapYearQuadraticLeapYearMAX

  8. Operators

  9. Punctuation • The following nine ASCII characters are the separators (punctuators): ( ) { } [ ] ; , .

  10. White Space • White space is defined as the ASCII space, horizontal tab, and form feed characters, as well as line terminators

  11. Comments • There are two kinds of comments: • /* text */A traditional comment: all the text from the ASCII characters /* to the ASCII characters */ is ignored by the compiler • // textA end-of-line comment: all the text from the ASCII characters // to the end of the line is ignored by the compiler.

  12. All variables must be defined • Tell the compiler the • name of each variable • type of each variable int x;int y;boolean isLeapYear;boolean isPerflick;double root1;double root2; int x, y;boolean isLeapYear, isPerflick;double root1, root2;

  13. Initializing variables int x = 5;int y; //y need not be initialized y = 2*x + 1;…

More Related