java coding for android application
Introduction to java
Java is a platform-independent, object-oriented programming language originally developed by Sun Micro-systems and now owned by Oracle. It is a programming language, Which inherits its object-oriented features from C++. Java language was created by a software developer, James Gosling, at Sun Microsystems in 1991. It was first called Oak, which got changed to Java in 1995, when it was first released for public use. Java was basically created to act as platform independent of object-oriented language that could run on any operating system. Java has a slogan that is right once, run anywhere. This slogan means once a program is compiled and run successfully on a platform then that program can easily be executed on any other operating system.
Need For Java For Android Application Development
The Java programming language is used to develop native application for the Android platform. The following are some of the reasons why Java has been chosen to develop Android Application:
- Java is a very popular language so most of the developers must be familiar with it and need not put any extra efforts to learn a new language.
- It provide security features such as protection from memory leaks and bad pointer usage.
- Android run on different hardware platforms which means that native code also known as machine code must be compiled and optimised according to each of the platforms. However, if you are using Java language, the Java code run in virtual machine and requires no interaction with the inner hardware of a device. A virtual machine safely manage the execution of the code within its virtual environment. In case of Android application, these applications run in a virtual machine called Dalvik Virtual Machine (DVM) and therefore it is not required to recompiled to code for every phone.
- Java provides huge open source support bu offering many libraries and tool for creating application in Java.
- Majority of the smartphones already use Java ME and Android Applications are developed for running on smartphones. Therefore Java is preferable for developing Android Applications.
Features of Java
Simple
Java is a simple to learn and use. Java programs are easy to write and debug because it does not use pointers.
Moreover, Java provide bug free system due to strong memory management and also has automatic memory allocation and deallocation systems. Unlike other programming language, which provide dozens of complicated ways to performs a simple task, Java provides a simple and clear approach. If a programmer understands the basic concepts of OOP, it becomes easier for the programmer to learn Java.
Secure
In today's world, everybody needs safety and security while performing online transaction. In order to overcome such threads, Java provide the safety and security features.
with the help of Java compatible browsers, Java applets can be easily and safely downloaded over the Internet. As the Java programs are confined to the Java runtime environment, the hackers can only access that part of your computer which is required for program execution. the data outside the Java runtime environment cannot be accessed by Java programmer, and therefore downloading a java application through internet will not harm your computer. That's why Java is a secure language.
Hindi distributed world of internet, an application developed with the help of a programming language might be exist on various computers having different kinds of operating system. But, it's not guaranteed that the application is portable, that is application Run successfully on all operating system. To overcome this portability issue, Java introduces a concept of which is known as bytecode.
So, in order to run your Java program, you should have only JVM installed. JVM is also considered as the interpreter of bytecode. In this way, Java has solve the problem of portability.
Generally, program fails for the following two reasons:
1. Lack of memory management devices for allocating the and deallocating memory for objects.
2. Occurrence of unexpected, exceptional conditions.
considering the preceding reasons, Java was designed to create robust programs full stop Java compels its programmers to resolve the mistake during the the compilation. More ever, it also frees the programmer from the common causes of programming error as the program code is verified during compilation.
Java is a programming language that is designed for the distributed environment of the internet and for that the concept of multithreading is implemented. This feature helps to write interactive programmes where in multiple tasks can be performed sahmat any asli hi, making it a reversed programming language.
Java is inherited multithreading as there can be multiple execution thread in a single Java program. For example, a java programmer can run 3 Java applets on the same page, provided that each applet gets equal time from the CPU.
it is one of the most important feature of Java. The Java is the first programming language, which is not bound to any specific operating system. In other words, Java program can be executed anywhere on any system. No other programming language, before the evolution of Java, was platform Independent and therefore, it can be said that Java is a revolutionary technology. A part from cross platform in source form, Java is also platform independent in compiled binary form.
Java is a distributed language as it can be used to create application to communicate over the network. Java can communicate over the network because it support transmission control protocol / internet protocol (TCP / IP).
Dynamic
During runtime of Java program, the relevant information is required to verify and resolve access two objects. This concept of providing runtime information is referred to as dynamically linking the code. This features of Java adds strength to the applets environment, in which small fragments of bytecode are dynamically updated on a running system.
Smallest individual unit in a program are known as Java tokens or tokens.
Java program is a collection of various tokens Java language use the following tokens:
an identifier is a symbolic name that refers to variables, methods, classes, packages, or interfaces in Java program. Each variable is identified by its name. The variable name should related to its purpose. Similarly, in case of method, the name of the method should relate the methods functionality stop Java identifiers consist of alphabets, numbers , underscore (_) close, and the Dollar sign ($).
In a Java program, you can assign a literal value to a variable. Literal refers to the constant values that can be changed depending on the program requirement. The source code representations of the values of primitive data types in java program are known as primitive literals. These primitive literals can be an integer number, floating point number, a Boolean value you, or a character that you use in your program. Some of the examples of primitive literals are:
79 // an int literal
837.367 // A double literal
True // A Boolean literal
'V' // A char literal
The operators that are used to perform arithmetic operations are called arithmetic operators, such as addition (+) , subtraction (-) and multiplication (*).
/* Program on Adding and subtracting integers numbers.
class intAddsub {
public static void main(string args[] ) {
int a= 50;
int b= 30;
system.out.println("First Number is :" +a);
system.out.println("Second Number is:" +b);
int c=a+b ;
system.out.println("Addition of two numbers is:" +c);
c=a-b;
system.out.println("Substraction of two numbers is:" +c);
}
}
Output:
First Number is:50
Second Number is:30
Addition of two numbers is:80
Subtraction of two numbers is:20
Operator that are used to determine the relationship between two operands are known as relational operators. The expressions that contain relational operators always return Boolean value, which other true or false. There are 6 relational operator that can be used to compare any value to integer, floats or characters.
*/ Program implementing the relational operators */
class relationaloperator
{
static int value1=10;
static int value2=8;
public static void main (string args[])
{
float a=3.6f;
float b=5.1f;
float c=1.1f;
system.out.println("First Number is" +a);
system.out.println("Second Number is:" +b);
system.out.println("Third Number is:" +c);
system.out.println("a<b is:"+(a<b));
system.out.println("a>b is:"+(a>b));
system.out.println("b==c is:"+(b==c));
system.out.println("a<=b is:"+(a<=b));
system.out.println("a>=b is:"+(a>=b));
system.out.println("a!=c is:"+(a!=c));
system.out.println('b==a+c is:"+(b==a+c));
}
}
OUTPUT:
First Number is:3.6
Second Number is:5.1
Third Number is:1.1
a<b is:true
a>b is:true
b==c is:false
a<=b is:true
a>=b is: false
a!=c is:true
b==a+c is:false
These operators operate only the Boolean operands.all of the binary logical operators combine two Boolean values and provide the resultant Boolean value.
with the help of Java compatible browsers, Java applets can be easily and safely downloaded over the Internet. As the Java programs are confined to the Java runtime environment, the hackers can only access that part of your computer which is required for program execution. the data outside the Java runtime environment cannot be accessed by Java programmer, and therefore downloading a java application through internet will not harm your computer. That's why Java is a secure language.
Portable
Hindi distributed world of internet, an application developed with the help of a programming language might be exist on various computers having different kinds of operating system. But, it's not guaranteed that the application is portable, that is application Run successfully on all operating system. To overcome this portability issue, Java introduces a concept of which is known as bytecode.
So, in order to run your Java program, you should have only JVM installed. JVM is also considered as the interpreter of bytecode. In this way, Java has solve the problem of portability.
Robust
Generally, program fails for the following two reasons:
1. Lack of memory management devices for allocating the and deallocating memory for objects.
2. Occurrence of unexpected, exceptional conditions.
considering the preceding reasons, Java was designed to create robust programs full stop Java compels its programmers to resolve the mistake during the the compilation. More ever, it also frees the programmer from the common causes of programming error as the program code is verified during compilation.
Multi-threading
Java is a programming language that is designed for the distributed environment of the internet and for that the concept of multithreading is implemented. This feature helps to write interactive programmes where in multiple tasks can be performed sahmat any asli hi, making it a reversed programming language.
Java is inherited multithreading as there can be multiple execution thread in a single Java program. For example, a java programmer can run 3 Java applets on the same page, provided that each applet gets equal time from the CPU.
Platform independent
it is one of the most important feature of Java. The Java is the first programming language, which is not bound to any specific operating system. In other words, Java program can be executed anywhere on any system. No other programming language, before the evolution of Java, was platform Independent and therefore, it can be said that Java is a revolutionary technology. A part from cross platform in source form, Java is also platform independent in compiled binary form.
Distributed
Java is a distributed language as it can be used to create application to communicate over the network. Java can communicate over the network because it support transmission control protocol / internet protocol (TCP / IP).
Dynamic
During runtime of Java program, the relevant information is required to verify and resolve access two objects. This concept of providing runtime information is referred to as dynamically linking the code. This features of Java adds strength to the applets environment, in which small fragments of bytecode are dynamically updated on a running system.
Tokens of Java
Smallest individual unit in a program are known as Java tokens or tokens.
Java program is a collection of various tokens Java language use the following tokens:
- Keyword
- Identifier/variable
- Literals/constants
- Operators
Keyword
keywords are reserved words that can be used while naming a variable or method for stop the keywords in Java are:- Abstract
- Assert
- Boolean
- Break
- Byte
- Byvalue
- Case
- Cast
- Catch
- Char
- Class
- Const
- Continue
- Default
- Do
- Double
- Else
- Extends
- Enum
- Final
- Finally
- Float
- For
- Go-to
- If
- Implements
- Import
- Instanceof
- Int
- Interface
- Long
- Native
- New
- Package
- Private
- Protected
- Public
- Return
- Short
- Static
- Strictfp
- Super
- Switch
- Synchronized
- This
- Throws
- Transient
- Try
- Var
- Void
- Volatile
- While
Identifiers
an identifier is a symbolic name that refers to variables, methods, classes, packages, or interfaces in Java program. Each variable is identified by its name. The variable name should related to its purpose. Similarly, in case of method, the name of the method should relate the methods functionality stop Java identifiers consist of alphabets, numbers , underscore (_) close, and the Dollar sign ($).
Literals
In a Java program, you can assign a literal value to a variable. Literal refers to the constant values that can be changed depending on the program requirement. The source code representations of the values of primitive data types in java program are known as primitive literals. These primitive literals can be an integer number, floating point number, a Boolean value you, or a character that you use in your program. Some of the examples of primitive literals are:
79 // an int literal
837.367 // A double literal
True // A Boolean literal
'V' // A char literal
Operators
Arithmetic operators
The operators that are used to perform arithmetic operations are called arithmetic operators, such as addition (+) , subtraction (-) and multiplication (*).
/* Program on Adding and subtracting integers numbers.
class intAddsub {
public static void main(string args[] ) {
int a= 50;
int b= 30;
system.out.println("First Number is :" +a);
system.out.println("Second Number is:" +b);
int c=a+b ;
system.out.println("Addition of two numbers is:" +c);
c=a-b;
system.out.println("Substraction of two numbers is:" +c);
}
}
Output:
First Number is:50
Second Number is:30
Addition of two numbers is:80
Subtraction of two numbers is:20
Relational operators
Operator that are used to determine the relationship between two operands are known as relational operators. The expressions that contain relational operators always return Boolean value, which other true or false. There are 6 relational operator that can be used to compare any value to integer, floats or characters.
Relational operators
|
|
Relational operators
|
Description
|
==
|
Equal to
|
!=
|
Not equal to
|
<
|
Less than
|
>
|
Greater than
|
<=
|
Less than equal to
|
>=
|
Greater than equal to
|
*/ Program implementing the relational operators */
class relationaloperator
{
static int value1=10;
static int value2=8;
public static void main (string args[])
{
float a=3.6f;
float b=5.1f;
float c=1.1f;
system.out.println("First Number is" +a);
system.out.println("Second Number is:" +b);
system.out.println("Third Number is:" +c);
system.out.println("a<b is:"+(a<b));
system.out.println("a>b is:"+(a>b));
system.out.println("b==c is:"+(b==c));
system.out.println("a<=b is:"+(a<=b));
system.out.println("a>=b is:"+(a>=b));
system.out.println("a!=c is:"+(a!=c));
system.out.println('b==a+c is:"+(b==a+c));
}
}
OUTPUT:
First Number is:3.6
Second Number is:5.1
Third Number is:1.1
a<b is:true
a>b is:true
b==c is:false
a<=b is:true
a>=b is: false
a!=c is:true
b==a+c is:false
Logical operators
These operators operate only the Boolean operands.all of the binary logical operators combine two Boolean values and provide the resultant Boolean value.
Logical
operators
|
|
Operators
|
Description
|
&
|
Logical AND
|
!
|
Logical OR
|
^
|
Logical XOR(Exclusive OR)
|
||
|
Short-circuit OR
|
&&
|
Short-circuit AND
|
!
|
Logical Unary NOT
|
&=
|
AND assignment
|
|=
|
OR assignment
|
^=
|
XOR assignment
|
==
|
Equal to
|
!=
|
Not equal to
|
/* Program implementing the boolean logical operators */
class BooleanLogicApp
{
public static void main(string args[])
{
boolean b1=false;
boolean b2=true;
boolean b3=b1 & b2;
boolean b4=b1 | b2;
boolean b5=b1^b2;
boolean b6=!b2;
system.out.println("b1=" +b1);
system.out.println("b2=" =+b2);
system.out.println("b1&b2="+b3);
system.out.println("b1| b2="+b4);
system.out.println("b1^b2="+b5);
system.out.println("!b2="+b6);
int i=10;
boolean b7=6==4&i<4;
boolean b8=b3^b2;
boolean b9=b4 | b1 & b2;
system.out.println("b7="+b7);
system.out.println("b8="+b8);
system.out.println("b9="+b9);
}
}
OUTPUT:
b1=false
b2=true
b1&b2=false
b1 | b2=true
b1^ b2=true
!b2=false
b7=false
b8=true
b9=true
class BooleanLogicApp
{
public static void main(string args[])
{
boolean b1=false;
boolean b2=true;
boolean b3=b1 & b2;
boolean b4=b1 | b2;
boolean b5=b1^b2;
boolean b6=!b2;
system.out.println("b1=" +b1);
system.out.println("b2=" =+b2);
system.out.println("b1&b2="+b3);
system.out.println("b1| b2="+b4);
system.out.println("b1^b2="+b5);
system.out.println("!b2="+b6);
int i=10;
boolean b7=6==4&i<4;
boolean b8=b3^b2;
boolean b9=b4 | b1 & b2;
system.out.println("b7="+b7);
system.out.println("b8="+b8);
system.out.println("b9="+b9);
}
}
OUTPUT:
b1=false
b2=true
b1&b2=false
b1 | b2=true
b1^ b2=true
!b2=false
b7=false
b8=true
b9=true
1 Comments
Just comment what you need...
ReplyDelete