Java Review

GUI Programming – A Review

Integrated Development Environment (IDE): It is a software tool to help programmer to edit, compile, interpret and debug the program in the same environment. i.e Eclipse, NetBeans, VB etc.
JVM: Java Virtual Machine (JVM) is a program which behaves as interpreter and translatesbyte code into machine language as they go called just in time compilation.
RAD: Rapid Application Development is software programming technique
that allows quickdevelopment of software application.
Source Code: The core program or text which is written in a language like C,C++ or Java
iscalled source code.
Object Code: The program which only is understood by the computer in the form of
machine instructions or binary instructions called object code. In Java JVM is used to
generate object code in the form of byte code.
Byte code: A byte code is long instruction that the Java compiler generates and Java
interpreter executes. When the compiler compiles a .java file, it produces a series of
bytecodes and stores them in a .class file. The Java interpreter (JVM) can execute the byte
codesstored in the .class file.
GUI: A graphical user interface (GUI) presents a pictorial interface to a program. GUI
allowsthe user to spend less time trying to remember which keystroke sequences do
what andspend more time using the program in a productive manner.
Token:
The smallest individual unit in a program is known as Token. Java has the following types
of tokens: keyword, Identifier, literal, punctuators and operators.
Keywords
Keywords are words that have a specific predefined meaning in Java. They cannot be used
as variable names. They are also known as reserve words. Eg. void, private, if, while etc.
Literals:
Items having fixed data values are referred to as Literals. They are also known as
Constants. Various types of literals available in Java are :
integer iterals
Floating literals
Boolean literals
Character literals
String literals
Null literals

Variable:
Variable is a named storage location in computer memory whose contents can change
during a program run.
The characteristics of a variable are:
(i) It has a name.
(ii) It is capable of storing values.
(iii) It provides temporary storage.
(iv) It is capable of changing its value during program execution.
Operators:
Operators are special symbols that perform specific operations on one, two, orthree
operands, and then return a result.
Operators Precedence
·         postfix expr++ expr
·         unary ++exprexpr+exprexpr~ !
·         multiplicative * / %
·         additive + -
·         shift <<>>>>>
·         relational <><= >= instanceof
·         equality == !=
·         bitwise AND &
·         bitwise exclusive OR ^
·         bitwise inclusive OR |
·         logical AND &&
·         logical OR ||
·         ternary ? :
·         assignment = += =*= /= %= &= ^= |= <<= >>= >>>=
Data type:
It states the way the values of that type are stored, and the range for that type.
Primitive Data Types:
The Java programming language is statically typed, whichmeans that all variables must first
be declared before they can be used.
A primitive type is predefined by the language and is named by a reserved keyword. The eight
primitive data types supported by the Java programming language are:
byte: The byte data type is an 8bit signed two's complement integer. It has a minimum
value of 128and a maximum value of 127 (inclusive).
short: The short data type is a 16bit signed two's complement integer. It has a minimum
value of 32,768and a maximum value of 32,767 (inclusive).
int: The int data type is a 32bitsigned two's complement integer. It has a minimum
value of 2,147,483,648and a maximumvalue of 2,147,483,647 (inclusive).
long: The long data type is a 64 bit signed two's complement integer. It has a minimum
value of 9,223,372,036,854,775,808and amaximumvalue of 9,223,372,036,854,775,807
float: The float data type is a single precision 32 bit IEEE 754 floating point.
double: The double data type is a double precision 64 bit IEEE 754 floating point.
boolean: The Boolean data type has only two possible values: true and false. Use this
data typefor simple flags that track true/false conditions.
char: The char data type is a single 16bitUnicode character. It has a minimum value
of'\u0000' (or 0) and a maximum value of '\uffff ' (or 65,535 inclusive).

Reference Data Types: These are constructed by using primitive data types, as per user
need. Reference data types store the memory address of an object. Class, store the
memory address of an object.
Class, Interface and Array are the example of Interface Reference Data types.
Basics of Object Oriented Programming
OOP: Object Oriented Programming, emphasis on objects and the interaction between
objects. An object is a self-contained entity that describes not only certain data but the
procedures tomanipulate that data.

Components of Object Oriented Programming are as follows:
1. Class
2. Object
3. DataMembers &Methods
4. Access Specifier and VisibilityModes

Class: A class in OOP is a template for objects. In other words, a class is a specification of
thedata and the functions to be encapsulated with data.

Object: Objects in the real world can be represented by objects in the program.
Each object contains data and code tomanipulate data.

Constructors: A class contains constructors that are invoked to create objects from the class
blueprint. Constructor declarations look likemethod declarations—except that they use the
name of the class and have no return type.

Control Flow Statements: The statements inside your source files are generally executed
from top to bottom, in the order that they appear. Control flow statements, however,
breakup the flow of execution by employing decision making, looping, and branching,
enabling your program to conditionally execute particular blocks of code.

Selection:
(i) Simple if:
The syntax of if statement is as shown below:
Syntax:
if (conditional expression)
{
Statement Block;
}
(ii) if-else
The syntax of if-else statement is as shown below:
Syntax:
if (conditional expression)
{
Statement Block;
}
else
{
Statement Block;
}


(iii) if else ladder
These control structures are used to test for multiple conditions as against the
simple if statement which can be used to test a single condition. The syntax of
nested if else is as follows:
Syntax:
if (conditional expression1)
{
statements1;
}
else if (conditional expression2)
{
statements2;
}
else if (conditional expression3)
{
statements3;
}
else
{
statements4;
}
(iv) Switch:
The syntax of the switch statement is as follows:
switch (Variable/Expression)
{
case Value1: statements1 ; break ;
case Value2: statements2 ; break ;
default: statements3 ;
}



2. Looping:
(i) The syntax of the for loop is:
Syntax
for( initialization; test exp; increment/decrement exp)
{
statements;
}
(ii)The syntax of the while loop is as follows:
Syntax
while(test expression)
{
loop body
}
(iii) The syntax of the loop is as
follows: Syntax :
do
{
loop body
}while (test expression);
3. Jump:
(i) break: The break is used to break from an enclosing do,while for,or switch statement.
Syntax: break;
(ii) continue: The continue statement stops the execution of the current iteration and
causes control to begin with next iteration.
Syntax: continue;
(iii) return : Return is used to return value from the method Syntax:
Return <value>;
Commonly available Swing Controls in Java
jFrame: A Frame is a container control, in which all the controls can be place.
jLabel: JLable allows placing un-editable text on the Frame/Panel
jTextField: JTextFiled allows placing editable text on the Frame/Pane. User can enter text in
a textFiled during runtime.
jbutton: is used to initiate an action when it is clicked.
jList: is a group of values or items from which one or more selections can be made.
jComboBox: jComboBox is similar to jList but also allow to enter editable text during run
time. It is a combination of jTextFiled and jList.
jPanel: Act like a frame, to group one or more controls.
jRadioButton: Allow us to choose a single item from a group of jRadioButton options.
jCheckBox: Allow us to choose one or more items from a group of jCheckBox options.
jPasswordField: Allow us to enter a text during the run time but shows an encrypted text
instead of the original text
jTextArea: JTextArea is a multi-line text component to enter or edit text.
Focus: The control under execution is said to have the focus. The control having the focus
obtains input form the user.
getText(): getText() method is used to obtain the text from a jTextFiled during the run time.
setText(): setText() method is used to set or change the text of a jTextFiled during run time.
Access Control of Inherited members :
Access specifier tells a complier about the usability of a data member of a class in a java
program. Java supports three types of access specifier:
Public, Private ,Protected, default and private protected.
Public:
A Class member with public access specifier is usable outside the class. i.e. it can be used in
any class in the program.
Protected
A class member with protected access specifier can be inherited by a child class but is not
usable outside the parent class.
Private:
Private members of a class can just be utilized inside the class and are hidden outside the
class
i.e. a private member cannot be used in any other class other than the class in which it is
declared.
Default: These members are accessible only in the class that are in the same package
class ie in their own classes.
Private Protected: These members are accessible only from subclasses whether in
the same package or in the other package.

Advanced Programming Concepts
Inheritance: Inheritance is the capability of one class to inherit properties from an existing
class. Inheritance supports reusability of code and is able to simulate the transitive nature of
real life objects.
Derived/Sub and Base/Super classes: A class from which another class is inheriting its properties is called base class. The class inheriting properties is known as a sub class or derived class.
Need of Inheritance: Inheritance helps in two ways:
(i) Code Reusability: Inheritance helps in adding new features to a class without modifying it. A pre-existing class can be directly be reused in a new class.
(ii) Helps in expressing relationship among classes
Types of Inheritance:
1. Single ( 1:1) : When a class inherits from a single base class.
2. Hierarchical (1:M) : When several classes inherit from the same class.
3. Multilevel (1:1:1) : When a subclass is the base class of another class.
4. Multiple Inheritance: when a class inherit from the several base class.


Method overriding: If Base class has a method with same signature as in sub class the method
of subclass overshadows the method of base class , it is called Method overriding.
Method Overloading: Two methods with same name but different signatures are there in the
same scope of program.
Abstract Class: The class that is used as only base class, no object of this class is used in the
program.
Interfaces: An interface defines a set of protocol. It declares a set of abstract methods i.e.
methods with an empty body.
Dialog Type:
There are four built in dialog styles:
1) OptionPane.showMessageDialog() : displays the message dialog
2) OptionPane.showInputDialog() : displays the input dialog
3) OptionPane showConfirmDialog() : displays the confirm dialog
4) OptionPane showOptionDialog() : displays the option dialog
Example:
1. String name=JOptionPane.showInputDialog(“Enter Name”);
2. String a=JOptionPane.showInputDialog(“Enter age”); Int ag = Integer.parseInt(a);
3. JOptionPane.showMessageDialog(null,”Eligible for vote”,”Title of the
window”,JOptionPane.ERROR_MESSAGE);
4. do
{ .
.
int res = JOptionPane.showConfirmDialog(null,”Want to add More ??”);
..
}while(res==JOptionPane.YES_OPTION);
if(res==JOptionPane.NO_OPTION);
{………….
}
Commonly available functions in Math class in Java are:
sin() Returns the trigonometric sine of an angle.
sin(double a)
cos() Returns the trigonometric cosine of an angle.
cos(double a)
log() Returns the natural logarithm (base) of a double value.
log(double a)
pow() This function returns you the number raised to the power of a first given value by another one.
pow(double a, double b)
sqrt() Returns a double value that is the square root of the parameter.
math.sqrt(100)
abs() Returns the absolute value of a number. Whereas the number can be int, float, double or long.
math.abs(100)
ceil() Returns the next whole number up that is an integer. math.ceil(1.1)
floor() Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer. math.floor(99.1)
max() Returns the maximum value from the two given value. math.max(1,10)
min() Returns the minimum value from the two given value. math.min(1,1)
round() Rounds to the nearest integer. So, if the value is more than half way towards the higher integer, the value is rounded up to the next integer. math.round(1.01)
random() Returns a random number between 0.0 and 1.0 math.random()*100

Commonly available functions in String class in Java are:
concat() : Converts the uppercase character into the lowercase character and returns converted lowercase character.
length() : Count and return the number of characters contained in the string object.
substring() : Return a part or substring of the String used to invoke the method. The first argument represents the starting location of the substring.
toLowerCase() : Converts the uppercase character into the uppercase character and returns converted lowercase character.
toUpperCase() : Converts the lowercase character into the uppercase character and returns converted uppercase character.

trim() : Returns a String after removing extra speces from any leading or trailing part of the string.

No comments:

Post a Comment