

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to the concepts of programs and algorithms using the java programming language. It covers the difference between a program and an algorithm, the role of a compiler and interpreter, and the basic structure of a java program. Students will learn about the importance of bytecode and the java virtual machine (jvm) in executing java programs on various devices.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


What is a program? A recipe for doing something A precise set of instructions - Generally from a limited set of available instructions Like the rules for a game, or how to build something, or directions to your house, or a recipe for macaroni and cheese What is an algorithm? A set of steps for solving a problem. Each step is effective o Doable, in a finite amount of time Each step is precise o Unambiguous and uniquely interpreted The algorithm terminates There are Inputs and Outputs Last time we looked a psuedocode: An English-like description of an algorithm. Java Start with source file viewed with an editor understandable by a human Not directly executable by a computer – cannot run the source file. The name of the .java file usually matches the name of the class it contains o CountSpaces.java contains the class CountSpaces o Capitalization must be the same. Use compiler to translate source code into another language For Java, compiler translates source code into Java bytecode Java bytecode is machine independent Compilers for other languages (such as C++ or FORTRAN) produce machine code o Directly executable by a computer o Not machine independent. Can only be executed on the type of computer on which it was compiled. javac CountSpaces.java o produces CountSpaces.class DRAW PICTURE Use interpreter to execute java bytecode Java Virtual Machine (JVM) - java Can execute java bytecode on any computer or device that has a JVM
Can create program on Windows computer and compile it using javac. Mail class file to your friend who has a Mac Your friend can execute your program on his Mac with his JVM Why is this important? o Bytecode files are smaller than source files, so sending them over the Internet is more efficient o Companies who develop software don’t want people to have access to their source code. o Some devices may not be capable of compiling programs, but they can run the JVM. Let’s look at the language: Project DisplayForecast.java Key elements of the program