02--basics-2x2

02--basics-2x2 - COMP 202 Introduction to Computing 1...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COMP 202 Introduction to Computing 1 COMP-202 Unit 2: Programming Basics CONTENTS : The Java Programming Language Variables and Types Basic Input / Output Expressions Conversions COMP 202 Introduction to Computing 1 Part 1: The Java Programming Language COMP 202 Introduction to Computing 1 3 COMP-202 - Programming Basics The Java Programming Language Java was created by Sun Microsystems, Inc. It was introduced in 1995 and has become quite popular It is an object-oriented language It represents the program as a series of objects , each of which belongs to one of many categories called classes The Java programming language combines both compilation and interpretation COMP 202 Introduction to Computing 1 4 COMP-202 - Programming Basics Java Translation and Execution (1) The Java compiler translates Java source code into a special representation called bytecode Java bytecode is not the machine language for any traditional CPU Another software tool, an interpreter called the Java virtual machine (JVM) translates bytecode into machine language and executes it Therefore the Java compiler is not tied to any particular machine Java bytecode will run on any CPU for which there exists a JVM Java is considered to be architecture-neutral COMP 202 Introduction to Computing 1 5 COMP-202 - Programming Basics Java Translation and Execution (2) .java Java compiler .class Java source code Java bytecode JVM (CPU 1) CPU 1 JVM (CPU 2) CPU 2 This is the standard approach to Java translation and execution COMP 202 Introduction to Computing 1 6 COMP-202 - Programming Basics Java Translation and Execution (3) Java compiler Java source code Java bytecode .java Bytecode compiler (to CPU 2) Bytecode compiler (to CPU 1) binary code (CPU 1) binary code (CPU 2) CPU 1 CPU 2 .class This approach to Java translation and execution is very uncommon, and probably unnecessary COMP 202 Introduction to Computing 1 7 COMP-202 - Programming Basics Java Program Structure (1) In the Java programming language: A program consists of one or more classes ; each class is defined in a different file A class contains one or more methods A method contains program statements Statements are the actual commands you issue, the instructions that are executed when the program runs A Java program always has at least one class which contains a method called main() This is where the program starts executing COMP 202 Introduction to Computing 1 8 COMP-202 - Programming Basics Java Program Structure (2) For now, all programs we develop will involve writing only one class , and this class will contain exactly one method: main() COMP 202 Introduction to Computing 1 9 COMP-202 - Programming Basics Java Program Structure: Classes public class MyProgram { } class body class header: the name of the class The class header states that you are defining a new class whose name will be the name you specify. This class will be the name you specify....
View Full Document

This note was uploaded on 01/15/2010 for the course MATH 423 taught by Professor Steele during the Spring '06 term at McGill.

Page1 / 32

02--basics-2x2 - COMP 202 Introduction to Computing 1...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online