1 Windows Programming with Java Oğuzhan Öztaş. 2 Java Books -Java Examples in a nutshell O’REILLY -Java Cookbook O’REILLY -Java 2 Core Language Little.

Slides:



Advertisements
Similar presentations
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Advertisements

Computer Science Dept. Fall 2003 Object models Object models describe the system in terms of object classes An object class is an abstraction over a set.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Object Oriented Programming in JAVA
OBJECT-ORIENTED PROGRAMMING CONCEPTS (Review). What is an Object? What is an Object? Objects have states and behaviors. Example: A dog has states - color,
Lab#1 (14/3/1431h) Introduction To java programming cs425
What is a Programming Language? The computer operates using binary numbers. The computer only knows about 1’s and 0’s. Humans can also use 1’s and 0’s,
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Object Orientated Programming
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
OOP & JAVA. HelloWorld.java /** * The HelloWorld class is an application that * displays "Hello World!" to the standard output. */ public class HelloWorld.
What is an object? Your dog, your desk, your television set, your bicycle. Real-world objects share two characteristics: They all have state and behavior;
Created by Ron Beglieter (based on the Java Tutorial) 1 What is Java? Java technology is both a programming language and a platform; Programming Language.
Introduction to Alice Basics : What is Alice? Object Oriented Definitions What Does it Look Like? Where Can I Use it?
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Object-oriented Programming Concepts
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Introduction to Java.
Getting Started What is Java? A programming language –Fully buzzword-compliant: A simple, object oriented, distributed, interpreted, robust, secure,
2015/8/221 Data Types & Operators Lecture from (Chapter 3,4)
Introducing Java.
Lecture 1 Introduction to Java MIT- AITI 2004 What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word.
+ Java vs. Javascript Jessi Style. + Java Compiled Can stand on its own Written once, run anywhere Two-stage debugging Java is an Object Oriented Programming.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Advanced Java New York University School of Continuing and Professional Studies.
About the Java  Java technology is both a programming language and a platform –The Java Programming Language A high-level language that can be characterized.
Object Oriented Programming Concepts Fatih University Ceng-104-A Introduction to Object Oriented Programming Harun Reşit Zafer This is a slide version.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
DAT602 Database Application Development Lecture 5 JAVA Review.
Why Java? A brief introduction to Java and its features Prepared by Mithat Konar.
Lecture 1 Introduction to Java MIT-AITI Ethiopia 2004.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
POS 406 Java Technology And Beginning Java Code
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
Lecture.1: Getting Started With Java Jiang (Jen) ZHENG May 9 th, 2005.
Object Oriented Programming Concepts. Object ► An object is a software bundle of related state and behavior. ► Software objects are often used to model.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Lecture 1. Introduction to Programming and Java MIT- AITI 2003.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
ITP 109 Week 2 Trina Gregory Introduction to Java.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
University of Central Florida COP 3330 Object Oriented Programming
Internet and Java Foundations, Programming and Practice
University of Central Florida COP 3330 Object Oriented Programming
Lecture 5 from (Chapter 4, pages 73 to 96)
Java Applets.
(Computer fundamental Lab)
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Introducing Java.
In this class, we will cover:
Chap 1. Getting Started Objectives
Presentation transcript:

1 Windows Programming with Java Oğuzhan Öztaş

2 Java Books -Java Examples in a nutshell O’REILLY -Java Cookbook O’REILLY -Java 2 Core Language Little Black Book Paraglyph Press -core java 2, volume 1 fundamentals 5th The Sun Microsystems Press - Prentice Hall -Java Tutorial 3th Edition - A Short Course on the Basics (2000) - Addison Wesley -Javascript Bible Gold.Edition Hungry Minder

3 Contents what is java? How java programs work? Standalone java program in DOS mode Standalone java program in Windows mode Java Applets Java Events Graphical User Interface Input/Output Database Access with SQL

4 Java Features independent from operating systems Object-oriented language internet programming Pocet PC and mobile phone programming And new technology

5 Java Features Get started quickly: Although the Java programming language is a powerful object- oriented language, it's easy to learn, especially for programmers already familiar with C or C++. Write less code: Comparisons of program metrics (class counts, method counts, and so on) suggest that a program written in the Java programming language can be four times smaller than the same program in C++. Write better code: The Java programming language encourages good coding practices, and its garbage collection helps you avoid memory leaks. Its object orientation, its JavaBeans component architecture, and its wide-ranging, extensible API let you reuse other people's code and introduce fewer bugs. Develop programs more quickly: Your development time may be twice as fast as writing the same program in C++. Why? You write fewer lines of code with the Java programming language, and it is a simpler programming language than C++. Avoid platform dependencies with 100% Pure Java™: You can keep your program portable by avoiding the use of libraries written in other languages. The 100% Pure Java™ Product Certification Program has a repository of historical process manuals, white papers, brochures, and similar materials online at: Write once, run anywhere: Because 100% Pure Java programs are compiled into machine-independent bytecodes, they run consistently on any Java platform. Distribute software more easily: You can easily upgrade certain types of programs, such as applets, from a central server. Applets take advantage of the feature of allowing new classes to be loaded "on the fly," without recompiling the entire program.

6 independent from operating systems

7 How java programs work?

8 1. Write simple java program using any editor. 2. Save it to the directory with giving a name. 3. The name as “sample.java”. 4. in the command line write (in two step) Javac sample.java Java sample

9 Java Commands Java Compiler : javac compiles Java programs into bytecodes Java Interpreter : java executes Java bytecodes Java Runtime Interpreter : jre for end-users not requiring all of the development- related options available with the java tool Java AppletViewer : appletviewer for testing and running applets

10 A simple java program public class Hello { public static void main(String[] args) { system.out.println(“Hello World!”); }

11 To compile and run it C:\> Javac Hello.java C:\> Java Hello Hello World!

12 Java applet First, start NotePad. In a new document, type the following code: import java.applet.Applet; import java.awt.Graphics; public class HelloWorld extends Applet { public void paint(Graphics g) { // Display "Hello world!" g.drawString("Hello world!", 50, 25); }

13 Java applet Second, you also need an HTML file to accompany your applet. Type the following code into a new NotePad document: A Simple Program Here is the output of my program: Save this code to a file called Hello.html.

14 What Is an Object? Objects are key to understanding object-oriented technology. You can look around you now and see many examples of real-world objects: your dog, your desk, your television set, your bicycle. These real-world objects share two characteristics: They all have state and behavior. For example, dogs have state (name, color, breed, hungry) and behavior (barking, fetching, and wagging tail). Bicycles have state (current gear, current pedal cadence, two wheels, number of gears) and behavior (braking, accelerating, slowing down, changing gears). Software objects are modeled after real-world objects in that they too have state and behavior. A software object maintains its state in one or more variables. A variable is an item of data named by an identifier. A software object implements its behavior with methods. A method is a function (subroutine) associated with an object. Definition An object is a software bundle of variables and related methods.

15 What Is a Class? In the real world, you often have many objects of the same kind. For example, your bicycle is just one of many bicycles in the world. Using object-oriented terminology, we say that your bicycle object is an instance of the class of objects known as bicycles. Bicycles have some state (current gear, current cadence, two wheels) and behavior (change gears, brake) in common. However, each bicycle's state is independent of and can be different from that of other bicycles. When building bicycles, manufacturers take advantage of the fact that bicycles share characteristics, building many bicycles from the same blueprint. It would be very inefficient to produce a new blueprint for every individual bicycle manufactured. In object-oriented software, it's also possible to have many objects of the same kind that share characteristics: rectangles, employee records, video clips, and so on. Like the bicycle manufacturers, you can take advantage of the fact that objects of the same kind are similar and you can create a blueprint for those objects. A software blueprint for objects is called a class Definition: A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind.

16 What Is Inheritance? Generally speaking, objects are defined in terms of classes. You know a lot about an object by knowing its class. Even if you don't know what a penny-farthing is, if I told you it was a bicycle, you would know that it had two wheels, handle bars, and pedals. Object-oriented systems take this a step further and allow classes to be defined in terms of other classes. For example, mountain bikes, racing bikes, and tandems are all kinds of bicycles. In object-oriented terminology, mountain bikes, racing bikes, and tandems are all subclasses of the bicycle class. Similarly, the bicycle class is the superclass of mountain bikes, racing bikes, and tandems. This relationship is shown in Figure.

17 What Is Inheritance?

18 Java integer types

19 Floating-point types

20 Special characters

21 Variables In Java, every variable has a type. You declare a variable by placing the type first, followed by the name of the variable. Here are some examples: double salary; int vacationDays; long earthPopulation; char yesChar; boolean done; Notice the semicolon at the end of each declaration. The semicolon is necessary because a declaration is a complete Java statement.

22 Assignments and Initializations int vacationDays; // this is a declaration vacationDays = 12; // this is an assignment int vacationDays = 12; // this is an initialization

23 Operators x += 4; is equivalent to x = x + 4; (In general, place the operator to the left of the = sign, such as *= or %=.)

24 Shortcut Increment and Decrement Operators

25 Increment and Decrement Operators int m = 7; int n = 7; int a = 2 * ++m; // now a is 16, m is 8 int b = 2 * n++; // now b is 14, n is 8

26 Relational Operators

27 Conditional Operators

28 Relational and boolean Operators uses && for the logical “and” operator and || for the logical “or” operator. To test for equality you use a double equal sign, ==. Use a != for inequality. you have the usual (greater than), = (greater than or equal) operators. Java supports the ternary ?: operator that is occasionally useful. The expression condition ? e1 : e2 x < y ? x : y

29 Mathematical Functions and Constants Mathematical functions in Math class. (import java.math.*;) double x = 4; y = Math.sqrt(x); System.out.println(y); // prints 2.0 double y = Math.pow(x, a);

30 Mathematical Functions and Constants The Math class supplies the usual trigonometric functions Math.sin Math.cos Math.tan Math.atan Math.atan2 and the exponential function and its inverse, the natural log: Math.exp Math.log Finally, there are two constants Math.PI Math.E

31 Legal conversions between numeric types

32 Casts in a formula, you can redefine any variables type. double x = 9.997; int nx = (int)x;

33 Round function If you want to round a floating-point number to the nearest integer (which is the more useful operation in most cases), use the Math.round method: double x = 9.997; int nx = (int)Math.round(x);

34 Parentheses and Operator Hierarchy

35 Parentheses and Operator Hierarchy If no parentheses are used, operations are performed in the hierarchical order indicated. Operators on the same level are processed from left to right, except for those that are right associative, as indicated in the table.

36 Strings String e = ""; // an empty string String greeting = "Hello"; String expletive = "Expletive"; String PG13 = "deleted"; String message = expletive + PG13; int age = 13; String rating = "PG" + age; This feature is commonly used in output statements; for example, System.out.println("The answer is " + answer);

37 Substring,length String greeting = "Hello"; String s = greeting.substring(0, 4); // is ‘Hell’ int n = greeting.length(); // is 5. char last = greeting.charAt(4); // fourth is 'o' greeting = greeting.substring(0, 4) + "!";// is ‘Hell!’

38 Formatting Output The NumberFormat class in the java.text package has three methods that yield standard formatters for (import java.text.*;) numbers currency values percentage values These functions are in the same order: NumberFormat.getNumberInstance() NumberFormat.getCurrencyInstance() NumberFormat.getPercentInstance()

39 Formatting Output x = / 3.0; System.out.print(x); prints That is a problem if you want to display, for example, dollars and cents. 3, $3, ,333% double x = / 3.0; NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMaximumFractionDigits(4); formatter.setMinimumIntegerDigits(6); String s = formatter.format(x); // the string "003, "