1 the language essentials


Published on

a series of basic java training courses, this is the first one

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • \n
  • - everything from stratch\n- default package, HelloWorld.java\n > main\n > pure OO\n- named package\n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • try to explain these in HelloWorld.java\n\nfield concept\n
  • - show literals\n- show array usage\n- ArrayCopyDemo without print out for exercise\n
  • - name like 1test\n- field default values, local variable default values\n
  • \n
  • write examples to show equals and ==\n\nString a = “hello”;\nString b = “hello”;\n\na.equals(b);\na == b\n\nString a = new String(“hello”);\nString b = new String(“hello”);\n\na.equals(b);\na == b\n
  • \n
  • \n
  • for (int a : array) {\n}\n
  • \n
  • \n
  • describe when to use static import and not overuse it\n
  • \n
  • \n
  • there is no multi-inherits\n\nshape, rectangle, triangle to show class hierarchy\n
  • \n
  • mention thread safety here\n
  • \n
  • show -cp option when compiling\n
  • \n
  • \n
  • \n
  • \n
  • 1 the language essentials

    1. 1. JAVA BASIC TRAINING I. The Language Essentials
    2. 2. HELLO WORLDHelloWorld.java with default packageHelloWorld.java with named package > javac HelloWorld.java > java HelloWorld
    4. 4. DEVELOPMENT SETUPEditor Choose anyone you prefer But do not rush to IDE Make sure you’ve killed “tab”JDK JDK not JRE 6 not 7Terminal Emulator Unix, Linux, Mac, but sorry M$
    5. 5. NAMING CONVENTIONPackage com.ericsson.ma.javatrainingClass/Interface HelloWorldMethod helloWorld();Variable String helloWorld = “Hello World”;Constant HELLO_WORLDhttp://java.about.com/od/javasyntax/a/nameconventions.htm
    6. 6. CODING STYLESimilar with C++Space instead of tabAlways make block with {}Already defined for EMA development (Eclipse): Get it here: /proj/EMA/env/formatter.xml Or install the all-in-one shot
    7. 7. VARIABLES
    8. 8. VARIABLESInstance VariablesClass VariablesLocal VariablesParameters
    9. 9. VARIABLESPrimitive Types byte (0) short (0) int (0) long (0L) float (0.0f) double (0.0d) boolean (false) char (‘u0000’)ObjectArray is an object must be initialized primitive/objectValue or References
    10. 10. EXERCISESTry some illegal field namesTest default values
    11. 11. OPERATORS
    12. 12. OPERATORSMostly the Same as C++equals and ==instanceof
    13. 13. EXERCISESequals and ==instanceof
    15. 15. CONTROL FLOW STATEMENTSEnhanced for statementNever use labeled break/continueAvoid continue and breakAlways use {} to clarify blocks
    16. 16. EXERCISESEnhanced for statementWrite a small program to give number of days of aspecified month Read from standard input Input like “1”, “2”, “3”, “quit”; if “quit”, terminate
    17. 17. PACKAGE
    18. 18. PACKAGENaming Conventions java and javax are reserved by Java language itself domain name + product nameImporting Package import com.ericsson.ma.javatraining.HelloWorld; import static com.ericsson.ma.javatraining.HelloWorld.say; import com.ericsson.ma.javatraining.*;Managing Source and Class Files Not required to rely on file system to manage source and class files As a universal convention, please rely on file system
    19. 19. EXERCISESRefactor three classes into three different packages com.ericsson.ma.javatraining.Server => c.e.m.j.s com.ericsson.ma.javatraining.Utilities => c.e.m.j.u com.ericsson.ma.javatraining.Client => c.e.m.j.c
    20. 20. CLASS AND OBJECT
    21. 21. CLASS AND OBJECTClass Constructor/”Destructor” Class Hierarchy Modifier Method and FieldObject Instance of Class Garbage Collector
    22. 22. CLASS AND OBJECT Modifier Class Package Subclass World public Y Y Y YAccess Control protected Y Y Y N no modifier Y Y N N private Y N N N
    23. 23. CLASS AND OBJECTClass Members aka, static methods/fields Thread-safetyInstance Members
    24. 24. CLASS AND OBJECTInitializing Fields Instance Fields Class Fields Static Block
    25. 25. EXERCISESWrite a few classes to represent Resource, Tester, Designer Common fields like id, gender, name, unit Test can test while designer can design, so the behaviors of working are differentThe following code creates one array and one string object. How manyreferences to those objects exist after the code executes? Is eitherobject eligible for garbage collection?...String[] students = new String[10];String studentName = "Peter Parker";students[0] = studentName;studentName = null;...
    26. 26. ANNOTATION
    27. 27. ANNOTATIONInformation for the Compiler Used by compiler to detect errors and suppress warningsCompiler-time and Deployment-time Processing Software tools can process annotation to generate XML, files, and so onRuntime Processing Available to be examined at runtime
    28. 28. EXERCISESTry @Override in previous test/designer exerciseTry @SuppressWarnings
    29. 29. HOMEWORKFinish all sections of http://t.cn/Ste59JStrongly recommend http://t.cn/SteofWWrite an address book program Store name, address, phone number Possbile to search by phone number, either complete or partial