Professional Documents
Culture Documents
Paradigms:
2.Abstraction:
3.Encapsulation:
CLASS defines the structure and behavior (data and code) that will
be shared by a set of objects.
4.Inheritance:
5.Polymorphism:
1.OverLoading:
2.Overriding:
6.Compile Java:
C:\>javac Example.java
7.Run Java:
9.Data Types:
byte - 8bits,
short - 16bits,
int - 32bits,
long - 64bits,
char - 16bits (c/c++ - 8bits),
float - 32bits,
double - 64bits and
boolean - true or false.
(eg: int type is always large enough to hold all valid byte
values)
(eg:)
int a;
byte b;
// ...
b = (byte) a;
11.Arrays:
class Matrix {
public static void main(String args[])
{
double m[][] =
{
{ 0*0, 1*0, 2*0, 3*0 },
{ 0*1, 1*1, 2*1, 3*1 },
{ 0*2, 1*2, 2*2, 3*2 },
{ 0*3, 1*3, 2*3, 3*3 }
};
}
13. Pointers:
for eg:
a= 64; (0100 0000= 2^6= 64)
i= a<<2; (1 0000 0000= 2^8= 256)
If & is used if a=0 then result will be false with out checking a.
>>>
1. () [] .
2. ++ --
3. * / %
4. + -
5. >> <<
6. > <
7. ==
8. &
9. ^
10. |
11. &&
12. ||
13. ?:
14. =
Box mybox = new Box(); (To create a Box object called mybox)
* Objectname.parametername= value.
* objectname.methodname(value).
this can be used inside any method to refer to the current object.
Windows - Microsoft
Mac OS - Apple
Linux - Many
Solaris - Sun(Unix)
30. Variables:
33. Literals:
The Java programming language also supports a few special escape
sequences for char and String literals: \b (backspace), \t (tab), \n
(line feed), \f (form feed), \r (carriage return), \" (double quote), \'
(single quote), and \\ (backslash).
36. SWITCH :
A switch works with the byte, short, char, and int primitive data
types.
It also works with enumerated types and a few special classes that
"wrap" certain primitive types: Character, Byte, Short, and
Integer
37. The most basic CONTROL FLOW statement supported by the Java
programming language is the if-then statement.
for ( ; ; )
{
while (true)
{
40. Constructors:
Constructor declarations look like method declarations—except that
they use the name of the class and have no return type.
Bicycle.numberOfBicycles
Instance Variables:
All the other variables of normal declarations are instance
variables.
54. Constants
(eg):-
55. If a variable is static. Then its old value is replaced by new value
when we initialise.
In Java, a class can inherit from only one class but it can
implement more than one interface.
60. Overriding:
Super:-
From Subclass the field in the superclass must be accessed through
super.
Bike Class:
Mountain Bike:
Road Bike:
Test Bike:
bike01.printDescription();
bike02.printDescription();
bike03.printDescription();
}
}
aCloneableObject.clone();
The equals() method compares two objects for equality and returns
true if they are equal.
The getClass() method returns a Class object, which has methods you
can use to get information about the class, such as its name
(getSimpleName()), its superclass (getSuperclass()), and the interfaces
it implements (getInterfaces()).
74. VARARGS:-
75. Converters:-
long n = 461012;
System.out.format("%d%n", n); // --> "461012"
System.out.format("%08d%n", n); // --> "00461012"
System.out.format("%+8d%n", n); // --> " +461012"
System.out.format("%,8d%n", n); // --> " 461,012"
System.out.format("%+,8d%n%n", n); // --> "+461,012"
double pi = Math.PI;
System.out.format("%f%n", pi); // --> "3.141593"
System.out.format("%.3f%n", pi); // --> "3.142"
System.out.format("%10.3f%n", pi); // --> "
3.142"
System.out.format("%-10.3f%n", pi); // --> "3.142"
System.out.format(Locale.FRANCE,
"%-10.4f%n%n", pi); // --> "3,1416" (-
left justified)
Calendar c = Calendar.getInstance();
System.out.format("%tB %te, %tY%n", c, c, c); // --> "May 29,
2006"
System.out.format("%tl:%tM %tp%n", c, c, c); // --> "2:34 am"
System.out.format("%tD%n", c); // --> "05/29/06"
To format a string containing numbers for output, you can use the
printf() or format() methods in the PrintStream class.
java.lang.character
string1.concat(string2);
/**
* Generic version of the Box class.
*/
public class Box<T> {
public T get() {
return t;
}
}
Box<Integer> integerBox;
Graphics Package:
package graphics;
public interface Draggable {
. . .
}
To use a public package member from outside its package, you must
do one of the following:
91. three exception handler components — the try, catch, and finally
blocks.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
}
finally
{
if (in != null)
{
in.close();
}
if (out != null)
{
out.close();
}
}
}
}
(eg:)
FileReader inputStream = null;
FileWriter outputStream = null;
inputStream = new FileReader("xanadu.txt");
outputStream = new
FileWriter("characteroutput.txt");
inputStream =
new BufferedReader(new FileReader("xanadu.txt"));
outputStream =
new BufferedWriter(new FileWriter("characteroutput.txt"));
96. Flushing:-
import java.io.*;
import java.util.Scanner;
while (s.hasNext()) {
System.out.println(s.next());
}
}
finally
{
if (s != null)
{
s.close();
}
}
}
}
99. Format:-
%d - Integer
%f - Float
%n - New Line
other,
%x - Converts Integer to hexadecimal.
%s - Formats to string.
%tB - locale-specific month name.