Chp 2 Flashcards
A JAVA APPLICATION
Executes when you use teh java command to launch JVM
A COMMENT LINE BEGINS WITH…
//
Which is an end-of-line comment
*It terminates at the end of the line on which it appears
** JAVA WILL NOT READ THESE COMMENTS
Example:
// empty statement
TRADITIONAL COMMENTS
PG. 39
CAN SPREAD OVER SEVERAL LINES AND ARE DELIMITED BY /* AND */
THESE COMMENTS ARE NOT READ BY JAVA EITHER
JAVADOC
COMMENTS
PG. 39
DELIMITED BY /** AND */
ENABLE YOU TO EMBED PROGRAM DOCUMENTATION IN YOUR CODE.
GENTERATES HTML PAGES BASED ON THESE COMMENTS
COMPILER INGNORES ALL TEXT BETWEEN DELIMITERS
SYNTAX ERROR
PG. 39
AKA COMPILER ERROR, COMPILE TIME ERROR, COMPILATION ERROR
OCCURS WHEN THE COMPILER ENCOUNTERS CODE THAT VIOLATES JAVA’S LANGUAGE RULES
SIMILAR TO A GRAMMER ERROR IN NATURAL LANGUAGE
THE COMPILER RESPONDS BY ISSUING AN ERROR AND PREVENTING YOUR PROGRAM FROM COMPILING
BLANK LINES
SPACE CHARACTERS
TAB CHARACTERS
PG. 39
KNOWN AS WHITE SPACE
WHITE SPACE MAKES PROGRAMS EAISER TO READ AND IS IGNORED BY THE COMPILER
** IN A PROGRAM IT WOULD JUST BE A SKIPPED LINE
KEYWORDS
PG. 40
RESERVED FOR USE BY JAVA AND ARE ALWAYS SPELLED WITH ALL LOWERCASE LETTERS
KEYWORD CLASS
PG 40
INTRODUCES A CLASS DECLARATION
EX:
public class Welcome1
- public class being the keyword class*
- Welcome1 being the class name*
CLASS NAMES
BY CONVENTION ALL CLASS NAMES IN JAVA BEGIN WITH A CAPITAL LETTER AND CAPITALIZE THE FIRST LETTER OF EACH WORD THEY INCLUDE
E.G.
SampleClassName
JAVA CLASS NAME
- SERIES OF CHARACTERS CONSISTING OF LETTERS, DIGITS, UNDERSCORES (_) AND DOLLAR SIGNS ($)
- DOES NOT BEGIN WITH A DIGIT AND DOES NOT CONTAIN SPACES
- JavaClassNameSample
IS JAVA CASE SENSITIVE?
- YES
- UPPER AND LOWERCASE LETTERS ARE DISTINCT
THE BODY OF EVERY CLASS DECLARATION
PG. 40
- IS DELIMITED BY BRACES
- { AND }
A PUBLIC CLASS DECLARATION MUST BE SAVED IN….
- A FILE WITH THE SAME NAME AS THE CLASS FOLLOWED BY THE “.java” FILE NAME EXTENSION
- E.G public class Welcome1, would be saved as Welcome1.java
METHOD MAIN
PG.41
- STARTING POINT OF EVERY JAVA APPLICATION
- MUST BEGIN WITH public static void main( String [] args)
- otherwise the JVM will not execute
Ex:
{
// main method begins execution of java application
public static main void main ( String [] args )
}
METHODS
PG.41
- PERFORM TASKS AND RETURN INFO WHEN THEY COMPLETE THEM
- KEYWORD void, INDICATES THAT A METHOD WILL PERFORM A TASK BUT RETURN NO INFORMATION
public static void main ( String [] args )
*The parentheses after the identtifirer main indicate that its’s a program building block called method.
STATEMENTS
- INSTRUCT THE COMPUTER TO PERFORM ACTIONS
A STRING
PG.41
- IN DOUBLE QUOTES
- CALLED A CHARACTER STRING OR STRING LITERAL
- CAN NOT SPAN MULTIPLE LINES OF CODE
EX:
System.out.println( ” Welcome to Java Programming!” )
STANDARD OUTPUT OBJECT
PG.41
- DISPLAYS CHARACTERS IN THE COMMAND WINDOW
- System.out
Method
System.out.println
- DISPLAYS THE ARGUMENT IN THE COMMAND WINDOW FOLLOWED BY A NEW LINE CHARACTER TO POSITION THE OUTPUT CURSOR TO THE BEGINING OF THE NEXT LINE
TO COMPILE A PROGRAM
- YOU COMPILE A PROGRAM WITH THE COMMAND javac.
- IF THE PROGRAM CONTAINS NO SYTAX ERRORS, A CLASS FILE CONTAINING JAVA BYTECODES THAT REPRESENT THE APPLICATION CREATED.
- THE BYTECODES ARE INTERPRETED BY THE JVM WHEN YOU EXECUTE THE PROGRAM
- Open Command Window
- Change directory where program is stored using command cd to change directory
- once directory is found type javac ClasName.java
TO RUN AN APPLICATION
- TYPE JAVAc
- FOLLOWED BY THE NAME OF THE CLASS THAT CONTAINS MAIN
System.out.print
not
System.out.println
pg.44
- DISPLAYS ITS ARGUMENT AND POSITIONS THE OUTPUT CURSOR IMMEDIATELY AFTER THE LAST CHARACTER DISPLAYED
- println vs print (println positions at the next line)
BACKLASH
( \ )
PG.45
- A BACKLASH IN A STRING IS AN ESCAPE CHARACTER
- JAVA COMBINES IT WITH THE NEXT CHARACTER TO FORM AN ESCAPE SEQUENCE
- THE ESCAPE SEQUENCE \n represents the newline character
Ex:
{
public static void main ( String [] args)
{
System.out.println ( "Welcome **\n** to **\n** Java **\n** Programing!" ); }
}
Will Display on seperate lines
Welcome to java progaming!