basics of java -...
TRANSCRIPT
![Page 1: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/1.jpg)
Basics of Java
Rabeea Ahmed
![Page 2: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/2.jpg)
Overview
1.History of Java
2.Using Java for CS50 Final Projects
3.Writing, Compiling and Running .java using Eclipse IDE
4.Coding and Debugging in Java
5.Other Resources
![Page 3: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/3.jpg)
![Page 4: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/4.jpg)
Compiling Java Programs
Step 1: Compiler turns Java code into byte-code
NOTE: byte-code is machine language of JVM.
Step 2: Interpreter turns byte-code into machine code for all
![Page 5: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/5.jpg)
WHY?
![Page 6: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/6.jpg)
Portability: write once, run everywhere
●Once compiled, byte-code can be sent over the Internet.
● No need to recompile if on another computer.
●Operating System differences bypassed
![Page 7: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/7.jpg)
uses of java
1. Internet Applications
2. Android App. Development
3. JavaServer Pages (JSP)
4.Mobile Information Devices Profile (MIDP)
![Page 8: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/8.jpg)
Using Eclipse IDE for Java
● The Integrated Development Environment (eg. Netbeans)
● Compiles upon saving (no need for Terminal commands)
Steps:
#1. Download Java Runtime Environment
#2. Download Eclipse itself
![Page 9: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/9.jpg)
... Let the coding begin
![Page 10: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/10.jpg)
Object Oriented Programming Language
● Java consists of○ Classes
■ descriptions of objects (blueprint)■ describes structure containing methods.
○Object ■ realization of what the class described■ instantiazed class■ have associated methods
![Page 11: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/11.jpg)
Remember:
Java is an object oriented programing language System.out.println("Hello, world!");
Class name and file name should be fully IDENTICAL
![Page 12: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/12.jpg)
Data Types in Java
Class Types: Blue-prints for objects Specifies how data included in a class is dealt with Eg. String
Primitive Types
Eg: Variables Value is a single number or letter.
![Page 13: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/13.jpg)
Primitive Data Types
Type Name Kind (of Value) Memory
byte integer 1 byte
short integer 2 bytes
int integer 8 bytes
float floating-point 4 bytes
double floating-point 8 bytes
char single-char 2 bytes
boolean true/false 1 bit
![Page 14: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/14.jpg)
STYLE: Legality of Identifier Names
Class Type:
YourBook MyFullName
Primitive Type:
myFirstInitial teamNumber days_Per_Week
![Page 15: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/15.jpg)
Constants
public static final Type Variable = Constant public static final double PI = 3.14159;
Type Variable = Constant; double PI = 3.14159;
![Page 16: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/16.jpg)
Type Casting in Java
int speed = 4.42; int points = (int) speed;
NOT: int points = speed;
![Page 17: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/17.jpg)
Type Casting in Java
double speed = 4.42; int points = (int) speed;
NOT: int points = speed;
![Page 18: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/18.jpg)
Char To Int
char symbol = '7'; System.out.println((int)symbol);
![Page 19: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/19.jpg)
Order of Precedence in Java
1. Unary operations +, - , !, ++ and --
2. Binary arithmetic operations *, / and %
3. Binary arithmetic operations + and -
![Page 20: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/20.jpg)
Flow of Control
● Very similar to C
● if-else, while, do-while all exist in Java
● ==, !=, <= and >= are same as in C
● System.exit (0) vs break;
![Page 21: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/21.jpg)
Making Final Projects
Make your own objects
![Page 22: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/22.jpg)
Making Objects For Yourself
Use constructors and methods (either public or private)
Use multiple classes made within the same directory.
These classes can be re-usable!
![Page 23: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/23.jpg)
Resources:
1) Java Class Library
2) Java: An Introduction to Problem Solving and Programming By: Walter Savitch (see Cabot Library)
3) Java Programming: A Back to Basics Approach By: Stuart Reges and Marty Stepp
4) Email me at: [email protected]
![Page 24: Basics of Java - d2o9nyf4hwsci4.cloudfront.netd2o9nyf4hwsci4.cloudfront.net/2011/fall/seminars/basics_of_Java/b… · 1) Java Class Library 2) Java: An Introduction to Problem Solving](https://reader034.vdocuments.us/reader034/viewer/2022051808/600c1cebad704716e328af06/html5/thumbnails/24.jpg)
Thank You!