you can understand what is the purpose of return in java after this simple example
Basically return use in java to return some values from a method
note: this sample will work on all java versions, i test it on JDK 1.4
enjoy the code.
file name : Class1.java
-----
package mypackage1; //package name
public class Class1 //class name + file name the
{
public String add(int a,int b) //a method in the class; its type is String and it take a and b variables; a and b are int
{
int answer = a+b; //this is some code in the class; maybe some operations; no need to know whats happening in this method
System.out.println("I'm in Class1"); //this is some code in the class; maybe some operations; no need to know whats happening in this method
return " I'm the returned value "+ answer; ////this is what you need to take from the method
}
public static void main(String [] arg)
{
Class1 c1 = new Class1(); //creating c1 object from Class1 Class
System.out.println(c1.add(10,6)); //printing the returned values from the method;
}
}
-----------------
output:
I'am in Class1
I'am the returned value 16
Return statement is commonly used with Method which return value.
Example,
int sum(int a,int b)
{
return (a+b);
}
This method gives sum of two numbers which can be assigned to any int variable.
When declaring a method, when you type in "public (or private) int", the int gives the return type. The return statement gives the value to return.
You declare a method's return type in its method declaration. Within the body of the method, you use the return statement to return the value.
The pane in which the Java programming statements are located is called
There are 4 different looping statements in Java. They are:While loopDo-While loopFor loopFor Each loop
Each statement in Java ends with a semicolon, for example: int a; a = 5; int b = 10;
A method in java can declare only one return value and type at a time. For ex: a single method cannot have a code that returns a string in some cases and an integer in other cases. Java compiler does not let you do that. You can only have one return type for every method in java.
posted by Suhit s Kalubarme Software Developer Solapur 9260069199 Controls are components that allow the user to interact with your application in various ways e.g. a commonly use the control is command button. Various controls: 1. Label 2. Button 3. Check Box 4. Choice Box 5. TextArea 6. TextField
The pane in which the Java programming statements are located is called
There are 4 different looping statements in Java. They are:While loopDo-While loopFor loopFor Each loop
There are many kinds of statements that are used in Java and they are predominantly used for database connectivity using JDBCEx:PreparedStatement - for normal SQL QueriesCallableStatement - for stored procedures
A Java method is a sequence of statements. It is comparable to a function, subroutine, or procedure in other languages.
The final and finally keywords have no impact on the return type of a method in Java.
Java Database Connectivity, a Java API that enables Java programs to execute SQL statements. This allows Java programs to interact with any SQL-compliant database.
Each statement in Java ends with a semicolon, for example: int a; a = 5; int b = 10;
A method in java can declare only one return value and type at a time. For ex: a single method cannot have a code that returns a string in some cases and an integer in other cases. Java compiler does not let you do that. You can only have one return type for every method in java.
default return type is : true
try{ statements; } catch(Exception e) { message }
posted by Suhit s Kalubarme Software Developer Solapur 9260069199 Controls are components that allow the user to interact with your application in various ways e.g. a commonly use the control is command button. Various controls: 1. Label 2. Button 3. Check Box 4. Choice Box 5. TextArea 6. TextField
A programming language uses control statements to cause the flow of execution to advance and branch based on changes to the state of a program. control statements are mainly three types in java. they are selection, iteration, and jump.