1/97
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Java
modern object-oriented programming language
features of Java
secure, robust, and portable
how is Java secure?
Enables the construction of virus-free, tamper-free systems
how is Java robust?
Supports the development of programs that do not overwrite memory
how is Java portable?
Yields programs that can be run on different types of computers without change
what are the features of Java that once made it the fastest-growing language of all time?
1) it's a modern object-oriented programming language. Java was inspired by combining the good features of C++ and Smalltalk and removing the less desirable features. 2) it's secure, robust, and portable. 3) Java supports the use of advanced programming concepts, ex. threads. 4) Java bears a superficial resemblance to C++, but it's easier to use & learn, less error-prone, and better suited to the internet.
thread
a process that can run concurrently with other processes, ex. in a simple Java application, one thread transfers an image from one machine to another across a network, while the other thread simultaneously interacts with the user
C++
the world's most popular industrial-strength programming language
why does Java run more slowly than most modern programming languages?
it is interpreted
interprative programming language
generally interpreted, without compiling a program into machine instructions. It is one where the instructions are not directly executed by the target machine, but instead, read and executed by some other program. (in Java it's the JVM)
what is a portable program?
a program that can be carried out (compiled/interpreted & executed) across multiple devices without reconstruction or hassle
Describe two features of Java that make it a better language than C++.
Java is easier to use & understand, and is better suited for the internet
What is a thread? Describe how threads might be used in a program.
a thread is a process in a program which acts concurrently with other processes. for ex. in a simple Java program, one thread transfers an image from one machine to another while another thread interacts with the user.
(Java) byte code
machine language for an imaginary Java computer, called pseudomachine language since it's not an actual machine language (language understandable to machines, ex. bits)
Java Virtual Machine (JVM)
an interpreter (program that behaves like a computer) that runs Java byte code
interpreter
program that behaves like a computer, runs program slower than an actual computer (disadvantage), but any computer can run it (advantage)
Just-in-time compilation (JIT)
a technique in which byte code is translated into machine language when first encountered so that the next time the instruction is encountered, it is executed as fast machine code rather than being interpreted as slow byte code (works "just in time")
applets
small programs already translated into byte code, has a wide range in performing many applications (not only in Java, includes other languages & types - but MOST of the time refers to JAVA programs running in WEB BROWSERS)
what are consequences of Java programs running in virtual machines?
their capabilities are limited, so programs can't infect computers with viruses, erase files from someone's hard drive, or steal sensitive data & sending it to competitors. (hackers have succeeded in the past but security weaknesses are repaired as soon as they're known).
what does JVM stand for?
Java Virtual Machine
What is byte code? Describe how the JVM uses byte code.
byte code in Java is a pseudomachine language in which the compiled program is translated into byte code on the JVM, then the program is executed
What is an applet? Describe how applets are used.
an applet is a small program of byte code, it typically refers to small programs of Java byte code that can run in web browsers, however applets are not limited to Java or web browsers. they have a wide range of purposes, from showing animated characters, graphics, or a continuous stream of the stock market.
user interface
The visual elements of an program through which a user controls or communications the application. Often abbreviated UI. (kinda like appearance, look, feel, vibe, or interaction with the program)
graphical user interface (GUI)
familiar to all PC users, familiar & comfortable
terminal I/O user interface
A user interface that allows the user to enter input from a keyboard and view output as text in a window, less common & less comfortable.
3 reasons for using terminal I/O
1) easier to implement than GUI (exception: Visual BASIC). 2) there are programming situations that require a terminal I/O than a GUI. 3) terminal-oriented programs are similar in structure to programs that process files of sequentially organized data.
program
a sequence of instructions for a computer, does nothing until executed by computer
source code
plain text computer program written in a programming language, like a bulk of instructions for a program written in code
System.out.println("Hello World");
prints out the phrase "Hello World"
System.out
the name of an object that knows how to display or print characters in a terminal window
println
is the name of the message being sent to the System.out object
"Hello World" or other strings enclosed in quotation marks
contain the content/characters to be printed
semicolon (;)
marks the end of each statement or sentence in the program
how does an object-oriented program accomplish its tasks?
by sending messages to objects
explain this example program: System.out.println("Hello World");
a System.out object responds to a println message by printing a string of characters (in this case, "Hello World") in the terminal window
parameter
the string characters that appears between the parentheses following the message. some messages require several of these separated by commas, and other messages might not have them.
ln (in println)
stands for "line" & indicates that the System.out object should advance to the beginning of the next line after printing a string
structure of sending messages to objects
method selector operator
period (.) between object's name & message, mechanisms or syntax used to identify and/or invoke specific methods or functions within a programming context. (The period in System.out is NOT this).
Give a short definition of "program.
a set of code/steps to be executed by a computer
What is the effect of the message println?
prints the statement and leaves an empty line after that, the cursor goes to the next empty line - NOT right after the last printed character
Describe how to use the System.out object.
you can use that object for outputting data to the console or other standard output streams
Write a sequence of statements to display your name, address, and phone number in the terminal window
steps to enter Java code into a computer and run it
edit, compile, execute
edit
In this first step, the programmer uses a word processor or editor to enter the source code into the computer and save it in a text file. The name of the text file must match the name of the program with the extension .java added, as in HelloWorld.java.
compile
In this second step, the programmer invokes the Java language compiler to translate the source code into Java byte code. In this example, the compiler translates source code in the file HelloWorld.java to byte code in the file HelloWorld.class. The extension for a byte code file is always .class.
execute
In this third step, the programmer instructs the JVM to load the byte code into memory and execute it. At this point the user and the program can interact, with the user entering data and the program displaying instructions and results.
development environment
a workspace where software is created, tested, and debugged. details involved in editing, compiling, and running a program vary depending on which one of these is used.
common development environments available to Java programmers
UNIX, Linux, Notepad (with command-line activation), BlueJ, Eclipse, JGrasp
UNIX
using a standard text editor with command-line activation of the compiler and the JVM. available on any Macintosh computer that runs MacOS X. free and may require you to download and install the Java software development kit (SDK).
Linux
(Java) development environment using a standard text editor with command-line activation of the compiler and the JVM
Notepad (Microsoft Windows)
used as an editor, with command-line activation of the compiler and the JVM from inside a command or DOS window. it's a DOS development environment
DOS development environment
collection of tools and resources used to create software applications specifically for the Disk Operating System (DOS). used to have the most widespread use.
integrated development environment (IDE)
may cost money, but it has the advantage of combining an editor, a Java compiler, a debugger, and a JVM in a manner intended to increase programmer productivity. take time to master, however, and they can obscure fundamental details of the edit, compile, and run sequence.
Step 1
Use Windows Explorer to create the directory in which you intend to work (for instance, C:\Javafiles). Open a terminal window by selecting Command Prompt (or something similar) on the Start/All Programs/Accessories menu. In the terminal window, use the cd command to move to the working directory.
Step 2
Open the Notepad editor and create the file HelloWorld.java by typing the text as shown in the image. Once Notepad opens, click Yes in the dialog box to create the file and then type in the lines of code for the program.
Step 3
Write the code, save the file and switch back to the terminal window. Compile the program by typing javac HelloWorld.java. The DOS prompt returns when the compilation is complete.
Step 4
Run the program by typing java HelloWorld.
compile-time errors
Mistakes detected by the compiler, also called syntax errors
error in the input
On line 6 of the program, println is misspelled as prinrln.
error message printed in output
When the program is compiled, the compiler prints a list of errors in the terminal window. The error messages refer to line 6 of the source program and says that a symbol cannot be found. More specifically, the symbol for method prinrln within the class java.io.PrintStream cannot be found. In fact, the object System.out is a member of this class, and the program has attempted to send a message that the class does not recognize. A caret symbol (^) points to the location of the error in the code. Error messages indicate where the compiler encountered text it could not translate into byte code.
readability
the quality of being legible or decipherable
why is readability important in a program?
Programs typically have a long life and are usually maintained by many people other than their original authors. They need to be easy to read, comprehend, and edit for other programmers.
what is the main factor affecting a program's readability?
The main factor affecting a program's readability is its layout. Indentation, the inclusion of blank lines and spaces, and other typographical considerations make the difference between an intelligible program and an incomprehensible mess.
does a program's layout, format, or readability matter when executing it?
No, the compiler completely ignores a program's format, provided that there are no line breaks in the middle of words or quoted strings. (The program in the image is completely functional, but it is just unreadable).
hacking
A term whose use goes back to the early days of computing. In its original sense, they are a programmer who exhibits rare problem-solving abilities and commands the respect of other programmers. regarded as an accomplishment along the lines of Olympic gymnastics. Unfortunately, this practice has changed over the years, and the term has acquired darker connotations.
a "hack"
a programming maneuver that exhibits technical brilliance and elegance
hacker ethic
hackers should respect the privacy of others and distribute their software for free
hackers
Programmers who break into computer systems in an unauthorized way, whether their intent is just to impress their peers or to cause actual harm. Also includes students and professionals who lack a disciplined approach to programming.
Name the three steps in writing and running a program.
Edit, compile, execute
What are compile-time errors?
Errors detected by the compiler, also called syntax errors
Find the compile-time errors in statements A and B.
A. System.out.println("Here is an error);
B. System.out.println("Here is another error";
Statement A's string is not closed by a second quotation mark. Statement B's string is not closed by a second parenthesis.
Why is readability a desirable characteristic of a program?
It makes programs easy to read, understand, and edit. This is especially paramount if programs are being shared among other users who are constantly editing the code. It needs to be understandable for other people to look at.
temperature conversion program
reads user inputs and performs computations, demonstrates several important concepts despite brevity & simplicity
How is instantiation done like in general?
SomeClass someObject = new SomeClass(some parameters);
System.in
names a variable in the System class that refers to the keyboard
parameters
used to share information between objects
variables
names that refer to data values or objects.
numeric variable
names a location in RAM in which a number can be stored. The number is usually referred to as the it's value.
type double variables
contain only floating-point numbers
is it required that all variables in Java begin with a lowercase lettter?
no, it is only customary
assignment operator
=
assignment statements
Statements utilizing an assignment operator
*
indicates the multiplication operator
/
indicates the division operator
-
indicates the subtraction operator
+
indicates the addition operator
Java operator precedence
PEMDAS
variables celsius and fahrenheit
hold numbers
variables reader and System.out
hold references to objects
What is a variable in a program and how is it used?
Stores data in a "container" and can be used & reused for complexity
Scanner class
Used for obtaining user input in Java.
Describe the role of the assignment (=) operator in a program.
assigns values/expressions to variables
What is a Scanner object?
A Scanner object receives messages to input data from a human user. For example, when sent the message nextDouble, a Scanner object causes a program to wait for a user to enter the digits of a number. When the user presses the Enter key, the object returns the corresponding floating-point number.
Explain the difference between a variable of type double and a variable of type Scanner.
a double variable tyle holds numerical floating-point values. a scanner variable type holds references to the scanner class & object
Describe the difference between print and println, and give an appropriate example of the use of each.
using print causes the cursor at the end of the last character to appear exactly after the character. using println causes the cursor to appear in the beginning of the next line.