Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 1 - Java Program Design and Development Monday, May 9, 2022 - 8:36 PM When talking about designing an object - really just talking about designing the objects c Class: defines the collection of objects that belong to it, the class can be considered the To figure out what should be split into different objects look for nouns Choosing behaviour of an object is a matter of looking for verbs Class Name: Riddle Role: to store and retrieve a question and answer Attributes: question - a variable to store a riddle's question (private); answer: a variable to store a riddle's answer (private) Behaviours: Riddle(): a method to set a riddle's question and answer getQuestion(): a method to return a riddle's question getAnswer(): a method to return a riddle's answer Public vs Private: - Mostly attributes (variables) are private (-) - Operations (methods) are public (+) Class Names: - Begin with capital letter and use capitals for all new words Ex HelloWorld Variable and Method Names: - Begin with lowercase letter but also use capitals for new words Ex getQuestion Statements: A variable’s type is either one of the primitive types we mentioned, such as int, double, or boolean, or f name of the object’s class, such as String or HelloWorld. - Declaring a variable will tell the program to set aside enough memory for whatever type of variab Declaration Variable: Type VariableName ; HelloWorld helloWorld; Assignment Variable: VariableName = Value ; Declaration Variable: Type VariableName ; HelloWorld helloWorld; Assignment Variable: VariableName = Value ; Expressions and Operators: +, -, < > are operators; these operators have a type that depends on the type being manipulated; int + int will produce int int > int will produce boolean Be careful not to confuse = and ==. The symbol = is the assignment operator. It assigns the value on its right-hand side to the variable on its left-hand side. The symbol == is the equality operator. It evaluates whether the expressions on its left- and right-hand sides have the same value and returns either true or false. Declaring Instance Variable: private String greeting = ”Hello , World!”; In general, an instance variable declaration has the following syntax, some parts of which are optional: Modifiersopt Type VariableName InitializerExpressionopt Defining an Instance Method: In general, a method header takes the following form, including some parts which are optional: Modifiersopt ReturnType MethodName ( ParameterListopt ) Java.lang package - common package that does not need to be referred to before using one of it's classes. String and Object are in the java.lang class but you can just do String xxx or Object xxx you do not have to do java.lang.String Import package.* } allows every package be used by their abbreviated names. Primitive Types vs Reference Types: Reference types - holds the ADDRESS for the variable in memory Primitive types - holds the value of the variable in memory