DOC PREVIEW
CU-Boulder CSCI 5448 - Introduction to java

This preview shows page 1-2-15-16-17-32-33 out of 33 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Introduction to JavaOverviewHistoryCharacteristicsData TypesPrimitive Data TypesVariablesOperatorsExpressionsAnatomy of A Java ProgramCommentsPackageClassesReserved WordsModifiersBlocksStatementsMethodsmain MethodObjectsClassesClassesConstructorsExampleInheritanceExampleInterfaceExampleEncapsulationAbstract Classes and MethodsAbstract Classes vs. InterfacesPackage幻灯片编号 33Zhifu PeiCSCI5448 – Spring 2011Prof. Kenneth M. Anderson Introduction• History, Characteristics of Java language Java Language Basics• Data types, Variables, Operators and Expressions Anatomy of a Java Program• Comments, Packages, Classes, Reserved Words, Modifiers, Blocks, Statements, Methods and main Method Concepts of Object-Oriented Programming• Objects, Classes, Inheritance, Interface and Package Developed by James Gosling at Sun Microsystems. Released by Sun Microsystems in 1995. Hotjava – The first java-enabled web browser J2EE, J2ME and J2SE Simple, object-oriented, and familiar Robust and secure Architecture-neutral and portable High performance Interpreted, threaded, and dynamic A data type is a scheme for representing values.• Values are not just numbers, but any kind of data that a computer can process. A data type defines a kind of data that is represented by a variable Java data types are case sensitive.Data Type Size (byte) Rangebyte 1 -128 to 127boolean 1 true or falsechar 2 (Unicode) A-Z, a-z, 0-9, etc.short 2 -32768 to 32767int 4 (about) -2 million to 2 millionfloat 4 -3.4E38 to 3.4E18long 8 (about) -10E18 to 10E18double 8 -1.7E308 to 1.7E308• There are only eight primitive data types.• New primitive data types cannot be created by a programmer Variables are labels that describe a particular location in memory and associate it with a data type. A declaration of a variable is where the program allow memory for the variable.• instance variables: declared without “static”• class variables: declared with “static”• local variables and Parameters Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result.• assignment, arithmetic, and unary operators“=”; “+”, “*”; “++”, “!”• equality, relational, and conditional operators“==”, “!=”, “<=”; “||”, “?:” • bitwise and bit shift operators“~”, “&”, “>>” An expression is a construct made up of variables, operators, and method invocations. An expression can return other types of values as well. A compound expression can be constructed from various smaller ones. A simple java Program Comments in Java are preceded in two types:• Line comments: Line comments are precede by two slashes “//” in a line.• Paragraph comments: Paragraph comments are enclosed between “/*” and “*/” in one or multiple lines. The second line of the program is the package name. It specifies the package name, org.Welcome for the class Welcome. The class is the essential Java construct. A class is a template. A program is defined by using one or more classes. Reserved words (Keywords) are words that have a specific meaning to the compiler and cannot be used for other purposes (name of variables, classes, methods…) in the program. Examples:• When the compiler sees the word class, it understands the word after class is the name for the class.• public, void, static are also reserved words. Certain reserved words are called modifies that specify the properties of the data, methods, and classes and how they can be used. Examples: • A public datum, method, or class can be accessed by other programs.• private, protected, static and void are also modifiers. A pair of braces in a program forms a block for a group components of a program. A statement represents an action or a sequence of actions. A statement ends with a semicolon “;”. A method is a collection of statements that performs a sequence of operations to display a message on the console. A method can be used even without fully understanding the details of how it works. A method is used by invoking a statement with a string argument which is enclosed within parentheses. The main method provides the control of the program flow.  The Java interpreter executes the application by invoking the main method. Objects are key to understand OO technology. An object is a structured block of data. An object may use many bytes of memory. An object stores its state in fields and exposes its behavior through methods. The data type of an object is its class. Creating an object is called instantiation. The class is the essential Java construct.  A class is a blueprint or prototype from which objects are created. A class is a description of a group of objects with similar properties and behaviors. A class is a pattern for an object. A class does not create any objects. A class consists of• a collection of fields, or variables, very much like the named fields of a struct.• all the operations (called methods) that can be performed on those fields.• can be instantiated. A class describes objects and operations defined on those objects. Classes should define one or more methods to create or construct instances of the class. Their name is the same as the class name. Constructors are differentiated by the number and types of their arguments. If none constructor is defined, a default one will be created. Constructors do not return anything. Classes are arranged in a hierarchy. Inheritance enables to define a new class based on a class that already exists. A class that is derived from another class is called a subclass. The class from which the subclass is derived is called a superclass. A class inherits fields and methods from all its superclasses, whether direct or indirect. A subclass can override methods that it inheritance, or it can hide fields or methods that it inherits. An interface defines a protocol of communication between two objects. An interface declaration contains signatures, but no implementations, for a set of methods, and might also contain constant definitions. A class that implements an interface must implement all the methods declared in the interface. An interface name can be used anywhere a type can be used. Encapsulation


View Full Document

CU-Boulder CSCI 5448 - Introduction to java

Documents in this Course
Django

Django

42 pages

ENRS

ENRS

30 pages

PhoneGap

PhoneGap

22 pages

Load more
Download Introduction to java
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to java and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to java 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?