Java data types ppt

java data types and operators ppt and also java data types variables and arrays ppt
Dr.BenjaminClark Profile Pic
Dr.BenjaminClark,United States,Teacher
Published Date:21-07-2017
Your Website URL(Optional)
Comment
3.1 Using Data Types Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2002–2010 · 3/18/11 9:05 AM A Foundation for Programming any program you might want to write create your own objects data types functions and modules graphics, sound, and image I/O arrays conditionals and loops Math text I/O primitive data types assignment statements 2 Data Types Data type. Set of values and operations on those values. Primitive types. Ops directly translate to machine instructions. Data Type Set of Values Operations boolean true, false not, and, or, xor 31 31 int -2 to 2 -1 add, subtract, multiply 64 double any of 2 possible reals add, subtract, multiply We want to write programs that process other types of data.   Colors, pictures, strings, input streams, …   Complex numbers, vectors, matrices, polynomials, …   Points, polygons, charged particles, celestial bodies, … 3 Objects Object. Holds a data type value; variable name refers to object. Impact. Enables us to create our own data types; define operations on them; and integrate into our programs. Data Type Set of Values Operations Color 24 bits get red component, brighten Picture 2D array of colors get/set color of pixel (i, j) String sequence of characters length, substring, compare 4 Constructors and Methods To construct a new object: Use keyword new and name of data type. To apply an operation: Use name of object, the dot operator, and the name of the method. 5 Image Processing Color Data Type Color. A sensation in the eye from electromagnetic radiation. 3 Set of values. RGB representation 256 possible values, which quantify the amount of red, green, and blue, each on a scale of 0 to 255. R G B Color 255 0 0 0 255 0 0 0 255 255 255 255 0 0 0 255 0 255 105 105 105 7 Color Data Type Color. A sensation in the eye from electromagnetic radiation. 3 Set of values. RGB representation 256 possible values, which quantify the amount of red, green, and blue, each on a scale of 0 to 255. API. Application Programming Interface. http://download.oracle.com/javase/6/docs/api/java/awt/Color.html 8 Albers Squares Josef Albers. Revolutionized the way people think about color. Homage to the Square by Josef Albers (1949-1975) 9 Albers Squares Josef Albers. Revolutionized the way people think about color. gray blue % java AlbersSquares 9 90 166 100 100 100 10 Using Colors in Java to access Color library import java.awt.Color; public class AlbersSquares public static void main(String args) int r1 = Integer.parseInt(args0); int g1 = Integer.parseInt(args1); first color int b1 = Integer.parseInt(args2); Color c1 = new Color(r1, g1, b1); int r2 = Integer.parseInt(args3); int g2 = Integer.parseInt(args4); second color int b2 = Integer.parseInt(args5); Color c2 = new Color(r2, g2, b2); StdDraw.setPenColor(c1); first square StdDraw.filledSquare(.25, .5, .2); StdDraw.setPenColor(c2); StdDraw.filledSquare(.25, .5, .1); StdDraw.setPenColor(c2); StdDraw.filledSquare(.75, .5, .2); second square StdDraw.setPenColor(c1); StdDraw.filledSquare(.75, .5, .1); 11 Monochrome Luminance Monochrome luminance. Effective brightness of a color. NTSC formula. Y = 0.299r + 0.587g + 0.114b. import java.awt.Color; public class Luminance public static double lum(Color c) int r = c.getRed(); int g = c.getGreen(); int b = c.getBlue(); return .299r + .587g + .114b; 12 Color Compatibility Q. Which font colors will be most readable with which background colors on computer and cell phone screens? A. Rule of thumb: difference in luminance should be 128. 256 208 105 47 28 14 public static boolean compatible(Color a, Color b) return Math.abs(lum(a) - lum(b)) = 128.0; 13 Grayscale Grayscale. When all three R, G, and B values are the same, resulting color is on grayscale from 0 (black) to 255 (white). Convert to grayscale. Use luminance to determine value. public static Color toGray(Color c) int y = (int) Math.round(lum(c)); Color gray = new Color(y, y, y); return gray; round double to nearest int Bottom line. We are writing programs that manipulate color. 14 OOP Context for Color Possible memory representation. D0 D1 D2 D3 D4 D5 D6 D7 D8 255 0 255 0 0 0 105 105 105 A0 B0 gray magenta D0 D6 memory address ("pointer") Object reference is analogous to variable name.   We can manipulate the value that it holds.   We can pass it to (or return it from) a method. 15 References René Magritte. "This is not a pipe." Java. This is not a color. Color sienna = new Color(160, 82, 45); Color c = sienna.darker(); OOP. Natural vehicle for studying abstract models of the real world. 16 Picture Data Type Raster graphics. Basis for image processing. Set of values. 2D array of Color objects (pixels). API. 18 Image Processing: Grayscale Filter Goal. Convert color image to grayscale according to luminance formula. import java.awt.Color; public class Grayscale public static void main(String args) Picture pic = new Picture(args0); for (int x = 0; x pic.width(); x++) for (int y = 0; y pic.height(); y++) Color color = pic.get(x, y); from before Color gray = Luminance.toGray(color); pic.set(x, y, gray); pic.show(); 19 Image Processing: Grayscale Filter Goal. Convert color image to grayscale according to luminance formula. mandrill.jpg % java Grayscale mandrill.jpg 20 Image Processing: Scaling Filter Goal. Shrink or enlarge an image to desired size. Downscaling. To shrink, delete half the rows and columns. Upscaling. To enlarge, replace each pixel by 4 copies. 21