Professional Documents
Culture Documents
Introduction Basics Instructions Methods & arrays Object oriented programming Ingeritance & modifiers Polymorphism&Abstraction Package & Interface Exeptions handlin & streams GUI SQL Data base
Basics
Variables
Comments Constants
Casting
Operation
Variables
Esc a p e seq uenc e Desc rip tion \n Newline. Position the screen cursor to the beginning of the next line. \t Horizontal tab. Move the screen cursor to the next tab stop. \r Carriage return. Position the screen cursor to the beginning of the current line; do not advance to the next line. Any characters output after the carriage return overwrite the characters previously output on that line. \\ Backslash. Used to print a backslash character. \" Double quote. Used to print a double-quote character. For example, System.out.println( "\"in quotes\"" ); displays "in quotes" Fig. 2.5 Som e c om mon esc a p e seq uenc es.
Casting
Constants
Define in C++ b ut in java called final Ex: Final float pi =3.14 Comments 1. One line //comment 2. More than one line /* comment */
Chapter 2 Instructions
I/P & O/P instructions use dialouge box
Icon
Description Displays a dialog that indicates an error to the user. Displays a dialog with an informational message to the user. The user can simply dismiss the dialog. Displays a dialog that warns the user of a potential problem. Displays a dialog that poses a question to the user. This dialog normally requires a response, such as clicking on a Yes or a No button.
JOptionPane.INFORMATION_MESSAGE
JOptionPane.WARNING_MESSAGE JOptionPane.QUESTION_MESSAGE
Displays a dialog that simply contains a message, with no icon. Fig. 2.12 JOptionPane constants for message dialogs.
JOptionPane.PLAIN_MESSAGE
no icon
Input
Variable=JOptionPane.showInputDialog( "Enter "
); Ex: String Number; Int number; Number =JOptionPane.showInputDialog( "Enter integer" ); number = Integer.parseInt( firstNumber ); int
Looping
For
While Dowhile
Control statements
If
If.else If.elseif.endif.
Switchcase..
methods
Ex
Public class Method{ Public int sum(int a,intb) {int s; S=a+b; Return s; } Public static void main(String[] args) {int r; Metod Obj=new Method // defination for class will discussed later r=Obj.Sum(10,15); System.out.prtln(the sum is +r) // instruction for o/p }}
Array
Definition
ex : int sum = new int [4] // 4 is size or int []sum={1,4,5,7} or int [] sum;sum=new int[4]; for