16 Pages
Unlock Document

Ryerson University
Information Technology Management
ITM 200
Vikraman Baskaran

Chapter 1 Solving Problems with Computers -Java is one of the most popular programming languages in the world -it is very popular because it can be used to solve a wide variety of problems in different domains -Java is a great way to solve problems Computers and Programming: What is a Computer? -a computer is a general purpose device that behaves according to the sets of instructions and data -computers execute instructions to process data -each computer has its core which is called Central Processing Unit (CPU) These days CPUs are built with a single microprocessor chip Each microprocessor is associated with a set of instructions (machine codes) which it can execute Instructions and the data are stored as a binary bit pattern which is a string of 1s and 0s -any computer can execute instructions in the machine code language of its microprocessor What is a Computer Programmer? 1) Machine Language: -set of primitive instructions -every computer is associated with a set of machine code instructions that is designed to recognize and execute -machine code consists of a sequence of instructions Example: two add two numbers you might write an instruction in binary code like this: 10010100100100101001001010 etc. -all information is stored in the sequence of ones and zeros (binary bit pattern) -it is highly to read and modify -program can be stored on a disk In order to execute the programs, it is loaded from the disk into the computers internal memory; then the instructions are fetched one by one by the CPU and executed 2) Assembler Language: -in order to overcome program of writing programs using binary bit language, assembler language was developed to make a programming easy for humans to read, and programming less error prone -computers cannot understand assembly language -data can be represented using decimal numbers instead of binary Example: Instruction to load the number 5 into a CPU might look like: LD 5 instead of 0010010001001101 -assembler is used to convert assembly language programs into machine code Example: to add two numbers, you might write an instruction in assembly code like this: ADDF3 R1, R2, R3 3) High Level Languages and Compliers: -high level languages are more abstract, problem oriented instructions that captured common patterns of instruction usage found in assembler language rd this meant that a single instruction from a 3 generation language might be correspond to several assembler language instructions, so that programs became shorter and more succinct -programming languages became more oriented towards solving problems and less towards machine architecture rd -3 generation rdnguage operated at a higher level of abstraction than the assembler program -Example of 3 generation language: 1980s: MODULA-2 C++ 1990s: MODULA - 3 JAVA -it is English like -easy to learn and program Example: following is a high-level language statement that computes the area of a circle with radius 5: area = 5 * 5 * 3.1415; -in this class we will use Java java is a relatively new programming language developed by Sun Microsystems, Inc java has a built in graphical user interface support it is intended to be platform independent its syntax (structure) is similar to C++ but is simpler than C++ in high level language things like text, windows, buttons and files have a meaning, in machine code only numbers have meanings Compiling Source Code: -program in high level language is called source code -computers cannot understand a source program -complier translates the source program -linked with supporting library code Constructing and Running Java Programs: -java program is just a text file; it contains letters, numbers and symbols, it is often called a source code file -you can create the source code using any text editor, commercial java development packages normally have an editor built it, if you are using Windows then the notepad program makes it perfectly to use -you can use JCreator, the java complier will require the filename of the Java source file to end in .java -program text is then fed into the Java complier, it there are no errors in the program then the output will be the file containing the complied byte code program, ready to run -name of the file should be the same as the source code file but with the extension .class, if there are no errors the complier will tell you what they are and will try to tell you where you are depending on how well you have written the program, it may work or not -process of finding out why a program does not work or does not work as expected is called debugging -before you run your program you must compile them complier: translates computer written in language to another language java development kit: includes java complier byte code: java complier converts your source code into a format named byte code that can be executed on many different kinds of computers Comments: -any text following // on a line is a comment which is an explanation of what the program does -there are 3 types of comments in Java 1. Line Comment: two slashes (//) in a line 2. Paragraph Comment: enclosed between /* and */ in one or multiple lines 3. Javadoc Comment: begins with /** and ends with */. Used for documenting classes, data, and methods, can also be extracted into an HTML file using JDKs javadoc command Reserved Words: -reserved words or keywords -have a specific meaning to the complier Example: when complier sees the word class it understands that the word after class is the name for the class -reserved words are; public, static, void Blocks: -pair of braces in a program that forms a block which groups components of a program public class Test { public static void main(String[] args) { Class block System.out.println("Welcome to Java!"); Method block } } Classes: -fundamental unit of organization in an object oriented program is the class which structures and organizes a program -classes are self contained and autonomous -class must have the same name as the program file itself -class should have an method called main (); this is where the program starts -all program instructions must be inside methods, which are inside classes -Common misunderstanding is that a program starts at the top, and continues downwards, however Main Method: Java programs start by executing the method called main () After this execution is controlled by the programmer -Main method provides control of the program flow -Java interpreter executes the application by invoking the main method SUMMARY: -java is an object oriented programming language -java complier converts java program into Byte code -when compilation is successful, Byte code can be successful -java compilation contains many components like reserved words such as methods, comments etc -java execution starts from the main method Chapter 2 Algorithms and Programs -programming task can be divided into 2 main phases: Problem Solving Phase: develop the algorithm in the form of pseudo-code and flow charts Implementation Phase: implement the program in a programming language Problem Solving: -programming is all about solving problems -program is just a set of instructions that describes how to solve a particular problem, written in a language that a computer can understand -there are usually 4 steps in solving a problem: Understand the problem Work out a plan Sort out the details Test and evaluate -same thing also applies to writing a program -understanding the problem is a vital step in solving a problem, you need to ask What information do we know? (most important step) What do we want to happen? What can one lead to the other? -writing a program is very time consuming and if it turns out that the program does not do what the client want it to do, then the process of re writing or changing the program can be extremely expensive Therefore best solution is to understand it fully before starting to develop a program -there are always many routes available to reach the destination or to solve the problem, therefore you should think about all the possible solutions and choose the best one The Pizza Eaters Problem: -consider the problem solving process as equally important to a programming problem; the desire to eat pizza -you will be amazed by the range of questions that you consider even on something as simple as eating pizza -Examples of some questions: You know you want pizza but when? Are you desperately hungry? Or can you wait for a while? Do you prefer to taste homemade pizza? Do you have ingredients? If not, can you be bothered to get them from the store? Do you have pizza in the freezer? Do you like near a take away? Or do they deliver? Do you want thin or thick base? Is it just for you? Or for your friends as well? -you should brainstorm in the above manner until you fully understand the problem and have some alternatives strategies for solving it
More Less

Related notes for ITM 200

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.