Example: stock market

Java certification success, Part 1: SCJP

java certification success , part 1:SCJPP resented by developerWorks, your source for great of ContentsIf you're viewing this document online, you can click any of the topics below to link directly to that Before you Declarations and access Flow control, assertions, and exception Garbage Language Operators and Overriding, overloading, and object Fundamental classes in the The Collections Summary and certification success , part 1: SCJPPage 1 of 50 Section 1. Before you startAbout this tutorialThis tutorial is a guide to help you become a Sun certified java programmer.

Section 2. Declarations and access control Arrays Arrays are dynamically created objects in Java code. An array can hold a number of variables of the same type.

Tags:

  Code, Success, Part, Part 1, Certifications, Java, Java certification success, Scjp, Java code

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Java certification success, Part 1: SCJP

1 java certification success , part 1:SCJPP resented by developerWorks, your source for great of ContentsIf you're viewing this document online, you can click any of the topics below to link directly to that Before you Declarations and access Flow control, assertions, and exception Garbage Language Operators and Overriding, overloading, and object Fundamental classes in the The Collections Summary and certification success , part 1: SCJPPage 1 of 50 Section 1. Before you startAbout this tutorialThis tutorial is a guide to help you become a Sun certified java programmer.

2 It is organizedin the same way as the Sun Certified java Programmer ( scjp ) exam and provides adetailed overview of all of the exam's main objectives. Throughout the tutorial, simpleexamples are provided to illustrate the important concepts covered in the the end of each section, exercises are provided to test your knowledge of the mainconcepts covered in that section. At the end of the tutorial, useful resources, such asrecommended books, articles, tutorials, training, and specifications for the exam, are you are a programmer interested in enhancing your skills and your resume, this tutorial isfor you.

3 The tutorial assumes you have familiarity with the java programming the scjp examThe scjp exam is the first in a series of java certification exams offered by SunMicrosystems, and for many programmers it is the first step to becoming established as acompetent java exam tests the knowledge of java fundamentals and requires in-depth knowledge of thesyntax and semantics of the language. Even experienced java programmers can benefitfrom preparing for the scjp exam. You get to learn very subtle and useful tips you might nothave been aware of, even after many years of java the authorPradeep Chopra is the cofounder ofWhizlabs Software, a global leader in IT skillassessment and certification exam preparation.

4 A graduate of the Indian Institute ofTechnology, Delhi, Pradeep has been consulting individuals and organizations across theglobe on the values and benefits of IT technical questions or comments about the content of this tutorial, contact the author,Pradeep Chopra, click Feedback at the top of any by developerWorks, your source for great tutorialsPage 2 of 50 java certification success , part 1: SCJPS ection 2. Declarations and access controlArraysArrays are dynamically created objects in java code .

5 An array can hold a number ofvariables of the same type. The variables can be primitives or object references; an arraycan even contain other array variablesWhen we declare an array variable, the code creates a variable that can hold the referenceto an array object. It does not create the array object or allocate space for array elements. Itis illegal to specify the size of an array during declaration. The square brackets may appearas part of the type at the beginning of the declaration or as part of the array identifier:int[] i; // array of intbyte b[]; // array of byteObject[] o, // array of Objectshort s[][]; // array of arrays of shortConstructing arraysYou can use thenewoperator to construct an array.

6 The size of the array and type ofelements it will hold have to be included. In the case of multidimensional arrays, you mayspecify the size only for the first dimension:int [] marks = new int[100];String[][] s = new String[3][];Initializing arraysAn array initializer is written as a comma-separated list of expressions, enclosed within curlybraces:String s[] = { new String("apple"),new String("mango") };int i[][] = { {1, 2}, {3,4} };An array can also be initialized using a loop:int i[] = new int[5];for(int j = 0; j < ;j++){i[j] = j.}

7 }Accessing array elementsArrays are indexed beginning with 0 and ending withn-1, wherenis the array size. To getthe array size, use the array instance variable calledlength. If you attempt to access anindex value outside the range 0 ton-1, by developerWorks, your source for great certification success , part 1: SCJPPage 3 of 50 Declaring classes, variables, and methodsNow let's look at ways we can modify classes, methods, and variables. There are two kindsof modifiers -- access modifiers and non-access modifiers.

8 The access modifiers allow us torestrict access or provide more access to our modifiersThe access modifiers available arepublic,private, andprotected. However, atop-level class can have only public and default access levels. If no access modifier isspecified, the class will have default access. Only classes within the same package can seea class with default access. When a class is declared as public, all the classes from otherpackages can access 's see the effect of some non-access modifiers on classes.

9 Thefinalkeyword (seeJavakeywords and identifierson page 21 for more on keywords) does not allow the class to beextended. Anabstractclass cannot be instantiated, but can be extended by subclasses:public final class Apple {..}class GreenApple extends Apple {} // Not allowed, compile time errorMethod and variable modifiersAll the access modifiers can be used for members of a class. The private members can onlybe accessed from inside the class. The protected members can only be accessed by classesin the same package or subclasses of the class.

10 The public members can be accessed byany other there is no access modifier specified, these members will have default access and onlyother classes in the same package can access let's explore other modifiers that can be applied to member declarations. Some of themcan be applied only to methods while some can be applied only to variables, as illustrated inthe figure below:Figure 1. Modifiers for methods and by developerWorks, your source for great tutorialsPage 4 of 50 java certification success , part 1: SCJPA synchronizedmethod can be accessed by only one thread at a cannot be serialized.


Related search queries