Skip to main content

Posts

Showing posts from December, 2013

android intent example

In this post we are going to make an example that demonstrate the use of intent, intent filter and startActivity in android. Create a new android application project in eclipse and name it as IntentDemo . I change the activity name as First_Activity and corresponding layout name as first_layout . Ads by Google Place a button on the first_layout.xm l file as shown bellow. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".First_Activity" > <Button

android button example

In this post we are going to see how to create a simple android application that contains two buttons and how to create the response for the button clicks. Create a new android project named ButtonDemo in eclipse. In  the activity_main.xml add two buttons as shown bellow. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_he

create your first android app

In this post i explain how to create your first android application. I use the eclipse ide for the development purpose. See this article for the installation and configuration of eclipse for android. Create a new android application project with name HelloWorld. ( Click the image to enlarge. ) Now on the activity_main.xml file add a new TextView as shown bellow. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:

arithmetic operators in java

Question : Write a java program that demonstrates the use of arithmetic operators. Answer : In this program we perform basic calculator functions like addition, subtraction, division and multiplication, which clearly shows the using of arithmetic operators in java. 1: import java.io.BufferedReader; 2: import java.io.IOException; 3: import java.io.InputStreamReader; 4: public class CalculatorDemo { 5: public static void main(String args[]) throws IOException 6: { 7: int a,b,c; 8: float s; 9: BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 10: System.out.println("Enter first number"); 11: a = Integer.parseInt(br.readLine()); 12: b = Integer.parseInt(br.readLine()); 13: c = a + b; 14: System.out.println("Sum :"+c); 15: c = a - b; 16: System.out.println("Difference :"+c); 17: c = a * b; 18: System.out.println("Product

read a string in java

Question 2 : Write a java program for read a string from keyboard and display it. Answer : In this program we accept a string from the keyboard and print that string on the output console. 1: import java.io.BufferedReader; 2: import java.io.IOException; 3: import java.io.InputStreamReader; 4: public class ReadStringDemo 5: { 6: public static void main(String args[])throws IOException 7: { 8: BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 9: String S; 10: System.out.println("Enter any String "); 11: S = br.readLine(); 12: System.out.println("Entered String is : "+S); 13: } 14: } Ads by Google

first java program

Question 1 : Write a program in java for print a greeting message . Answer:  This program demonstrate how to write a simple java program print a greeting message on the output console. 1: public class FirstProgram 2: { 3: // Create the main method here 4: public static void main(String args[]) 5: { 6: System.out.println("this is my first program in java"); 7: } 8: } Ads By Google