মঙ্গলবার, ৭ জানুয়ারি, ২০১৪

this Constructor


Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by using this.
Using this with a Field
The most common reason for using the this keyword is because a field is shadowed by a method or constructor parameter.
For example, the Point class was written like this
public class Point {
    public int x = 0;
    public int y = 0;
       
    //constructor
    public Point(int a, int b) {
        x = a;
        y = b;
    }
}
but it could have been written like this:
public class Point {
    public int x = 0;
    public int y = 0;
       
    //constructor
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}
Each argument to the constructor shadows one of the object's fields — inside the constructor x is a local copy of the constructor's first argument. To refer to the Point field x, the constructor must use this.x.
Using this with a Constructor
From within a constructor, you can also use the this keyword to call another constructor in the same class. Doing so is called an explicit constructor invocation. Here's another Rectangle class, with a different implementation from the one in the Objects section.
public class Rectangle {
    private int x, y;
    private int width, height;
       
    public Rectangle() {
        this(0, 0, 0, 0);
    }
    public Rectangle(int width, int height) {
        this(0, 0, width, height);
    }
    public Rectangle(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }
    ...
}
This class contains a set of constructors. Each constructor initializes some or all of the rectangle's member variables. The constructors provide a default value for any member variable whose initial value is not provided by an argument. For example, the no-argument constructor calls the four-argument constructor with four 0 values and the two-argument constructor calls the four-argument constructor with two 0 values. As before, the compiler determines which constructor to call, based on the number and the type of arguments.
If present, the invocation of another constructor must be the first line in the constructor.
Summery:
“this” constructor always calls the current method. It is used in constructor for the purpose of the calling of the current method. It is also used for the shortest calling of the method path. But it is the too shortest path of calling a method.



Prime Number Theorem

One of the supreme achievements of 19th-century mathematics was the prime number theorem, and it is worth a brief digression. To begin, designate the number of primes less than or equal to n by π(n). Thus π(10) = 4 because 2, 3, 5, and 7 are the four primes not exceeding 10. Similarly π(25) = 9 and π(100) = 25. Next, consider the proportion of numbers less than or equal to n that are prime—i.e., π (n)/n. Clearly π (10)/10 = 0.40, meaning that 40 percent of the numbers not exceeding 10 are prime. Other proportions are shown in the table.

A pattern is anything but clear, but the prime number theorem identifies one, at least approximately, and thereby provides a rule for the distribution of primes among the whole numbers. The theorem says that, for large n, the proportion π(n)/n is roughly 1/log n, where log n is the natural logarithm of n. This link between primes and logs is nothing short of extraordinary.


One of the first to perceive this was the young Gauss, whose examination of log tables and prime numbers suggested it to his fertile mind. Following Dirichlet’s exploitation of analytic techniques in number theory, Bernhard Riemann (1826–66) and Pafnuty Chebyshev (1821–94) made substantial progress before the prime number theorem was proved in 1896 by Jacques Hadamard (1865–1963) and Charles Jean de la Vallée-Poussin (1866–1962). This brought the 19th century to a triumphant close.

সোমবার, ৬ জানুয়ারি, ২০১৪

Exponents


In the table below, the number 2 is written as a factor repeatedly. The product of factors is also displayed in this table. Suppose that your teacher asked you to Write 2 as a factor one million times for homework. How long do you think that would take?
 Answer :

FactorsProduct of FactorsDescription
2 x 2 =42 is a factor 2 times
2 x 2 x 2 =82 is a factor 3 times
2 x 2 x 2 x 2 =162 is a factor 4 times
2 x 2 x 2 x 2 x 2 =322 is a factor 5 times
2 x 2 x 2 x 2 x 2 x 2 =642 is a factor 6 times
2 x 2 x 2 x 2 x 2 x 2 x 2 =1282 is a factor 7 times
2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 =2562 is a factor 8 times

Writing 2 as a factor one million times would be a very time-consuming and tedious task. A better way to approach this is to use exponents. Exponential notation is an easier way to write a number as a product of many factors.

     

   
BaseExponent :
                        The exponent tells us how many times the base is used as a factor.

For example, to write 2 as a factor one million times, the base is 2, and the exponent is 1,000,000. We write this number in exponential form as follows:

21,000,000  read as two raised to the millionth power

Example 1:Write 2 x 2 x 2 x 2 x 2 using exponents, then read your answer aloud.
Solution:2 x 2 x 2 x 2 x 2  =  252 raised to the fifth power

Let us take another look at the table from above to see how exponents work.
Exponential
Form
Factor
Form
Standard
Form
22 =2 x 2 =4
23 =2 x 2 x 2 =8
24 =2 x 2 x 2 x 2 =16
25 =2 x 2 x 2 x 2 x 2 =32
26 =2 x 2 x 2 x 2 x 2 x 2 =64
27 =2 x 2 x 2 x 2 x 2 x 2 x 2 =128
28 =2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 =256

So far we have only examined numbers with a base of 2. Let's look at some examples of writing exponents where the base is a number other than 2.


Example 2:Write 3 x 3 x 3 x 3 using exponents, then read your answer aloud.
Solution:3 x 3 x 3 x 3  =  343 raised to the fourth power

Example 3:Write 6 x 6 x 6 x 6 x 6 using exponents, then read your answer aloud.
Solution:6 x 6 x 6 x 6 x 6  =  656 raised to the fifth power

Example 4:Write 8 x 8 x 8 x 8 x 8 x 8 x 8 using exponents, then read your answer aloud.
Solution:8 x 8 x 8 x 8 x 8 x 8 x 8  =  878 raised to the seventh power


Example 5:Write 103, 36, and 18 in factor form and in standard form.
Solution:
Exponential
Form
Factor
Form
Standard
Form
10310 x 10 x 101,000
363 x 3 x 3 x 3 x 3 x 3729
181 x 1 x 1 x 1 x 1 x 1 x 1 x 11


The following rules apply to numbers with exponents of  0, 1, 2 and 3:
RuleExample
Any number (except 0) raised to the zero power is equal to 1.1490 = 1
Any number raised to the first power is always equal to itself.81 = 8
If a number is raised to the second power, we say it is squared.32 is read as three squared
If a number is raised to the third power, we say it is cubed.43 is read as four cubed


Summary:Whole numbers can be expressed in standard form, in factor form and in exponential form. Exponential notation makes it easier to write a number as a factor repeatedly. A number written in exponential form is a base raised to an exponent. The exponent tells us how many times the base is used as a factor.