|
| |||||||||
| Tags: final, java, keyword, programming |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| Final keyword in Java
Hi, I want some example code and basic explanation of final keyword in JAVA. Can anyone provide me this? I am trying to improve my knowledge in java and want to learn new things. I am not having more knowledge about java. So, please give me details of final keyword. |
|
#2
| ||||
| ||||
| Re: Final keyword in Java
Hi, Final keyword is used in java for the purpose of making some housekeeping task. There may be possibility that your try catch block is not get executed but your final block gets executed at every time when your program would get executed. Therefore this block is used for making those executions which have to be done before moving out of the program. As whether your program gets exception or not, it has to execute the final block. That is why many times final block is used to close the connections, so no single connection is remain open to slow down the traffic of the two nodes. |
|
#3
| |||
| |||
| Re: Final keyword in Java
Hi, you have not explained where did you want to use the final keyword. If a method is declared final then subclasses would be prevented from overriding or hiding it. It will give compile-time error. You can't declare them abstract. It can be used as follows: Code: final class one
{
int a, b;
void change (int x, int y) { a += x; b += y; }
}
class check
{
public static void main(String[] args)
{
test[] p = new test[100];
for (int i = 0; i < p.length; i++)
{
p[i] = new test();
p[i].change(i, p.length-1-i);
}
}
} |
|
#4
| ||||
| ||||
| Re: Final keyword in Java
Hi, you want to know about keyword final in java, right? In java basically, final simply means that the value will not going to change further. Advantages:
// final is used to ensure a variable is always assigned a value, // and once assigned value never change. Code: final int a;
if ( x> 0 )
{
a=14;
}
else if ( x < 0 )
{
a = 0;
}
else
{
a = 7;
} |
|
#5
| |||
| |||
| Re: Final keyword in Java
You can find more information on all different uses of final here https://sites.google.com/site/javadvanced/final-keyword |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Final keyword in Java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Equivalent to Java finally keyword in PHP | Jaganmohini | Software Development | 6 | 12-08-2010 11:20 AM |
| Keyword Analyzer and keyword ranking tool | Captain Carrot | Technology & Internet | 5 | 21-06-2010 04:12 PM |
| How to use same keyword for two purposes in java? | Juaquine | Software Development | 4 | 08-03-2010 09:48 PM |
| Difference between final, finally and finalize in Java? | Maddox G | Software Development | 6 | 31-01-2010 11:09 AM |
| How to use Search Engine Keyword Tracker & Keyword Ranking Code using PHP | Burnet | Software Development | 3 | 09-01-2009 01:38 PM |