Download CS 110 -- Introduction to Computer Science JAVA Programming Basics Header Comment

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CS 110 -- Introduction to Computer Science
JAVA Programming Basics
Form of a JAVA Program
Header Comment
Import statements
Class definition
{
Main Method declaration
{
Scanner definition
Declare statements
Programming Statements
}
}
Import statement Æ brings in JAVA library elements
Class definition Æ
class name must match the filename
filename must be .java
class name follows identifier rules
except it starts with upper case (style convention)
Declare statements Æ form: datatype identifierName;
Defines variables which name memory locations used to store
information
Identifier names start with lower case,
use uppercase at word change (style convention)
meaningful names
Constant declaration: final datatype identifiername = value;
User defined constants: all upper case (style convention)
Assignment Statements Æ variable = expression;
Operator precedence rules
()
* / %
+ Operators of equal precedence are evaluated left to right
Output Æ System.out or System.err
print (expression)
println(expression)
flush()
Input Æ System.in
Requires a Scanner object is declared and associated with System.in
String Æ next()
delimeter blank
String Æ nextLine();
delimeter is carriage return
Integer Æ nextInt()
Float Æ nextFloat()
Double Æ nextDouble();
Char Æ next().charAt(0);
Related documents