COURSE 1 PROGRAMMING III OOP. JAVA LANGUAGE

Similar documents
Index COPYRIGHTED MATERIAL

Introduction to Programming Using Java (98-388)

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

CSC 1214: Object-Oriented Programming

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

5/23/2015. Core Java Syllabus. VikRam ShaRma

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Games Course, summer Introduction to Java. Frédéric Haziza

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

Course information. Petr Hnětynka 2/2 Zk/Z

Language Fundamentals Summary

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Course information. Petr Hnětynka 2/2 Zk/Z

DM550 Introduction to Programming part 2. Jan Baumbach.

15CS45 : OBJECT ORIENTED CONCEPTS

3. Java - Language Constructs I

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

1 OBJECT-ORIENTED PROGRAMMING 1

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Programming. Syntax and Semantics

STRUCTURING OF PROGRAM

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Introduction to. Android Saturday. Yanqiao ZHU Google Camp School of Software Engineering, Tongji University. In courtesy of The Java Tutorials

WA1278 Introduction to Java Using Eclipse

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Page 1

Language Features. 1. The primitive types int, double, and boolean are part of the AP

1 Shyam sir JAVA Notes

Java 1.8 Programming

Pace University. Fundamental Concepts of CS121 1

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

Programming with Java

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

1Z Java SE 5 and 6, Certified Associate Exam Summary Syllabus Questions

JAVA MOCK TEST JAVA MOCK TEST II

Java Training JAVA. Introduction of Java

NOOTAN PADIA ASSIST. PROF. MEFGI, RAJKOT.

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Operators in java Operator operands.

An overview of Java, Data types and variables

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

The Java language has a wide variety of modifiers, including the following:

Operators and Expressions

Java Programming. Atul Prakash

APPENDIX A: SUMMARY OF IMPORTANT JAVA FEATURES

COMP 202 Java in one week

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

AP Computer Science A

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

Program Fundamentals

Object Oriented Programming and Design in Java. Session 2 Instructor: Bert Huang

Chapter 1 Introduction to java

CMSC 331 Second Midterm Exam

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

Computational Expression

Outline. Why Java? (1/2) Why Java? (2/2) Java Compiler and Virtual Machine. Classes. COMP9024: Data Structures and Algorithms

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

CSC Java Programming, Fall Java Data Types and Control Constructs

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

Core Java Syllabus. Overview

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

4 Programming Fundamentals. Introduction to Programming 1 1

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

JAVA OPERATORS GENERAL

CS251L REVIEW Derek Trumbo UNM

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

Chapter 2. Elementary Programming

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

Computer Components. Software{ User Programs. Operating System. Hardware

LTBP INDUSTRIAL TRAINING INSTITUTE

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Tony Valderrama, SIPB IAP 2009

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Java for Python Programmers. Comparison of Python and Java Constructs Reading: L&C, App B

A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p.

Java Overview An introduction to the Java Programming Language

Introduction to Java & Fundamental Data Types

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

Chapter 1 Introduction to Java

CS260 Intro to Java & Android 03.Java Language Basics

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

DM503 Programming B. Peter Schneider-Kamp.

Transcription:

COURSE 1 PROGRAMMING III OOP. JAVA LANGUAGE

COURSE CONTENT OOP Concepts. Java Language Classes Comparing objects in Java Collections. Generics Graphical Interfaces. Swing Java IO JDBC - Java Database Connectivity Threads [possible - IBM - Web Services. Soap. Rest]

ORGANIZE STUFFS Course Flavia Micota cab. 046B contact: flavia.micota@e-uvt.ro site: web.info.uvt.ro/~zflavia Laboratory Flavia Micota Monica Tirea cab. 050B contact: monica.tirea@e-uvt.ro Attendee Course random tests from subjects presented in current course Laboratory minimum 10 presences

ORGANIZE STUFF Mark Theoretical exam 50% Laboratory test after exam 30% Homework - 10% Attendee - 10% 5% course tests 5% laboratory activity Homework submit: http://elearning.e-uvt.ro/ cut date: 2 weeks from the moment of announcement

COURSE 1. CONTENT Object Oriented Programming Java Language History Java Program Structure Java Language

PROGRAMMING LANGUAGES Imperative (algorithmic) languages The program is a sequence of statements Uses variables to access emmory Types Procedural Languages Object Orieted languages Declarative (non-algorithmic) languages The progammer presents the problem, the way to solution it is included in the language Types Functional (applicative) languages Logic languages Other languages

PROGRAMMING LANGUAGES

PROGRAMMING PARADICSM Unstructured programming Procedural programming Modular programming Data abstractization Object oriented programming Generic programming (templates) Aspected oriented programing (AOP)

OBJECT ORIENTED LANGUAGE A language or technique is object-oriented if and only if it directly supports [Stroustrup, 1995]: [1] Abstraction providing some form of classes and objects [2] Inheritance providing the ability to build new abstractions out of existing ones [3] Runtime polymorphism providing some form of runtime binding.

OBJECT ORIENTED LANGUAGE Objects Have a state that reflects by current characteristics and conditions and a behaviour that describe the action that it cat execute Classes Groups objects with similar characteristics Data Encapsulation Hidding object data and behaviour Data Abstractization A simplification or a model of a compex concept, process or real word object Inheritance Is a contract between a class and the outside world When a class implements an interface, it promises to provide the behavior published by that interface Polymorphism The possibility to offer an interface that has different implementations for different objects

OBJECT ORIENTED LANGUAGE Objects Have a state that reflects by current characteristics and conditions and a behaviour that describe the action that it cat execute Classes Groups objects with similar characteristics Data Encapsulation Hidding object data and behaviour Data Abstractization A simplification or a model of a compex concept, process or real word object Inheritance Is a contract between a class and the outside world When a class implements an interface, it promises to provide the behavior published by that interface Polymorphism The possibility to offer an interface that has different implementations for different objects

JAVA PLATFORMS J2SE (Standard Edition) offers support for creating descktop applications and applets Contains the standard set of classes offered by Java J2ME (Micro Edition) offers support for programming on mobile devices J2EE (Enterprise edition) Site Offers support for complex aplications on web. It contains standards for database acessing, servlets, beans, web services, messages queues... http://www.oracle.com/technetwork/java/index.html

JAVA LANGUAGE EVOLUTION

IDE JAVA NetBeans Eclipse https://eclipse.org/ IntelliJ BlueJ developed mainly for educational porpuse

JAVA APPLICATIONS Stand alone Applets Contain main() method Compile javac filename.java Execution java filename Inherates Applet or JApplet class Compile javac filename.java Execution create a HTML page that contains tag APPLET that refers to compiled class appletviewer html.page or open HTML page into a browser Web Start Servlets Inherates class HttpServlet Compile javac filename.java Execution an WAR archive deployed on a WEB Server NOT object of this course

JAVA PROGRAM STRUCTURE [package identifier;] [import class(es);] All code (functions, variable decrations) is included inside a java class. It cann't exist code outside a class. [access specifiers] class/interface ClassName { } //member attributes declaration // member methods declaration If a class is declared to be public it must be placed in a file with same name like the class

FIRST EXAMPLE File: Example.java public class Example { public satic void main (String args[]) { Starting poit of a desktop application in Java. The signature of the method cannot be changed } Compile } Execution Output System.out.println ( Hellow World! ); javac Example.java => Example.class java Example Hello World! The method println() that belong to class out displays a text to standard output

JAVA CODDING GUIDELINES Diffrent standards http://www.oracle.com/technetwork/java/codeconventions- 135099.html https://google.github.io/styleguide/javaguide.html https://www.securecoding.cert.org/confluence/display/java/ Java+Coding+Guidelines

JAVA CODDING GUIDELINES Packages the prefix of a unique package name is always written in alllowercase Classes should be nouns in mixed case with the first letter of each internal word capitalized Interfaces names should be capitalized like class names Methods should be verbs in mixed case with the first letter lowercase, with the first letter of each internal word capitalized Variables should not start with '_' the name starts with lower case each word starts with upper case Constants should be uppercase with words seprated by underscores ('_')

JAVA KEYWORDS Category Keyword Example Primitive Types boolean boolean isopen = true; byte byte i1 = -128; char char c ='A'; short short i =10; int int i = 10; long long i = 7l; long j = 1234567567; float float i =3.4f; double double i = 3.4;

JAVA KEYWORDS Category Keyword Example Control Flow for for(int i=0; i<10; i++){...} do while do{... }while (i<10); while while (true) {... } if if (a<3) {... else } else if (a>5) {... } else {... } switch swich(i) { case case abc :... breack; default default:... }

JAVA KEYWORDS Category Keyword Example Control flow break break label; continue continue label; return return i; try throw catch finally try{... throw new Exception();... } catch (Exception e) {... } finally {... } throws void fct () throws Exception {... }

JAVA KEYWORDS Category Keyword Example Modifier public public int i; protected protected int i; private private int i; static static int i; final final int i; abstract abstract void fct() {... } synchronized synchronized int funct() {... } synchronized (obj) {.. } native native int funct() {... } tansient transient int i; volatile volatile int i;

JAVA KEYWORDS Category Keyword Example Classes class class A {... } interface interface A {... } extends class A extends B {... } implements class A implements B {... } package package ro.uvt.p3; import import java.awt.*; OBS: Some of the modifer keywords can be used together with classes not just with class fields.

JAVA KEYWORDS Category Keyword Example Miscellaneous (true) boolean x = true; (false) (null) boolean x = false; Object obj = null; void void fct( ) {... } this this.x = x; new super instanceof Object obj = new Object(); super ( call base classs constructor ) if (a instanceof String) String s = (String) a;

OPERATORS Category Operator Description Simple Assigment = Simple assigment operator Aritmetic + Additive (also used for String concatenation) - Substraction * Multiplication / Sivision % Remainder Unary + Indicates positive value - Negates a value ++ Increment -- Decrement! Logical complement

OPERATORS Category Operator Description Equality and Relational == Equal to!= Not equal to > Greater then >= Greater then or equal to < Less then <= Less then or equal to Conditional && Conditional AND Conditional OR?: Ternary (if - then - else)

OPERATORS Category Operator Description Type comparation instanceof Simple assigment operator Bitwise and Bit Shift ~ Unary bitwise complement << Signed left shift >> Signed right shift >>> Unsigned right shift & Bitwise AND ^ Bitwise exclusive OR Bitwise inclusive OR

COMMENTS Line comment // Block comment /* */ Java Doc Generates class documentation methotds documentation Standard way to document java projects Java API - https://docs.oracle.com/javase/8/docs/api/

JAVADOC Class comments /** * <h1>add Two Numbers!</h1> * The AddNum program implements an application that * simply adds two given integer numbers and Prints * the output on the screen. * <p> * <b>note:</b> Giving proper comments in your program makes it more * user friendly and it is assumed as a high quality code. * * @author Popescu Ion * @version 1.0 * @since 2016-08-31 */ public class AddNum {... }

JAVADOC Method comments Fields comments /** * This method is used to add two integers. This is * a the simplest form of a class method, just to * show the usage of various javadoc Tags. * @param numa This is the first paramter to addnum method * @param numb This is the second parameter to addnum method * @return int This returns sum of numa and numb. */ public int addnum(int numa, int numb) {... } /** * This is the main method which makes use of addnum method. * @param args Unused. * @return Nothing. * @exception IOException On input error. * @see IOException */ public static void main(string args[]) throws IOException {... }

JAVAD0C. ANNOTATIONS @author @deprecated @exception @param @return @see @since @throws @version...

JAVADOC javadoc tool that allows generation of HTML pages based on javadoc annotations Example run in commned line: javadoc AddNum.java result: a structure similar with official Java API documentation

JAVA UTIL STUFFS String class Display information on standard output Autoboxing Math class Random numbers generation

STRING CLASS java.lang.string stores charctes arrays inmutable objects Exemple the objects of the class cannot be modified see: https://docs.oracle.com/javase/tutorial/essential/concurrency/ imstrat.html String s1 = null; //decleare a null string object Strig s2 = Course Java ; //declares and initialize a string object

IMMUTABLE PATTERN Don't provide "setter" methods methods that modify fields or objects referred to by fields. Make all fields final and private. Don't allow subclasses to override methods. The simplest way to do this is to declare the class as final. A more sophisticated approach is to make the constructor private and construct instances in factory methods. If the instance fields include references to mutable objects, don't allow those objects to be changed: Don't provide methods that modify the mutable objects. Don't share references to the mutable objects. Never store references to external, mutable objects passed to the constructor; if necessary, create copies, and store references to the copies. Similarly, create copies of your internal mutable objects when necessary to avoid returning the originals in your methods.

STRING CLASS Methods concatenation: + String s = Course + ' ' + Java. transformatios: touppercase(), tolowercase() s.tolowercase() comparations: compareto(), equals(), equalsignorecase() s.equalsignorecase( course java. ) search a string into a string: contains(), endswith(), indexof(), lastindexof() operations: split(), replace(), substring() size: length()

DISPLAY TO STANDARD OUTPUT non-formated System.out.print() System.out.print( without new line at the end ); System.out.println() System.out.print( with new line at the end ); formated System.out.println([format], [value list]) System.out.printf("Integer : %d\n",15); System.out.printf("String: %s, integer: %d, float: %.6f", "Hello World",89,9.231435); System.out.printf("%-12s%-12s%s\n","Column 1","Column 2","Column3"); OBS: String can be formatted to be used latter String s = String.format("%-12.5f%.20f", 12.23429837482,9.10212023134);

AUTOBOXING Concept related to generics (templates in C) For each basic type there is a corresponding class Basic Type char int float double boolean byte long short Corresponding Class Characer Integer Float Double Boolean Byte Long Short

AUTOBOXING //before autoboxing Integer iobject = Integer.valueOf(3); int iprimitive = iobject.intvalue() //after java5 Integer iobject = 3; //autobxing - primitive to wrapper conversion int iprimitive = iobject; //unboxing - object to primitive conversion Each class that coresponds to a primitive type contains static methods to transform String objects to primitive types. ie. int i = Integer.parseInt( 123 );

MATHEMATIC OPERATIONS java.util.math Static methods and constants Math.sqrt() Math.abs() Math.cons() Math.random() generates random numbers in [0,1)... Math.PI Math.E

RANDOM NUMBERS GENERATION Using Math class Math.random() generates uniform distributed numbers in [0,1) Using Random class java.util.random In order to user Random class create an object of type Random and call methods to generate random numbers Random r = new Random(); Random class methods setseed(long seed); nextint() - [0, +2 147 483 647) (for 32 bytes) nextint(value) - [0, value) nextdouble() - numbers in [0,1) nextboolean()

NEXT COURSE Classes Objects Object class Acess control specifier fields methods classes