iPhone – UIAlertView example in iphone

This is an simple UIAlertView example.UIAlertView is used for the notification purpose.

Step 1: Start the program by opening the Xcode. select the option Create a new Xcode Project.

Step 2: Select the option Single view Application.

Step 3: Drag a button from object library and place it on the viewController.xib file.

Step 4: Now place the mouse over the button and right click on it and drag a line on the ViewController.h as shown below.

Step 5: Now a small window appears,here select ‘Action’ option on the Connection field.Give a name for your button method and click connect.

Step 6: Now inside the method add the code below to the ViewController.m file.

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@”I am a AlertView” message:nil delegate:self cancelButtonTitle:@”Ok” otherButtonTitles:nil, nil];   // Creating a UIAlertView object

[alert show];          //Calling the AlertView
[alert release];      //Now the alert object is released from the stack memory

Step 8: Now Run the Project.



Java – Sample method in java

After the simple ‘HelloWorld’ program this is going to be easy too.


A method is a collection of coding which is specified by its name and signature.It is called to perform a specific task.


public class Cars

public static void sampleMethod()     //this is a method which prints some message
        System.out.println(“This is a method”);
public static void main(String args[])
    sampleMethod();                             // calling the method sampleMethod


  • Here the method modifier is static because everything inside the static field will be static.So to call the method inside the main method ‘public static void main(String args[])’ we defined it as static.