Class declaration and java source file.
- Only “one” top-level public class is allowed per java source file.
- The name of the java source file and the name of the top-level public class MUST be the same.
- If no public class is there in a file, after compiling separate class files will be created for all classes in the file.
- Package statement, import statements and class definition MUST appear in the order given.
Keywords and Identifiers
- Keywords are always in a lower case.
- Some keywords: const, goto, strictfp, and volatile
- Identifiers must start with either letter, $ or _ (underscore) and can have letter, $, _ or digits in it.
- no keyword is allowed as identifiers
abstract | do | import | public | transient |
boolean | double | instanceof | return | try |
break | else | int | short | void |
byte | extends | interface | static | volatile |
case | final | long | super | while |
catch | finally | native | switch | |
char | float | new | synchronized | |
class | for | package | this | |
continue | if | private | throw | |
default | implements | protected | throws |
Default Values, Local Variables
- Each primitive data type has a default value specified. Variable of primitive data type may be initialized
- Only class member variables are automatically initialized. Method variables need explicit initialization
- Local variables (also known as automatic variables) are declared in methods and in code blocks
- Automatic variables are not automatically initialized
- local variables should be explicitly initialized before first use. These are automatically destroyed when they go out of scope
Arrays
- Fixed-sized ordered collection of homogeneous data elements
int[] ints; // array declaration
ints = new ints[25]; // array construction at runtime. - Array declared, constructed and initialized at the same time.
int[] ints = {1,2,3,4,5}; // array declaration, - An array of primitive data type created using the new keyword is automatically initialized. Each array element is initialized to its default value.
For example,
char[] arrayOfChars = new char[10]; - Array of object references: An array of object references created using the new keyword is also initialized. Each array element is initialized to its default value, i.e. null.
String[] names = new String[10]; - length is a property of array (and not a method)
- java.lang.Object is the superclass of an array
Argument passing during method calls
- Always a copy of argument value is passed to calling method
- Arguments of primitive data types: first, a copy of the passing variable is made and then it is passed. The original copy remains unaffected
- Object reference as an argument: A copy of object reference is passed for method calls. It still points to the same object. The original copy is affected.
From: http://sitestree.com/?p=4862
Categories:Java Short Notes, SCJP
Tags:
Post Data:2008-07-28 12:18:41
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada