17. 1E-5d is a valid double literal, E2d is not (since it starts with a letter, compiler thinks that it's an identifier).
18. Two types of variables
1. Member variables
- Accessible anywhere in the class.
- Automatically initialized before invoking any constructor.
- Static variables are initialized at class load time.
- Can have the same name as the class.
- Must be initialized explicitly. (Or, compiler will catch it.) Object references can be initialized to null to make the compiler happy. The Following code won't compile.
String tmp;
If (a>0) tmp = "Positive";//Specify else part to make this code compile.
return tmp;
}
- Can have the same name as a member variable, resolution is based on scope.
20. Arrays should be
- Declared. (int[] a; String b[]; Object []c; Size should not be specified now)
- Allocated (constructed). ( a = new int[10]; c = new String[arraysize] )
- initialized. for (int i = 0; i < a.length; a[i++] = 0)
22. Java arrays are the static arrays. Size has to be specified at compile time. Array.length return array's size. (use vector for dynamic purposes ).
23. Array size is never specified with the reference variable, it is always maintained with the array object. It is maintained in array .length, which is a final instance variable .
24. Anonymous arrays can be created and used like this: new int[] {1,2,3} or new int[10]
25. Arrays with zero elements can be created. args array to the main method will be a zero element array if no command parameters are specified. In this case args.length is 0.
26. Comma after the initializer in array declaration is ignored.
27. Array indexes start with 0. Index is an int data type.
28. square brackets can come after data type or before/after variable name. White spaces are fine . Compiler just ignores them.
29. Arrays declared even as member variables also need to be allocated memory explicitly.
30. Once declared and allocated (even for local arrays inside methods), array elements are automatically initialized to the default values.
31. If only declared (not constructed), member array variables default to null, but local array variables will not default to null.
32. Java does not support multidimensional arrays formally, but it supports arrays of arrays. From the specification - "The number of bracket pairs indicates the depth of array nesting." So this can perform as a multidimensional array. (no limit to levels of array nesting)
33. args array's name is not important. args[0] is the first argument. args.length gives no. of arguments.
34. Main method can be overloaded.
35. Main method can be final .
i like it
ReplyDeletephp development