Answers to review questions from Chapter 11.When you write a Java program, do you prepare a source file or a class file?A source file2.What characters are used to mark comments in a Java program?/*. . .*/3.What is the significance of each component in the package declarationpackageedu.stanford.cs.javacs2.ch1;eduindicates the educational domainstanfordindicates Stanford Universitycsindicates the Computer Science departmentjavacs1indicates that this package goes with the Java book for CS1ch1indicates that this package is associated with Chapter 14.How would you define a constant calledCENTIMETERS_PER_INCHwith the value 2.54?publicstaticfinaldoubleCENTIMETERS_PER_INCH=2.54;5.What is the name of the method that must be defined in every Java program?A public static void method namedmain6.What is meant by the termboilerplate?What is the boilerplate form of themainmethod usedthroughout this book?Boilerplaterefers to idiomatic programming patterns that are repeated in different programs buthave no real significance for the programmer. The boilerplate form of main ispublicstaticvoidmain(String[]args){newclassname().run();}7.Indicate which of the following are legal variable names in Java:a.xLegalb.formula1Legalc.average_rainfallLegald.%correctIllegal (begins with%)e.shortIllegal (reserved word)f.tinyLegalg.totaloutputIllegal (contains a space)h.aVeryLongVariableNameLegali.12MonthTotalIllegal (begins with a digit)j.marginal-costIllegal (contains a hyphen)k.b4handLegal (but perhaps too clever)l._stk_depthLegal8.What are the two attributes that define a data type?Types are defined by adomainand aset of operations.Preview Mode
This document has 65 pages. Sign in to access the full document!
