Search the Web for JAVA Answers:

Search the Web for more JAVA Answers:
Hint: Press Ctrl+ to increase the font size of this blog and Ctrl- to decrease the font size of this blog.

general

Object-Oriented Programming Concepts
An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. 
A class is a blueprint or prototype from which objects are created. 
An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. 
A package is a namespace for organizing classes and interfaces in a logical manner. Placing your code into packages makes large software projects easier to manage.
-------------------------------------------------------------------------------------------------------------
Source Code Comments
Three styles of comment notation are used in Java. 
-Any text between "//" and the end of the line is a comment.
-Text starting with "/*" and terminated with "*/" is used to make multiple-line comments. 
-The special form starting with "/**" and terminated with "*/" is used to create comments that can be processed by the Javadoc program to produce HTML-formatted documentation.

-------------------------------------------------------------------------------------------------------------
Because any import statements must precede any class definitions, the required order for these primary
elements is as follows:
- 0 or 1 package declaration
- 0, 1, or many import statements
- 1 or many class definitions, but at most one public class definition.
-------------------------------------------------------------------------------------------------------------
Java keywords:
abstract default if private this boolean do implements protected throw break double import public throws byte else instanceof return transient case extends int short try catch final interface static void char finally long strictfp volatile class float native super while const for new switch
continue goto package synchronized

Reserved Word:I true, false, null, const, goto


----------------------------------------------------------------------------------
What are the Difference between Functions and Procedures? 
Answer: 
1. Functions are used for computations where as Procedures can be used for performing business logic
2. Functions MUST return a value, Procedures need not be.
3) Function parameters are always IN, no OUT is possible
4) Function returns 1 value only. Procedure can return multiple values(max. 1024)
5) We can select the fields from function.In the case of procdure we cannot select the fields.
6) Function do not return the images,text whereas stored procedures returns all data types.

-------------------------------------------------------------------------------------------------------------
How to swap two variables, without using third variable ?
Let the variable be a and b. Then

a=a*b;
b=a/b;
a=a/b;
-------------------------------------------------------------------------------------------------------------
Package Visiblity:

Visibility of a class controls the ability of other classes to create objects or gain access to the
variables and methods in the class. There are various types of visibility:

 Public visibility-A class, variable, or method declared public can be used by any class in
the program.
 Protected visibility-A variable or method declared protected can be used only by classes in
the same package or in a derived class in the same or a different package.
 Default, or package, visibility-If none of the visibility keywords are used, the item is said
to have package visibility, meaning that only classes in the same package can use it.
 Private visibility-The private keyword is not used with classes, only with variables and
methods. A private variable or method can be used within a class only.
-------------------------------------------------------------------------------------------------------------
Identifiers
Words used in programs to name variables, classes, methods, or labels are identifiers and are subject to
strict rules. None of the Java reserved words may be used as identifiers. An identifier can begin with a
letter, a dollar sign, or an underscore character.

The compiler generates an error if you try to use a digit or any punctuation other than the dollar sign and underscore to start an identifier. Identifiers are case sensitive.

-------------------------------------------------------------------------------------------------------------
Array:

Examples of array declarations:
1. int[] counts ;   2. String names[] ;   3. boolean flags[][] ;

Statement 1 declares that the variable counts is an array of int primitives.
Statement 2 declares that the variable names is an array of references to String objects. 
Statement 3 declares that the variable flags is a two-dimensional array of boolean primitives. 
Note that in these statements, I have not set the size of the arrays, and no memory has been allocated for the array items.

Creating an Array
The size of an array is fixed when it is created with the new operator or with special combined declaration
and initialization statements. 

Here are examples of creating some arrays :
1. counts = new int[20] ; // assuming counts was declared int[]
2. String names[] = new String[100] ; // combines declaration and creation
3. boolean[][] flags = new boolean[8][8] ;

When arrays of primitives are created, they are filled with the default values: zero for numerics and false
for booleans. Reference variable arrays, on the other hand, are filled with the special value null. After you
have created an array, you can use the length variable to find out the number of elements the array has.

Initializing an Array
Arrays of primitives are automatically initialized to the default values, but reference variable arrays contain
references to objects only after you create each individual object. In other words, there is no way to "bulk"
initialize. In the following code, statement 1 declares and creates an array of Point objects, but there are no
objects in the array until statement 2 runs. Statement 3 illustrates use of the length variable belonging to the
array.
1. Point spots[] = new Point[20];
2. for(int i = 0 ; i < 20 ; i++){spots[i] = new Point(i,0);}
3. int count = spots.length ;

-------------------------------------------------------------------------------------------------------------
Increment and Decrement
When an  operator appears in a larger expression, the order in which the modification occurs depends on the position of the operator, as shown in the following code fragment:

1. int x = 5 ;
2. int y = x++ ; // y gets the value 5, before incrementing x
3. int y2 = ++x ; // y2 gets the value 7, after incrementingstatic variables, and variables declared inside code blocks.
-------------------------------------------------------------------------------------------------------------

Here is a summary of the different configurations of nested classes:

 Nested static class—A named class declared static. It can directly access only static variables and methods. It is considered a top-level class.
 Nested interface—A named interface, declared as a static member of a class, typically used for defining methods used to access the enclosing class.
 Inner class (member)—A named class defined as a member of the enclosing class. It must be associated with an instance of the enclosing class. There can be multiple member inner classes in an enclosing class. Member inner classes can be declared as public, private, protected, final, or abstract, but they cannot have the same name as any enclosing class.
 Inner class (local)—A named class defined in a code block in a method of the enclosing class. The inner class can access local variables in the method and parameters passed to the method only if the variables are declared final. As with a local variable, the inner class cannot be accessed outside the code block; in other words, the scope of the class is confined to the code block.
 Inner class (anonymous)—A class defined inside a single expression, having no name or constructor method. These classes can access local variables in the method and parameters passed to the method only if they are declared final.