Wednesday 29 August 2012

Comments, Case Sensitivity, Collections and Loops


The previous tutorials showed variable declarations, conditional, and assignment statements. In this tutorial, you receive a tour de force through much of the Apex syntax. Use the Developer Console to execute all of the examples in this tutorial.
Here is an overview of what this tutorial covers.
  • Comments: Comments are lines of text that you add to your code to describe what it does.
  • Case sensitivity: Apex is case insensitive.
  • Collections: Apex supports various types of collections—arrays, lists, sets, and maps.
  • Loops: Apex supports do-while, while, and for loops for executing code repeatedly.
Comments:

Comments are lines of text that you add to your code to describe what it does. Comments aren’t executable code. It’s good practice to annotate your code with comments as necessary. This makes the code easier to understand and more maintainable. Apex has two forms of comments. The first uses the // token to mark everything on the same line to the right of the token as a comment. The second encloses a block of text, possibly across multiple lines, between the /* and */ tokens.
Execute the following. Only the debug statement runs:
System.debug ('I will execute');   // This comment is ignored. 
    
/*
 I am a large comment, completely ignored as well.
*/ 
Case Sensitivity:
Unlike Java, Apex is case insensitive. This means that all Apex code, including method names, class names, variable names and keywords, can be written without regard to case. For example, Integer myVar; and integeR MYVAR; are equivalent statements. All of the following statements print out today’s date using the System.todaymethod when you execute them in the Developer Console:
System.debug ( System.today() );
System.debug ( System.Today() );
System.debug ( SySteM.Today() );
A good practice is for class names to start with an uppercase letter and method names to start with a lowercase letter.


No comments:

Post a Comment