JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.

Slides:



Advertisements
Similar presentations
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Advertisements

Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
Written by: Dr. JJ Shepherd
CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Java Syntax Primitive data types Operators Control statements.
Subclasses. Inheritance class Animal { int row, column; // will be inherited private Model model; // private prevents inheritance Animal( ) {... } //
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Comparing Objects in Java. The == operator When you define an object, for instance Person p = new Person("John", 23); we talk about p as if its value.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Java. Why Java? It’s the current “hot” language It’s almost entirely object-oriented It has a vast library of predefined objects It’s platform independent.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
BPJ444: Business Programming using Java Java basics Tim McKenna
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Introduction to Java COM379 (Part-Time) University of Sunderland Harry R Erwin, PhD.
Java Programming Java Basics. Data Types Java has two main categories of data types: –Primitive data types Built in data types Many very similar to C++
Copyright Curt Hill Variables What are they? Why do we need them?
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Java 5 Part 2 CSE301 University of Sunderland Harry Erwin, PhD.
CSC 212 Object-Oriented Programming and Java Part 2.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Written by: Dr. JJ Shepherd
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
1 Review for Midterm 2 Aaron Bloomfield CS 101-E.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
CompSci 100E JB1.1 Java Basics (ala Goodrich & Tamassia)  Everything is in a class  A minimal program: public class Hello { public static void main(String[]
Object Oriented Programming Lecture 2: BallWorld.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Lecture 5: Some more Java!
Java Primer 1: Types, Classes and Operators
Object Oriented Programming
Multiple variables can be created in one declaration
University of Central Florida COP 3330 Object Oriented Programming
Starting JavaProgramming
null, true, and false are also reserved.
An overview of Java, Data types and variables
Recap Week 2 and 3.
Java Programming Language
Java Basics Data Types in Java.
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304

Outline Resources Java Basics Operators in Java Java Syntax Method Calls Wrapping it up

Resources Arnold and Gosling, 1998, Java Programming Language, second edition, Addison-Wesley. Farley, Crawford, and Flanagan, 2002, Java Enterprise in a Nutshell, second edition, O’Reilly, ISBN: For programmers. Bergsten, 2002, JavaServer Pages, second edition, O’Reilly, ISBN: X. Covers JSP 1.2, for both programmers and web page authors. Has lots of worked examples. Recommended.

Scope This presentation is not intended to make you a Java programmer. If you will be doing a good deal of JavaServer Pages scripting, you should learn Java. Remember, however, scripting is often unnecessary.

Java Basics Unicode Identifiers and Names Primitive Types Reference Types

Unicode Java is written in the Unicode character set. Java programs can also be written in ASCII or Latin-1 characters, which most text editors and web page development programs support. Unicode characters are stored in 16 bits and can represent almost all written languages. –A –å –π Unicode can be used anywhere.

Identifiers These begin with a letter, underscore (_), or currency symbol (€$¥£). Contain any number of letters, numbers, underscores, and currency symbols. Avoid the currency symbols as compilers use them. Remember Unicode. The following are legal identifiers: –π –Ö

Scope of Names The scope of the declaration of a name is the region of the program within which the entity can be referred to using a simple name. Class names must be imported (or declared) to be in scope. Members (attributes and methods) have class or interface scope. Method parameters have method scope. Local variables have block scope. When a name is hidden by another name, you must provide a full name, not a simple name.

Primitive Data Types boolean (true or false) char (16-bit) short byte (8-bit) int long float double

‘Horses for Courses’ Primitive types lack methods and cannot be stored in collections that expect some sort of object. Each primitive type has a corresponding class (with useful methods) that provides instances that can be stored in a collection. Boolean—boolean Character—char Byte—byte Short—short Integer—int Long—long Float—float Double—double

Type Conversions Integer to floating point are automatic. char to/from integer and floating point are supported Widening conversions (e.g., short to long) are safe. Narrowing conversions are dangerous. They lose information.

Pointers There are no programmer-accessible pointers in Java. Yeah! Classes and arrays in Java are called reference types. Java manages the underlying pointers. There is no way to convert from a reference to a primitive object. You cannot use a reference to access a private member attribute.

Classes and Arrays These are called reference types Created using the new operator –new type(args); // an object –new type[dim]; // 1-D array –new type[dim1][dim2] etc; //larger arrays A class or array object is null (does not exist) until it is initialized. Writing new classes is Java programming. Plan on using existing Java classes instead.

Creating an Object ClassName obj; –Declares that the name obj refers to an obj of class ClassName in the current scope. –Does not create that object. Until the object is created, obj refers to null (e.g., nothing). –To create the object, execute the following: obj = new ClassName(argument list); –Note that the constructor for ClassName may be overloaded. –‘argument list’ is a list of arguments.

Using an Object or Class To refer to the member fields and methods of an object, use the following syntax: –obj.field; –obj.method(args); To refer to class level (‘static’) fields and methods, use the following syntax: –ClassName.field; –ClassName.method(args);

String Contains Unicode text Constant—unlike C and C++ strings. A class, not a primitive type Literals consist of anything between a pair of double quotes. To include a double quote in a string, use \” Supports operator overloading (+, +=). This is the only place in Java where operator overloading takes place.

Copying and Comparing Reference Types The pointer is copied, not the data. Hence the same data are used. Comparisons (e.g., ==, !=,, etc.) of most reference types are done by comparing pointers. Hence two different objects containing the same field values are not equal. Comparisons of primitive types and Strings are based on value.

Java Operators Generally as in C or C++. Typecasting is handled by (type)var;

Java Operator List +=, ++, -=, --, etc., as in C and C++ != not-equals-test == equals-test, = [num] for array access ! means ‘not’ = assignment +, -, *, /, % arithmetic && logical and || logical or ?: conditional. used for member access () used in function or method calls

Java Syntax Variables may be declared anywhere. The variable name is in scope in the local block from the point of declaration. Reference types are set to null (non- existent) until they are given a value. Primitive types have a default value, typically zero or false.

Statements Generally as in C/C++ Statements are terminated by ‘;’ Blocks are delimited by { }, may substitute for individual statements. Statements that you are unlikely to use: –synchronized (threads) –throw (an exception) –try/catch/finally (to handle exceptions)

Common Statements import brings a Java class into scope if (logical test) then statement; else statement; switch is used to handle multiple cases for(init;logical test;final) statement; is a for loop do statement while(expression); is a do loop while (logical test) statement; is a while loop break; is used to exit a loop immediately continue; goes to the end of the loop return retval; exits a function or method

Method Calls Look like functions, but are always associated with a class or object. Defined by a signature: –Method name –Arguments –Return type (differs from C++, may be void) –Checked exceptions thrown (not of much concern here) –Method modifiers: public, static, abstract, final, native, private, protected, synchronized. (you usually use public methods)

Using JSP Scripting You don’t need to write classes or methods. If you need to use a temporary variable, declare it in a element. If you need to display a variable, use a element. If you need to use Java syntax (if then else, loops, switch perhaps, use elements to hide it from the HTML. If you need to call Java classes, you will need to import them.

Conclusions Java is available if you need it, particularly for something that an action element (see previous lecture) can’t handle or prototyping. Use it like any scripting language. You won’t usually need to write classes or methods. Use the block structure to control the HTML generation and any logic. Variables give you flexibility in displaying information. JDBC can be used like ODBC. That’s all you need folks!