14
Topic 02 : Genesis and Structure of Java DDOOCP

Topic 02: Genesis and Structure of Java

Embed Size (px)

DESCRIPTION

Softwarica Slides

Citation preview

Page 1: Topic 02: Genesis and Structure of Java

Topic 02 : Genesis and Structure of JavaDDOOCP

Page 2: Topic 02: Genesis and Structure of Java

Terminologies

› Interpreter

› Compiler

› Oak

› Bytecode

Page 3: Topic 02: Genesis and Structure of Java

The Java Language

› Java has a block structure

› Java is strongly typed language.

› Java allows the programmer to create their own data types.

› Java is platform independent.

› Instancing a class

Page 4: Topic 02: Genesis and Structure of Java

Test Class

Page 5: Topic 02: Genesis and Structure of Java

Test Class

Page 6: Topic 02: Genesis and Structure of Java

static Modifiers

› A variable or method that is shared by all instances of a class is called a class variable or class method.

› Class variable or class method in Java is declared using statickeyword.

› A class variable/method can be referred either through an instance of the class (like a normal instance variable) or through the full class name e.g. classname.variable or classname.method().

Page 7: Topic 02: Genesis and Structure of Java

static Modifier Example

Page 8: Topic 02: Genesis and Structure of Java

Math class

1. PI

1. abs

2. acos

3. asin

4. atan

5. ceil

6. cos

7. exp

8. floor

9. max

10. min

11. pow

12. random

13. rint

14. round

15. sin

16. sqrt

17. tan

18. toDegrees

19. toRadians

• java.lang.Math• All methods and properties in Math class are static.• Automatically imported.

Page 9: Topic 02: Genesis and Structure of Java

String class

1. charAt

2. compareTo

3. compareToIgnoreCase

4. concat

5. endsWith

6. equals

7. equalsIgnoreCase

8. indexOf

9. lastIndexOf

10. length

11. matches

12. replace

13. replaceAll

14. replaceFirst

15. split

16. startsWith

17. substring

18. toCharArray

19. toLowerCase

20. toString

21. toUpperCase

22. trim

23. valueOf

Page 10: Topic 02: Genesis and Structure of Java

Color Class

› java.awt.Color

› static members

1. BLACK / black

2. BLUE / blue

3. WHITE / white

4. GREEN / green

5. YELLOW / yellow

6. ORANGE / orange

7. RED / red

8. PINK / pink

9. GRAY / gray

10.LIGHT_GRAY

› Constructor

› Color(int r, int g, int b)

› Color(int rgb)

› Color(int r, int g, int b, inta)

› Color(float r, float g, float b)

› Color(float r, float g, float b, float a)

Page 11: Topic 02: Genesis and Structure of Java

Questions

› Generate and display 20 random integers in the range 200 to 500.

› WAP to display following output.

Page 12: Topic 02: Genesis and Structure of Java

Solution contd…

Page 13: Topic 02: Genesis and Structure of Java

Questions

› Build a GUI to include three JButtons and a JTextField.

› Set their titles to RED, Green and BLUE respectively. When a button is clicked, the background colour of the text field should change accordingly.

Page 14: Topic 02: Genesis and Structure of Java

References

› http://docs.oracle.com/javase/7/docs/api/java/awt/Color.html