Creating Java Program Ch1
Polymorphism
-"many forms" -Allows the same word to be interpreted correctly in different situations based on context
Finding help: Java Development Kit (JDK)
-A software development kit (SDK) of programming tools -Free to download
Adding comments to a java class (Javadoc comments):
-A special case of block comments -Begin with a slash and two asterisks (/**) -End with an asterisk and a forward slash (*/) -Use to generate documentation
Finding help: Java API
-Also called the Java class library -Provides prewritten information about Java classes
Attributes
-Characteristics that define an object -Differentiate objects of the same class -The value of attributes is an object's state
Java interpreter
-Checks byte code and communicates with the operating system. -Executes byte code instructions line by line within the JVM
Compiling a Java class
-Compile the source code into bytecode -Translate the bytecode into executable statements (using a Java interpreter) -Type javac First.java
Object-oriented programming was used most frequently for two major types of applications:
-Computer simulations -GUI (graphical user interfaces) [not all object oriented programs are written to use a GUI]
Encapsulation
-Conceals internal values and methods from outside sources -provides security -keeps data and methods safe from inadvertent changes
Class
-Describes objects with common properties -A definition -An instance
Dont do it:
-Don't forget the file's name must match the class name -Don't confuse these terms: -Parentheses, braces, brackets, curly braces, square brackets, and angle brackets -Don't forget to end a block comment -Don't forget that Java is case sensitive -Don't forget to end every statement with a semicolon -Do not end class or method headers with a semicolon -Don't forgot to recompile when making changes -Don't panic when you see a lot of compiler error messages -Don't assume your program is perfect when all compiler errors are eliminated
Java app that produces GUI output
-JOptionPane: Produces dialog boxes -Dialog box: A GUI object resembling a window. Messages placed for display -import statement: Use to access a built-in Java class -Package: A group of classes
correcting logic errors
-Logic error: The syntax is correct but incorrect results were produced when executed -Run-time error: Not detected until execution. Often difficult to find and resolve
java class: reasons for error messages
-Misspelled the command javac -A misspelled filename -Not within the correct subfolder or subdirectory on the command line -Improper installation of Java
Modifying a compiled java class
-Modify the text file that contains the existing class -Save the file with changes using the same filename -Compile the class with the javac command -Interpret the class bytecode and execute the class using the java command
Adding Comments to a Java Class (Program comments):
-Nonexecuting statements added to a program for documentation -Use to leave notes for yourself or others -Include the author, date, and class's name or function
Object-oriented programming differs from traditional procedural programming because of....
-Polymorphism -inheritance -Encapsulation
Running a java application
-Run the application from the command line (Type java First) -Shows the application's output in the command window -The class is stored in a folder named Java on the C drive
Saving a Java class
-Save the class in a file with exactly the same name and .java extension -For public classes, class name and filename must match exactly
Program statements
-Similar to English sentences -Commands that carry out program tasks
Adding comments to a java class (block comments):
-Start with a forward slash and an asterisk (/*) -End with an asterisk and a forward slash (*/)
Adding comments to a java class (line comments):
-Start with two forward slashes (//) -Continue to the end of the current line -Do not require an ending symbol
Correcting syntax errors (compile time error)
-The compiler detects a violation of language rules -Refuses to translate the class to machine code
Correcting syntax errors (first line of error message):
-The name of the file where the error was found -The line number -The nature of the error
Correcting syntax errors (next lines identify):
-The symbol -The location
Adding Comments to a Java Class (Comment out):
-Turn it into a comment -The compiler does not translate, and the JVM does not execute its command
Indent style
-Use whitespace to organize code and improve readability -For every opening curly brace ( { ) in a Java program, there must be a corresponding closing curly brace ( } ) -Placement of the opening and closing curly braces is not important to the compiler -Allman style used in text
Literal string
-Will appear in output exactly as entered -Written between double quotation marks
Inheritance
-an important feature of object-oriented programs -helps you understand real-world objects -classes share attributes and methods of existing classes but with more specific features
Java
-developed by Sun Microsystems -object oriented language -general purpose
Compilation outcomes
-javac is an unrecognized command -Program language error messages -No messages indicating successful completion
windows applications examples;
-menus -toolbars -dialog boxes
syntax error
-misuse of language rules -misspelled programming language word
Java advantages:
-security features -architecturally neutral -can be run on a wide variety of computer -doesnt execute instructions on the computer directly -runs on hypothetical computer known as JVM (Java Virtual Machine)
logic errors
-semantic errors -incorrect or procedures -program may run but provide inaccurate output
Bytecode
-statements saved in a file -a binary program into which the java compiler converts source code
Correcting syntax errors (Parsing)
Compiler divides source code into meaningful portions
Access specifier
Defines how a class can be accessed
Upper Camel casing (Pascal casing)
Each word of an identifier begins with uppercase letter: -UnderGradStudent -InventoryItem
High-level programming language
Let's you use a vocabulary of reasonable terms
Machine Language
Low-level programming language
Finding help: FAQs
On the Java Web site
Procedural programming
Operations executed in sequence
Arguments
Pieces of information passed to a method
System class
Refers to the standard output device for a system
method
Requires information to perform its task
Syntax
Specific rules for the language
Objects
Specific, concrete instances of a class (examples of the class)
main( ) method
Static: -A reserved keyword -Means the method is accessible and usable even though no objects of the class exist Void: -Use in the main( ) method header -Does not indicate the main( ) method is empty -Indicates the main( ) method does not return a value when called -Does not mean that main( ) doesn't produce output
Compiler/Interpreter
Translates a language into machine code
WORA
Write once, run anywhere
Computer program
Written intrusions that tells the computer what to do.
Method
a self-contained block of program code that carries out an action...similar to a procedure
Debugging
freeing the program of all errors
procedures
individual operations grouped into logical units
variables
named computer memory locations that hold value
Source code
programming statements written in high level programming language
Develpomental environment
set of tools used to write programs
Console applications
support character output