ISYS 303 - Ch. 1-4 Flashcards
The “if” statement
if (condition) { statement(s); } else if(condition) { statement(s); } else { statement(s); } ***condition is a Boolean expression (the statement is either true or false) The if statement only takes ONE statement after the if. That is why we use the curly braces. Then, the curly braces represent ONE statement but they can contain many statements
The “for” loop
for (initialization; condition; iteration)
{
statement;
}
**initialization - sets a loop control variable to an initial value
**condition - is a Boolean expression that tests the loop control variable. If the outcome of that test is true, the for loop continues to iterate, but if it is false the loop terminates
***iterate - determines how the loop control variable is changed each time the loop iterates
The for loop consists of 3 parts and each is separated by a semi colon: initializing of the variable, the condition, and the update to the variable
code block
- another key element of Java
- it’s a group of two or more statements, it is done by enclosing the statements between opening and closing curly braces
- the statements become a logical unit that can be used at any place that a single statement can, one statement cannot execute without the other also executing
- The curly braces { } are used to create blocks of code. They are often used in if, for, while, and other java statements when you want more than one line to be connection to the if, while, for, etc.
semicolon
- is a separator that is used to terminate a statement, each individual statement must be ended with a semicolon, it indicates the end of one logical entity
- a code block IS NOT terminated by a semicolon, the end of the block is indicated by the closing brace
- java does not recognize the end of the line as a terminator, does not matter where on a line you put a semicolon
What is bytecode? Why is it important to Java’s use for Internet programming?
Bytecode is a highly optimized set of instructions that is executed by the Java run-time system, which is called the Java Virtual Machine (JVM). Bytecode helps Java achieve both portability and security.
Java source code (the java statements) are compiled into Java Bytecode (set of highly optimized instructions) which is executed by the Java Virtual machine (JVM). Using bytecode makes the programs more portable and flexible since the JVM can be implemented for those environments.
***NOT EXECUTABLE CODE
What are the three main principles of object-orientated programming?
- Encapsulation
- Polymorphism
- Inheritance
What is a variable?
-a named memory location
-the contents of a variable can be changed during the execution of a program
A variable is a holding spot (or a “pocket”) where you can tell the computer to set up a place in memory to hold a value for later use
Unlike VBA, Java requires you to tell the system what type of variable you will want to use
***CANNOT START WITH A NUMBER
Scanner Class
Scanner iScan = new Scanner(System.in) then you create another variable to hold iScan: iNumInput = iScan.nextInt() ***.nextInt can be anything from nextDouble, nextFloat, nextLine, and so on ***make sure to initialize the variable holding the scanner variable
Random Class
Random iRndNum = new Random(); then you create another variable to hold iRndNum: iGameScore = iRndNum.
Import
BEFORE setting up any type standard class, make sure use: import java.util.* after “package” to be able to use any standard class like Scanner or Random
What is JVM?
Java Virtual Machine - designed as an interpreter for bytecode, only JVM needs to be implemented for each platform (although different on platforms all JVMs can understand the same bytecode)
-helps make it secure because JVM is in control, it can contain the program and prevent it from generating side effects outside of the system
Java programs are executed within a java environment making them more secure. If something goes wrong (i.e. virus, etc.) then the entire system will NOT be affected. The java execution environment can confine the program to the environment and not allow access to other parts of the computer
Java Buzzwords - Simple
Simple – Java has a concise, cohesive set of features that makes it easy to learn and use
Java Buzzwords - Secure
Secure – Java provides a secure means of crediting Internet applications
Java Buzzwords - Portable
Portable – Java programs can execute in any environment for which there is a Java run-time
system
Java Buzzwords - Object Oriented (OOP)
Object-orientated – Java embodies the modern, object orientated programming philosophy
OOP are organized around the data, with the key priniciple being "data controlling access to code." You define the data and the routines that are permitted to act on that data In an object oriented world, a class is a template or mold that determines what an object will look like and how it will performance through the use of attributes (they describe the object), methods (they do the work), and events (they respond to other objects)
Java Buzzwords - Robust
Robust – Java encourages error-free programming by being strictly typed and performing run-time checks
Java Buzzwords - Multithreaded
Multithreaded – Java provides integrated support for multithreaded programming
Java Buzzwords - Architecture-neutral
Architecture-neutral – Java is not tied to a specific machine or operating system architecture
Java Buzzwords - Interpreted
Interpreted – Java supports cross-platform code through the use of Java bytecode
Java Buzzwords - High performance
High performance – The Java bytecode is highly optimized for speed of execution
Java Buzzwords - Distributed
Distributed – Java was designed with the distributed environment of the Internet in mind
Java Buzzwords - Dynamic
Dynamic – Java programs carry with them substantial amounts of run-time type information that is used to verify and resolve accesses to objects at run time
Java Buzzwords
We like java because it is simple, secure, portable, object oriented, multithreaded, has high performance due to the bytecode, and more
Encapsulation
-programming mechanism that binds together code and the data it manipulates, and keeps it both safe from the outside interference and misuse
Encapsulation (or black box) hides the details from the world to make life easier. We don’t care how it works, we just want it to work
Code & data are found in the box, when code & data are linked together in this way, an object is created. An object is the device that supports encapsulation.
Private vs. Public
Within an object, code, data, or both may be private to that object or public.
The keyword public means something is visible to everyone and everything within the java program, other parts of your program can access it even thought it is defined within an object
Private code - known to and accessible by another part of the object. It cannot be accessed by a piece of program that exists outside the object
Polymorphism
-is the quality that allows one interface to access a general class of actions. "one interface, multiple methods" Helps reduce complexity by allowing the same interface to be used to specify a general class of actions
Polymorphism allows one interface (method) to be executed in many different ways depending on how you want to use it. For example, you can print a word doc, excel spreadsheet, jpg image, etc just by calling the print method. You only need to remember the one method and the system determines how the method will work
Inheritance
process by which one object can acquire the properties of another object. Using inheritance, an object need only define those qualities that make it unique within its class and can inherit its general attributes from its parent.
is when one object (child) is based upon another object (parent). The child object can get everything (attributes, methods, etc.) that the parent wants to pass down to the child class (subclass).
Javac
Javac is a special keyword that can be used at the command.com prompt (windows) to compile java source code (a file with the extension of .java and contains java statements) The result of compiling the java source code file is another file with the same name as the source code file but with an extension of .class You can run the results of the compilation (the .class file) through the use of the java key word at the command prompt
System.out.println vs. System.out.print
System.out.println is a method that prints something to the screen and then does a carriage return (drops to the next line and positions the cursos at the beginning of the line)
System.out.print is a method that prints something to the screen but does NOT do a carriage return. The cursor stays on the same line waiting to do something. If you print again it will pick up from the same spot where it left off.