Beruflich Dokumente
Kultur Dokumente
What is Java
Developed in the early 1990s by Sun Meant to be highly portable so it could be embedded into microwave ovens, cell phones, remote controls, etc Java was written with the C language Has similar syntax to C, C++, and JavaScript (JavaScript is totally different than Java)
Java can be run on any platform or any processor that has a JVM built for it. Java is an interpreted language, meaning that there is a machine/processor-dependent interpreter called the JVM that translates the standard Java code into instructions for the specific processor
Java Architecture
Platform Independence
In C++, only the source code is platform independent; the compiler and executable are platform-dependent Microsoft.NET products are Platform Dependent but Language Independent to a degree
In addition to converting your common bytecode to machine-dependent instructions, the JVM provides memory cleanup known as garbage collection The JVM will clean up after a program once components are no longer needed (i.e. you dont need stuff like set x = nothing).
Java includes many reusable tools and objects that are part of the language Additional open-source tools and classes can be found on the web that have been built by the open source community and can be reused in your applications
Java is object-oriented
Concept Description Class Method Job Description Task Example Instructor doLecture()
Java Application
Standalone; run from command line Runs in a web browser Downloaded from server and run client-side Resides and runs on web server
2.
Java Applet
3.
Java Servlet
System Development
Always plan before you code. Understand the problem and plan a solution. Always test. Test driven development encourages writing tests first and creating automated build scripts that run the tests Dont wait until the last minute! Count on building a program over several days. Assume you will be rethinking and refactoring as you go; just like writing a novel
Phases of the Software Development Life Cycle Needs Analysis: The Why Requirements Analysis: The What
Define the problem
Define the solution in terms of business requirements Consideration of Who and Where High Level and Detailed Design Flow charts, psuedocode
Construction of the Software and unit testing Unit Testing (Unit, Integration)
Programming in Java
Question: what are the inputs and outputs of the main method?
Standards
Java ignores whitespace, so you can use as much or as little as you want, but please maintain readibility!! Bracket positioning (two standards, use either)
Java includes 8 primitive (non-object) data types. They begin with a lower-case
boolean
byte char short
int
long float double
Java class that has many built-in methods for replace, find, case, etc Concatenate strings with the + operator
String instructorName = Mr. Dobda; System.out.println(Your instructor is + instructorName);
Note that System.out.println allows you to write a line of text to the output console
\n
\\
value = Are you sure\n you want to do this? Value = Go to c:\\My Documents
System.out.println(You go to + MyClass.SCHOOL_LOCATION);
Naming conventions
Class: Descriptive noun or noun phrases. Starts with caps and uses caps for each word Method: start with lower case, use caps for each subsequent word Variable: same as methods. Be descriptive! Use single letter variable names only for loop indexes Final variable: CAPS_WITH_UNDERSCORE
Java Operators
Casting Variables
You can cast variables from one type to another when direct assignment is not an option: float f = (float)9.8765
Java considers everything with a decimal to be a double. Since float takes up less memory and holds up to 7 decimal places, you can cast 9.8765 as a float. There are better real-world examples out there than this, especially when you get into objects
These provide a quick way to add or subtract 1 from a variable i++ or ++i will add 1 to i i-- or --i will subtract 1 from i When assigning values, there is a difference between i++ and ++i (see table 2.12 p70)
Accumulation Operators
Operator Example += sum += x Result sum = sum + x
-= *= /=
Note that you dont NEED to use accumulation operators, but they are a nice shorthand.