Lecture 1 - Introduction (Class Notes) Outline: How does a computer work? Very brief! What is programming? The evolution of programming languages Generations of programming languages Compiled vs. Interpreted Procedural vs. Object-oriented Your first taste of a Java program Remember/memorize your "boiler plate" Give it a try (compile and run) My words, your words,..., and keywords Types of apps: Console-based vs. Graphical The process of writing a program Understand your problem Come out with a way to solve it: algorithm Edit, compile, and run If error, debug and try again IDE (Integrated Development Environment) Eclipse Netbeans Any thing else? How does a computer work? The knowledge lies on your fingertips - Try a google search on this subject on this question should yield a bunch of hits Major computer hardware components - A computer system has many components. Key components to facilitate computation are:
1. Central Processor Unit (CPU), usually a microprocessor nowadays 2. Memory chips 3. Input / output, such as keyboards, mice, printers, display units, etc. 4. Bus or bridges How do you put these components together? Computer architectures. - The role of each components: 1. CPU -- executes programs (to be precise, execute a sequence of program instructions) CPU is designed to understand a set of fixed instructions, call instruction set Which major brands of CPUs do you know? Different types of CPUs have different instruction sets. Can you give some examples? Have you ever thought about how a computer becomes so smart while at the same time its CPU really only understands a limited set of instructions? 2. Memory chips -- store input data, intermediate data, and final results for a program execution
3. Input / Output -- Keyboard and mice - provides input data for programs / tasks -- Display and printer - provides the results -- Ports, ports, how many ports can you imagine? What are their functions? 4. Bridges and buses -- Do we really talk about the bridges and buses as we see every day? No No No. -- Do you mean there are bridges and buses inside a computer? Yes Yes Yes. -- You cannot see them but they function the same way as physical bridges and buses -- They transport data or digital electronic signals instead of human traffic Major computer software components -- System software (operating systems, file systems, user interfaces, etc.) -- Application software (editors, office productivity suites, databases, browsers, etc.) What is programming? - Can someone tell me what you think programming is about? A wikipedia link: http://en.wikipedia.org/wiki/computer_programming Problem Solution A sequence of program statements (instructions) Take a solution of a quadratic equation as an example. How you program it into a working program is a good example of programming First you are going to decide which programming language to use. There are many programming languages out there. Choose which one?
It really depends on many factors. We give an overview on the evolution of the programming languages. The evolution of programming languages -- Generations of programming languages 1) Machine code -- all numbers (instructions and data) a) No translation is needed -- directly understandable by machines b) But do you dare to program this way? 2) Assembly languages -- symbolic name from instructions a) An assembler is needed to translate symbolic instructions into machine code b) Pseudo instructions added -- these do not translate into machine code c) Different family of CPUs may use different assembly languages 3) High-level languages -- every expressive a) A compiler or interpreter is needed to do the translation b) Examples: BASIC, Fortran, Pascal, C, C++, Ada, Java, Python, 4) Fourth-generation programming languages (4GL) -- designed to reduce programming effort -- Compiled vs. Interpreted 1. Is a compiler needed? 2. Is a interpreter needed? 3. What are the pros and cons? -- Procedural vs. Object-oriented (OO) 1. From procedural to object-oriented: a significant shift a. Procedural: very good for scientific computing b. OO is better to model the worldly reality (for business applications and
system controls) 2. What is the difference? Your thinking/designing pattern is totally different 3. Pros and cons Your first taste of a Java program Read this: http://introcs.cs.princeton.edu/java/11hello/ The above link also shows you how to get your first Java program working. Your first Java program (p. 11). Here is another one: public class HelloWorld { public static void main(string[] args) { System.out.println( Hello, World! ); } } The anatomy of the above Java program: 1. Every Java program starts with a public class -- called Main class a. What is the name of the class? 2. Inside the main class, there must be public static method (or function) by the name of main ; this method provides the entry point of the Java program 3. The System.outis an built-in Java object we talk to to get our print-outs. 4. The result of executing the program is a single-line output: Hello, World! Your boiler-plate code As you can see, quite some decorative stuff existed in the above code. This stuff is the boiler-plate code to get Java compiler happy.
While you may not be that happy, but someone higher than you said this has to be done! What can you do with it? Option 1 - Sigh as long as you like it to be Option 2 - (highly suggested) Get used to it Let s try to memorize it. Then take a piece of paper. Write the code out of your memory. Go... Compile and run See my demo. Try to remember the steps as I demo. - Edit and save source code: the file name has to be HelloWorld.java, matching the name of the class - Compile: use Java compiler (the input is the source code) javac HelloWorld.java What do you get out of this? HelloWorld.class(the binary output containing machine code) - Run: use java interpreter java HelloWorld You instruct java to execute HelloWorldclass (but.classis not needed because it is implied) My words, your words, and keywords
Take another look at our first Java code containing a bunch of words: 1. Typos really? What language are we speaking? Ex: HelloWorld, args, println 2. My words and your words: which are? Ex: HelloWorld, args 3. Specially reserved words for special meanings: keywords Ex: public / private, static, void, class Make sure use them as intended! The process of writing a program 1. Understand your problem: can be easy (purely simple) and hard (complex enough) 2. Figure out a solution (or algorithm): That has to work all the time (corner cases, etc.) Who can do such a perfect job? Otherwise we would not see blue screens, etc. 3. Edit, compile, and run Source code files binary code files Java virtual machine (run) 4. When all is not perfect, errors, test for errors, debug, fix errors, long-term maintenance (isn t it boring to do this? But someone has to do it. You and/or me!) Can all of these be made easier? Sort of What makes us different from animals? We build tools! Integrated Development Environments (IDE) How an IDE helps? Edit/Compile/Run/Debug and beyond Examples of Java IDEs: Dr. Java -- Light-weight, for students Eclipse -- developed by IBM initially
Netbeans -- now under Oracle Your instructor has chosen to use Netbeans. But you are free to try others. However I might not be able to help. (End of lecture 1)