Java Tutorial

by Dinesh Thakur Category: Java Methods

Accessor methods are used for initializing and accessing the value of instance variables. The value of these instance variables can be used further in the program. For creating accessor methods, it is required to create two methods among which one method is used to initialize the value and other is used to retrieve the value. An accessor method makes the program more readable and understandable. Moreover, accessor methods are similar to any other method, as can be seen from Program.

 
by Dinesh Thakur Category: Java Methods

To create a class variable or method, include the word static in front of the method's name. The modifier static typically comes after any protection modifiers. Given below is an example that illustrates how a class variable may be created in a program.

 
by Dinesh Thakur Category: Java Methods

Since the string variable str is static, it is initialized to "This is second line displayed" (static variables are initialized before an object is initiated). Then, the static block is executed which will invoke the disp() method displaying the message: "This is first line displayed". Static() method can be invoked without the need of any object. In main(), again disp() method is called with the string str (This is second line displayed). After that an object SMV is made, and it will get a member str2 initialized to "This is last line displayed". Then disp() is called with SMV.str2 which displays: This is last line displayed on the screen

 
 
by Dinesh Thakur Category: Java Methods

A Java method is a collection of statements, all performing a particular operation.  Let’s say that you were calling the method called System.out.println(); Java executes some different statements that print a message to your console.  We’re going to look at the creation of methods or, as they often called, functions.

 
by Dinesh Thakur Category: Java Methods

Tail recursion occurring when the recursive call is at the end of the recursive instruction. This eliminates the potential problem of stack overflow. A call is tail recursive if nothing has to be done after the call returns. i.e. when the call returns, the returned value is immediately returned from the calling method.

 
by Dinesh Thakur Category: Java 2D Example

Point2D class does not draw anything; it is the representation of points Java2D. But yes you can draw shapes from points. Following is at able that lists some of the Constructors and methods of Point2D class:

 
by Dinesh Thakur Category: Java 2D Example

Another way is to build figures using GeneralPath class, which but also inherits from Shapeisan interface, but a class. This class allows  define a shape by a sequence oflines that can be established through  functions in the following table:

 
by Dinesh Thakur Category: Java 2D Example

The class that is used to draw rectangles and squares is the Rectangle2D. The constructor specifies the first two parameters of the corner position upper left relative to the coordinate system of the window.

 
by Dinesh Thakur Category: Java 2D Example

Draw a straight line is one of the easiest things to do with Java2D. This is achieved through the Line2D class, whose constructor accepts four parameters, namely the coordinates of the start and end respectively.

 
by Dinesh Thakur Category: Java 2D Example

The QuadCurve2D class lets build a curved segment based on mathematical equations. The curve generated is also called curve quadratic Bezier and based on a very simple idea is to establish two points that define the ends of a curved segment and a third point, called checkpoint that allows "stretching" more or less the curvature of the segment.

 
by Dinesh Thakur Category: Java 2D Example

With this code we will study how text is drawn on a any image.

 
by Dinesh Thakur Category: Java 2D Example

The ellipses or ovals are drawn by Ellipse2D class.This requires you defined to be a rectangle enclosing the boundaries between the ellipse.There the concept of a circle, so that it must be obtained by an ellipse enclosed in a square.

 
by Dinesh Thakur Category: Java 2D Example

The class allows Arc2D draw an arc of an ellipse or a circle. For this, first the rectangle that contains the ellipse whose arc you want to draw is defined ; then assuming that the center of the rectangle sets the point (0,0) of a Cartesian coordinate axis , the angles start and end are specified the arc in degrees . Finally , indicate whether you want to close the bow joining ends or not. This closure can be of three types :

 
by Dinesh Thakur Category: Java 2D Example

This code can be seen as built a clipping path with the content of the text area of the word "Java " located in the middle of the window.In the drawn area can be seen as the image is painted behind the chain. As seen, the effect is very colorful and easy to perform.

 
by Dinesh Thakur Category: Java 2D Example

CubicCurve2D which also shows the segments joining  the ends with the points control and the set together. An example of use appears in the following code, which also have highlighted the four reference points. The result can be seen in CubicCurve2D Java Example.

 
by Dinesh Thakur Category: Java 2D Example

much more powerful mechanism for drawing text is provided  the TextLayout class.This class not only allows you to draw text in a similar way  to as was done be fore but also provides a number of methods that  let youk now what is specific to draw features.

 
by Dinesh Thakur Category: Java 2D Example

In this example we show how the Set operations going to make a Subtraction of 2 circles . Subtraction examples how the code as follows:

 
by Dinesh Thakur Category: Java 2D Example

In this example we show how the Set operations going to make a Addition of 2 circles. An example show the code below:

 


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.