Sunday, 2 October 2016

Netbeans Programming Notes With programs, question and explaination(JAVA)

To get started , firstly download netbeans from Netbeans.org with JDK

Then install it and start learning..................
(<< MY OTHER BLOGS ON mysql, databse connectivity etc. links are given below the page.>>)
Netbeans page overview
you can also visit www.angadsoni.westarts.com
to download netbeans+JDK software down the page.
I will be posting a video on my youtube channel (SOON) regarding all this and  also about shortcut keys +variable name+easy going programming for all of you.
Start learning...................

Before starting I would like to tell you that this is only short notes for berif illustration do refer to SUMITA ARORA or IP book by Ncert.




!<<<(BASICS )Getting started/Famalier with NETBEANS IDE.
1. >>  Getting Started with NetBeans After you have successfully installed NetBeans on your machine. Start NetBeans from Windows, Linux, Mac OS X, or Solaris. The NetBeans main window appears. The NetBeans main window is the command center for the IDE. The NetBeans main window contains menus, toolbars, project pane, files pane, runtime pane, navigator pane, and other panes. 

2. >> Creating a Project A project contains information about programs and their dependent files, and it also stores and maintains the properties of the IDE. To create and run a program, you have to first create a project. Here are the steps to create a demo project: 1. Choose File, New Project to display the New Project dialog box, as shown in Figure 2. 2. Select General in the Categories section and Java Application in the Projects section and click Next to display the New Java Application dialog box, as shown in Figure 3. 3. Type demo in the Project Name field and c:\michael in Project Location field. 4. (Optional) You can create classes after a project is created. Optionally you may also create the first class when creating a new project. To do so, check the Create Main Class box and type a class name, say First, as the Main Class name. 5. Click Finish to create the project. 

FOR MORE AND FULL TUTORIAL ON STARTUP WITH NETBEANS CLICK HERE (in pdf).>>>!








<<After learning this all you will be able to form a simple program / softwares by using Netbeans Ide on Java.>>

 


NETBEANS: It is an IDE of Java which is used to create application with the help of predefined tools and wizards such as, palettes, design area, coding area, investigator and navigator window, properties, output window and etc.


RAD-(Rapid Application Development)-It refers to the methods of developing software through the use of predefined tools and wizards.

IDE: Integrated Development Environment: it is an interface by which a person can create application with the help of predefined controls and tools.
Netbeans IDE offers many features for application development, which are as follows:
1.Title Bar-It displays the title of the application.
2.Menu Bar-It contains different menus requires in application development.
3.Toolbar- It contains different tools required in application development.
4.GUI Builder-It is an area to place the component on the form visually.
5.Palette- It consists all the components needed to create application.
6.Inspector window-It display a tree hierarchy of all components contained in the currently open frame.
7.Properties window-It display all the properties of currently selected component.
8.Code Editor window- It is used to write code for a component used in application.

Do take a look to my website : http://www.angadsoni.webstarts.com
Follow me on facebook : fb.me/being.angadsoni
follow me on twitter :  www.twitter.com/angad57

Graphical Components
It is a component that defines a screen element.
They are of two types:
a. Parent Control/Container control-These are the components that hold other controls, eg-frame, panel etc.
b. Child control- These are the controls that placed inside the container or parent control, eg- textfield, label etc.
When we delete or move parent control than the child control will be deleted or moved simultaneously.

Character Set
Netbeans support UNICODE character set.
Set of valid characters that a language can recognize. Character set of Java contains Numbers from 0-9, alphabets-both small and capital, special symbols.Unicode support almost every language of world that's why it is known as Univesal code.

Tokens:They are the smallest individual unit in a program code.
They are Identifiers, Literals, Keywords, Punctuators and Operators.
Identifiers: They are some name given to a memory, program, function, class and etc.
Rules for identifiers:
1. They must not be keywords.
2. They must not use any special symbols not even space.
3. They consist of alphabets, number, underscore and dollar sign only.
4. First letter must be alphabet, underscore or dollar sign.
5. They are case sensitive that means upper case and lower case letters are treated differently.

Literals: They are the fixed values. They are
a. Integer literal-numeric value without decimal point.
b. Floating point literal-numeric value having decimal point.
c. Character literal- any single character that must be enclosed in single quote.
d. String literal- single character or group of characters that must be enclosed in double quotes.


Keywords: These are the words with predefined meaning, we can use these words but we cannot change their meaning.
Visit : www.angadsoni.webstarts.com
Take a look at my ##youtube channel : Being Technised




Punctuators: These are the symbols that are used as separators and having their specific meaning in program. They are .  ,  ; { } [ ] ( )

Operators: They are the symbols that are used to perform specific operations on one or more than one operands. On number of their operands they are classified in three categories-Unary(Single
operand),Binary(Two operands),Ternary(Three operands).
There are many operators provided in Java, they are:
1. Arithmetic operator   + - / * %
2. Relational operator > < >= <= == !=
3. Logical operator && || !
4. Assignment operator =
5. Increment and decrement operator ++ --
6. Conditional operator ? :

Q. What is the difference between assignment operator (=) and comparison operator (==)?
A. Assignment operator is used to assign right hand side value either derived from some expression or given by user to left hand side variable, whether comparison operator is used to compare values on both side of the operator.

Increment and Decrement operator
Increment (++) operator is used to increase value of any variable by one.
Decrement (--) operator is used to decrease value of any variable by one.
Both operators can be classified in PRE or POST
Pre-Increment: ++A This statement first increase value of variable A and that perform other operation.
Eg-lets take value 10 in A
B=++A;
First: A=A+1; A=11
Than this value assigned to B
Means value of B=11
Post-Increment: A++ This statement first perform other operation than it will increase value of variable A.
Eg-lets take value 10 in A
B=A++;
First: Value of A is assigned to B i.e, B=10
Than A=A+1; A=11

Same for decrement operator.

Variable
It is a named memory location that is used to store value given by user or derived from some expression. We can change this value during execution of program, and it is temporary in nature.
Declaration
Datatype variable;
Initialization:
Datatype variable=value;

Q.What is the difference between declaration and initialization of variable?
A. Declaration means to declare a memory for use, with some name following rules for identifiers, Initialization means to assign value in variable at the time of declaration.

Data Types
They refers to what kind of value user should enter and how that value stored in memory like type, size, range and operations can be performed on that values.
There are two types of data types:
1. Primitive Data types: These are the data types provided by compiler, they are of four types.
a. Numeric Integral Primitive type:Byte, Short, Int, Long
b. Fractional Primitive type: Floar, Double
c. Character Primitive type: Char
d. Boolean Primitive type: True,false

2. Non-Primitive Data types: They are also known as reference data type, these are     
constructed from primitive type

Methods and Properties
Methods: These are the task performed by any component.
They are of two types a.Getters b.Setters
Getters are those methods which are used to take input from components,eg are getText( ),isEditable( ),isEnabled( ).
Setters are those methods which are used to set value on components,eg are setText( ),setVisible( ),setEditable( ).
Properties: Characteristics and appearance of any component.

Text interaction in Java
Text interaction can be done by using four methods.
a. getText( ) method: it is used to return the text stored in a text based GUI component.
b. setText (  ) method:  it is  used to store or change text in a text based GUI component
c. parse.. ( ) method: This method is used to convert string value to different numeric types.
(i) byte variable=Byte.parseByte(String value);convert string value to byte type.
(ii)    short variable= Short.parseShort(String value);convert string value to short type.
(iii)    int variable = Integer.parseInt(String value);convert string value to int type.
(iv)   long variable= Long.parseLong(String value);convert string value to long type.
(v) float variable= Float.parseFloat(String value);convert string value to float type.
(vi) double variable= Double.parseDouble(String value);convert string value to double type.
d.  JOptionPane.showMessageDialog( ): used to show message in a dialog box with ok button.

Non-GUI output Methods
(i) System.out.print ( )- used to display result on output window, below code editor window.
(ii) System.out.println( )- used to display result and than throws the cursor on next line.

CONVERSION METHODS
1.parse( ) method is used to convert string value to numeric values. kindly refer to above topic for different variations in parse method.
2.toString( ) method is used to convert numeric value to string value.
Eg String st1=Integer.toString(int value);
String st1=Float.toString(float value);
String st1=Double.toString(double value);
String st1=Long.toString(long value);
3.valueOf( ) method is used to convert numeric value to string.
Eg String st1=String.valueOf(int value);
String st2=String.valueOf( float value);
String st3=String.valueOf(long value);
String st4=String.valueOf(double value);

PROGRAMS
1.WAP to find sum of two nos. given by user in text fields.
2.WAP to calculate all arithmetic functions on two nos. given by user.
3.WAP to calculate simple interest as per given principle, rate and interest.
4.WAP to swap values of two variables.
5.WAP to swap values of two variables without using third variable.
6.WAP to calculate bill as per given price, quantity and discount. Display total price along discounted price.
7.WAP to calculate Gross pay and Net pay as per given criteria, take Basic as input from user and use following allowances as given:
HRA=30% of basic pay.
TA=60% of basic pay.
DA=80% of basic pay.
MED=30% of basic pay.
CON=20% of basic pay.
NP=Basic+HRA+TA+DA
GP=NP-MED-CON
8.WAP to calculate Gross pay and Net pay as per values given by user, take  hra, ta, da, med, con in percentage form from user and use following formulae:
NP=Basic+HRA+TA+DA
GP=NP-MED-CON

Control Structure or Flow of Control:
These are the statements which are used to control flow of execution of program. If you want to skip any statement or you want to execute any statement or group of
statement more than one time. They are Conditional statement and Iterative Statement (looping).

Conditional Statements
These are the statements which are used to execute any statements depend on some particular condition, every condition will return Boolean value either True or False, if it return True than the subsequent statement or group of statement will be executed and if the condition will return false than no statement will be executed. We have no. of conditional statements:
IF STATEMENT,IF ELSE STATEMENT,IF ELSE IF ELSE IF ELSE STATEMENT,SWITCH CASE

IF STATEMENT
  In this statement first condition will be checked and than statement2 will be executed only if condition returns true and if condition is false than no statement will be executed.
Syntax:                                       
If( condition )
Statement1;


IF ELSE STATEMENT
  In this statement first condition will be checked and than subsequent statement2 will be executed only if condition returns true and if condition is false than Statement3 will be executed.
Syntax:                                       
If( condition )
Statement2;
Else
Statement3;




for Mysql Tutorial blog   : ipmysql.blogspot.com
take a look at my instagram profile : www.instagram.com/being_angadsoni





IF ELSE IF ELSE IF ELSE STATEMENT
  In this statement first condition1 will be checked and than subsequent statement2 will be executed only if condition returns true and if condition is false than condition2 will be checked than statement3 will be executed if condition 2 will be false than condition 3 will be checked and if this condition is true than statement 4 will be executed and if condition 3 is false than statement 5 will be executed.
Syntax:                                    
If( condition1 )
Statement2;
else if(condition 2)
Statement3;
else if(condition 3)
Statement4;
else
Statement5;

SWITCH CASE STATEMENT
It is another type of conditional statement that replace multiple IF statement and IF ELSE IF ELSE STATEMENT.
Syntax:
switch(Expression)
{
case value1:      statement1;
  break;
case value2:      statemenr2;
  break;
case value3:      statement3;
                                                       break;
default:              statement4;
}
Value of expression is checked by value1 or value2 or value3,if expression value match with any value than statement written in front of them will be executed. The
Variable / expression in the switch statement should either evaluates to an integer value or character value. When no value matches with expression value then default statement will be executed.

Break statement will break the block and if break statement is missing than FALL THROUGH problem will arise.

Q. How if else if else statement is different from switch case statement?
A.We can use all relational operator in if else If else statement but switch case works only with comparison operator( ==).

PROGRAMS
9.WAP to find whether the given no is positive or negative.
10.WAP to find whether the given no is odd or even.
11.WAP to find maximum out of two nos.
12.WAP to find maximum out of three nos.
13.WAP to find minimum out of two nos.
14.WAP to find minimum out of three nos.
15.WAP to calculate simple Interest as per given criteria:
Principle is greater than equal to 10000 than rate of interest will be 7%
Principle is less than 10000 than rate of interest will be 5%.
16.WAP to calculate bill as per given quantity and price for individual unit.
Amount=price * quantity
Amount is greater than equal to 25000 than discount will be 30%.
Amount is greater than equal to 20000 than discount will be 25 %
Amount is greater than equal to 15000 than discount will be 20 %
Amount is greater than equal to 10000 than discount will be 15 %
Amount is greater than equal to 5000 than discount will be 5 %
Amount is less than 5000 than discount will be 2 %
Display net amount and discounted amount also.
17.WAP to find nos of notes in a given currency.
18.WAP to print weekday name as per given no.
19.WAP to print MR or MS in prefix of your name as per selected radiobutton


20.WAP  to calculate wages as per given criteria:
  Take no of days from user in text field and select whether the labor is male or female, If labor is male than wage is 200 and If labor is female than wage is 150.
If labor is skilled than additional 50 rs per day will be remunerated.
Calculate wages for labor.

21.Calculate bill as per given conditions:

Take quantity and price in respective text fields.
Discount will be offered on the basis of radiobutton selection, if credit card has been selected than 10% discount, if cheque has been selected than 5% discount will be awarded, and if cash has been selected than 25% discount will be given to user.
If membership card is selected than 5% additional discount will be awarded.


22.Create question no 12 by using combo box instead of radiobutton.
23.Create question no 13 by using combo box instead of radiobutton.
24.WAP to  calculate simple interest by selecting rate from combo box.


ITERATIVE STATEMENT OR LOOPING STATEMENT
When we want to execute a statement or group of statement more than one times, than we use looping or iterative statement.
There are three types of loops for loop, while loop, do while loop.
Four major parts of loop
Initialization-first value given to counter variable from where we start counting iteration of loop.
Condition checking or testing-this statement is responsible for checking, whether loop will execute or not. Loop will be executed until condition become false.
Update statement (increment or decrement)-this statement is responsible for increase or decrease value of counter variable.
Body of loop-these are the statement(s) that will be executed until the condition become false.

Iterative statements are categorized in two categories:
Entry control loop-these type of loop check condition at the beginning of loop. If condition is false than this loop will not executed once.Eg are for ,while loop.
Exit control loop-these type of loop check condition at the end. If condition is false after that this loop will be executed one time.Eg do.while loop.

FOR LOOP


First 1(initialization) will be executed and than 2(condition) will be checked and if condition is true than statement1 and statement2(body of loop) will be executed and than 3(update) will be executed and next iteration will be executed after checking the condition, if this condition will return false than loop will be terminated.
If you have only one statement in body of loop than there is no need of curly braces Curly braces are known as block.
This loop is use for finite nos. of iteration.
PROGRAMS
25.WAP to print series of natural nos. upto 10.
26.WAP to print series of natural nos. from 10 to 1.
27.WAP to print series of natural nos. upto n .
28.WAP to  print series of even nos. upto n.
29.WAP to print series of odd nos. upto n.
30.WAP to print series of square nos upto n.
31.WAP to print table of a given no.
32.WAP to print sum of natural nos upto n.
33.WAP to print sum of even and odd nos. upto n and display them in two separate text fields.
34.WAP to find factorial of a given no.
35.WAP to find series from minimum to maximum.
36.WAP to print Fibonacci series upto n.
37.WAP to find square root of a given no.
38.WAP to find whether the given no is prime or not.
39.WAP to find sum of series :
1/1 + 1/ 4+ 1/7+ 1/10+ 1/13+ 1/16+ 1/19+ 1/22+ 1/25
40. WAP to find sum of series:
1+3.5+6+8.5+11+13.5+16+18.5+21+23.5



WHILE LOOP
  This loop is used when we do not know no. of iterations.
1(Initialization) statement is written outside the loop, if 2(condition) is true than we will enter in loop and then 3(update) statement will be executed and than move to next iteration only if condition is true, otherwise loop will be terminated.

PROGRAMS
41.WAP to print series of natural nos. upto 10.
42.WAP to print series of natural nos. from 10 to 1.
43.WAP to print series of natural nos. upto n .
44.WAP to  print series of even nos. upto n.
45.WAP to print series of odd nos. upto n.
46.WAP to print series of square nos upto n.
47.WAP to print table of a given no.
48.WAP to print sum of natural nos upto n.
49.WAP to print sum of even and odd nos. upto n and display them in two separate text fields.
50.WAP to find factorial of a given no.
51.WAP to find series from minimum to maximum.
52.WAP to print Fibonacci series upto n.
53.WAP to find square root of a given no.
54.WAP to find whether the given no is prime or not.
55.WAP to find sum of series :
1/1 + 1/ 4+ 1/7+ 1/10+ 1/13+ 1/16+ 1/19+ 1/22+ 1/25
56. WAP to find sum of series:
1+3.5+6+8.5+11+13.5+16+18.5+21+23.5

57.WAP to find no. of digits in a given no.
58.WAP to find sum of all digits in a given no.
59.WAP to find reverse of a given no.
60.WAP to find whether the given no is Palindrome or not.
61.WAP to find whether the given no is Armstrong or not.
62.WAP to find sum of even and odd digits in a given no.


DO WHILE LOOP
  This is an example of exit control loop.
First 1(initialization) take place than loop will be executed once than 2(update) statement executed than condition will be checked, if condition return Boolean value true than only loop moves to next iteration else loop will be terminated.

PROGRAMS
63.WAP to print sum of all nos. given by user randomly until user press zero. When user press 0 it will show sum of all entered nos.
64. WAP to print maximum out of all nos. given by user randomly until user press zero. When user press 0 it will show maximum out of all entered nos.
65.WAP to find m to the power n.
66.WAP to find factors of a given no and also count the no of factors.

PROPERTIES AND METHODS OF VARIOUS CONTROLS
jFrame
defaultCloseOperation:set action to be performed when user clicks on close button.
Title:sets the text to be displayed in the title bar of the form window.

jButton
Background:set the background color of button.
Enabled:make button enable or disable.
Font:sets the font
Foreground:set the foreground color
Horizonatal Alignment:use to set horizontal alignment of text written on button.
Label:sets the display text.
Text:sets the display text but also allow HTML tags for formatting.
getText( ): use to retrieve text written on button. It will return string value.
String var=button.getText( );
setText( ): use to set text on component.
Button.setText(string);
setEnabled( ): use to make button enable or disable
for enable: Button.setEnabled(True);
for disable:Button.setEnabled(False);
setVisible( ): use to make button visible or invisible
for visible:Button.setVisible(True );
for invisible:Button.setVisbile(False);

jTextField
This control is used to take input from user in string form and it can be used to display output to user.It is editable control.
Border:set the type of border that will surround the textfield.
Editable: make textfield editable or uneditable.
toolTipText:sets the text that will be displayed when we move cursor over the textfield.
isEditable( ):this method is used to check whether the textfield is editable or not.
boolean var=textfield.isEditable ( );
isEnabled( ):this method is used to check whether the textfield is enabled or not.
boolean var=textfield.isEnabled( );
setEditable( ): this method is used to make textfield editable or uneditable.
For editable=textfield.setEditable(True);
For uneditable= textfield.setEditable(False);
jLabel
This control is used to display message to user only.It is uneditable control.
having same properties and methods as jTextField

Q: What is the difference between textfield and label?
A: Textfield is editable control and label is undeditable control.

jTextArea
This control is also used to take input from user and display output like textfield,but the difference between textfield and textarea is in textarea we take multiple line input and we can display multiple line output.
columns: set nos. of columns to be displayed.
lineWrap:when text reaches at the end of textarea, cursor will move to next line.
wrapStyleWord:sends word to next line in case lineWrap is true and it results in breaking of a word, when lines are wrapped.
append( ):adds data at the end
TextArea.append(String);
jPassword
This contol is used to take password from user.
echochar:sets the character to be displayed instead of text.

jRadioButton
This control is used to select single option from multiple options given to user.
buttonGroup: specifies the name of the group of button to which the jRadioButton belongs.
Selected: sets the button as selected, if set to true, default is false.
isSelected( ): Returns true if the component is checked  else return false.
boolean var=jRadioButton.isSelected( );
setSelected( ):used to set radiobutton selected or unselected radiobutton.
jRAdioButton.setSelected(Boolean val);

jCheckBox
This control is used to select multiple choices from multiple options.
Methods and properties are similar to jRadioButton.

jCombBox
This type of control is used to display list of element to user,jComboBox are similar to jRadiButtons, like radiobuttons combobox also select single value from multiple values but radiobuttons occupy lots of space on frame but combobox use to save space on frame.

model: contains the values to be displayed in the combobox.
selectedIndex:sets the index number to the element which should be selected by default.
selectedItem:sets the selected item in the combobox.selectedItem and selectedIndex are in synchronization with each other.
getSelectedItem( ):used to return selected object from combobox at run time.
Object var=combobox.getSelectedIndex( );
getSelectedIndex( ):used to return index of selected item from combobox at run time.
int var=combobox.getSelectedIndex( );
jListBox
This type of control is used to display list of element to user,jListBox are similar to jcheckBox, like checkBox select multiple values from given values but checkbox occupy lots of space on frame but listBox  use to save space on frame.
selectionMode
Single:use to select single value
Single Interval:use to select single continuous selection of options using shift key.
Multiple Interval: use to select multiple selections of options using ctrl key.
getSelectedValue( ):Returns the selected value when only a single item is selected, if multiple items are selected than returns first selected value. Returns null incase no item is selected.
Object obj=list.getSelectedValue( );
isSelectedIndex(( )=Returns true if specified index is selected.
Boolean val=list.isSelectedIndex( int index);

jOptionPane
This component is used to take input, display message and take confirmation from user.
There are three methods
showMessageDialog( ): shows a one button, modal dialog box that gives the user some information.
jOptionPane.showInputDialog(this,”hello” );
showConfirmDialog( ):shows a three button modal dialog that asks the user a question. User can respond by pressing any of the suitable buttons.
jOptionPane.showConfirmDialog(null,”quit?” );
showInputDialog( ):shows a modal dialog that prompts the user for input. It prompts the user with a text box in which the user can enter the relevant input.
jOptionPane.showInputDialog(null,”name “ );

ACTIVITY
1. Observe the following code carefully and find which statement will never et executed in the code? 2013
int t=1;
do
{
If(t>13)
Tf.setText(“something”);
else
Tf.setText(“Pass);
t+=3;
}while(t<=15);
2.Write a java statement to make the textfield non-editable. 2013
3.What is the difference between textfield and password field? 2013
4.The variable/expression in the switch statement should either evaluate to an integer value or character value. State true or false. 2013
5.While making a form in Netbeans,Ms Jaya Laxminathan wants to display a list of countries to allow the users to select their own country. Suggest her to choose most appropriate control out of listbox and combobox. 2012
6.What is the purpose of break keyword while using switch case statement? Illustrate with the help of an example. 2012
7.List two purpose of ‘+’ operator. 2012
8.Write the output of following code in java. 2012
int x=0;
while(x<=1)
{
System.out.println(“X”);
x=x+1;
}
9.What happen if we do not include BREAK statement with a CASE in a SWITCH statement? 2012
10.While working on netbeans Ms Kanta wants to display cleared or reattempt required message depending upon the marks entered in textfield. Help her to choose more appropriate statement out of If statement and switch statement. 2011
11.Name any two loop control structure provided by java. 2011
12.What is the significance of default clause in a switch statement? 2011
13.Write two points of difference between a while loop and a do while loop? 2011
14.The statement i++ is equivalent to__________
15.What do you understand by Keyword? Why keywords cannot be identifier?
16.What will be the result of following two expression if, initially x=15;
(i)x++<=15 (ii)++x<=15
17.Mention two forms of increment and decrement operator used.
18.Java is case sensitive language. Is it true or false?
19.Name the method that displays message in a dialog box in Java.
20.What is the difference between System.out.print( ) and System.out.println( )methods?
21.What are relational operator?
22.How many times will the following loop executes? Which one o them is entry control and which one is exit control? 2013
Loop1 Loop2
int i=10,sum=0;
while(i>1)
{
sum+=1;
i-=3;
} int i=10,sum=0;
do
{
sum+=1;
i-=3;
}while(i>1);
23.Mr.Kapoor is a programmer at  Ekasnsh enterprise. He created 5 digit password and stored in a string variable called strpassword. He wants to store the same password in an integer type variable called intpassword. Write an appropriate java statement to transfer the content from strpassword to intpassword. 2013
24.What will be the content of jTextArea1 and jTextField1 after the execution of the following statement. 2013
a.jTextArea1.setText(“just\tAnother\nday”);
b.String subject=”informatics practices”;
c.jTextField.setText((subject.length( )+10)+” “);
25.Rewrite the following program code using a if statement 2013
String Remarks;
int code=Integer.parseInt(jTextField1.getText( ));
switch(code)
{
case 0:Remarks=”100% Tax Exemption”;break;
case 1:Remarks=”50% Tax Exemption”;break;
case 2:Remarks=”30% Tax Exemption”;break;
default:Remarks=”invalid entry”;
}
26.What will be displayed in jTextField1 and jTextField2 after the execution of the following code?2013
int last,first=3,second=5;
last=first+second++;
jTextField1.setText(Integer.toString(last));
jTextField2.setText(Integer.toString(second));

27.What will be the contents of str1 and str2 after the following code is executed 2013
String str2,Str1;
Str1=”Dear friend”;
Str2=”hello”;
Str1=Str1.concat(Str2);
28.What will be the output of the following statement?
jTextfield1.setText(“1”+3);
29.What will be the output of the following program segment?
int x;
x=5;
jTextArea1.append(String.valueOf(x++) );
jTextArea1.append(String.valueOf(x) );
jTextArea1.append(String.valueOf(++x) );
30.What will be the output of the following program segment?
int r,x=50,y=10;
r=(x>45)?x:y;
jTextField1.setText(String.valueOf(r) );
31.What will be the output of the following program segment?
int a;
a=25+4-4;
jTextField1.setText(String.valueOf(a) );
32.What would be the output of the following program?
int a=1,b=2,c=4;
a=c+ ++b/c;
jTextField1.setText(String.valueOf(a) );
33.What would be the output of the following program?
float P=10.45F;
P=P++ +1;
jTextField1.setText(String.valueOf(P) );
34. What would be the output of the following program?
int p=10,k=20;
k=k/++p;
jTextField1.setText(String.valueOf(k) );
35. What would be the output of the following program?
float num;
num=4+ (float)7/(int)2.0;
jTextField1.setText(String.valueOf(num) );
36. Determine the output.
int i=7;
jTextArea1.append(String.valueOf(++i));
jTextArea1.append(String.valueOf(i));
jTextArea1.append(String.valueOf(i++));
37. Determine the output.
int z,x=5,y=-10,a=4,b=2;
z=x++ - --y*b/a;
38.What is conditional operator? What will be the output of the following expression:
y-x<500/150:50
(a)x=300 y=700
(b)x=700 y=800
39.what output will the following code fragment produce when you input value for variable val?
int val,res,n=1000;
res=n+val>1750?400:200;
40.What will be the value of the following ,If j=5,initially
a.(5*++j)%6 b.(5*j++)%6
41.Find the output of the following
a. int x=2;
int y=++x;
jTextArea1.append(String.valueOf(x));
jTextArea1.append(String.valueOf(y));
jTextArea1.append(String.valueOf(x++));
b. int x=1;
int y=x++;
jTextArea1.append(String.valueOf(x++));
jTextArea1.append(String.valueOf(y+x));
jTextArea1.append(String.valueOf(++y));
42. What is the difference between:
a.num=10 b.num==10
43. What is the output of the following statements?
a. int i=2-;
jTextArea1.append(String.valueOf(i)+”\n”);
jTextArea1.append(String.valueOf(i++)+”\n”);
jTextArea1.append(String.valueOf(++i));
b. int i=1,a=3;
i=a++;
jTextField1.setText(String.valueOf(i));
c. int z,x=3,y=2;
z=--x+y++;
jTextField1.setText(String.valueOf(z));
44. Determine the output
int a=5;
int b=++a;
jTextArea1.append(String.valueOf(a));
jTextArea1.append(String.valueOf(++a));
jTextArea1.append(String.valueOf(b));
jTextArea1.append(String.valueOf(b++));
jTextArea1.append(String.valueOf(a));
jTextArea1.append(String.valueOf(b));
45. Determine the output
int a=10,b;
b=a++ + ++b;
jTextArea1.append(String.valueOf(b));
jTextArea1.append(String.valueOf(a++));
jTextArea1.append(String.valueOf(a));
jTextArea1.append(String.valueOf(++a));
46. Determine the output
int x=5,y=5;
jTextArea1.append(String.valueOf(x++));
jTextArea1.append(“,”);
jTextArea1.append(String.valueOf(++x));
jTextArea1.append(“,”);
jTextArea1.append(String.valueOf(y++));
jTextArea1.append(“,”);
jTextArea1.append(String.valueOf(++y));
47.What value will be stored in different variable when the following java statements are executed?
int i=10;
int j,k,l,m,n;
j=i+5;
k=i+j/5;
l=k+1;
m=l+1-I;
n=k+m*l;
jTextArea1.append(String.valueOf(i)+”\n”+Strin.valueOf(k)+”\n”+String.valueOf(l)+”\n”+String.valueOf(m)+”\n”+String.valueOf(n));

48.Write result of the following Java statements
int a=10,b=4,c,d;
c=++a- b-- *2;
d=a/2 * 5- --b;
jTextField1.setText(String.valueOf(c));
jTextField2.setText(String.valueOf(d));
49.Write a java code that take the price of a pencil from jtextfield1 and quantity of pencils from jtextfield2 and calculates total amount as price * quantity to be displayed in jtextfield3 and also find 10% tax amount to be displayed in jtextfield4. 2011
50.Write java code that takes value for side of a square in jtextfield1 and calculate area of it to be displayed in jtextfield2.   2012

51.Write java code that takes value for a number in a jtextfield1 and cube of it to be displayed in jtextfiel2.
52.The code is given a string object named salary having value as “55000” stored in it. Obtain the output of the following:
jOptionPane.showMessageDialog(null,” “ +salary.length( )+Integer.parseInt(salary));
53.An workerid consist of 4 digits is stored in string variable strwrkid. Now Mr.Jai wants to strore this id in integer type variable intwrkid.Write a Java statement to do this.
54.Item code consists of 6 digits is stored in an integer type variable intItemCode.Mrs.Sriniwas wants to store this item code in string type variable called stritemcode. Write appropriate java statement to help her performing the same.
55.What will be the content of the jtextarea1 after executing the following code. Assuming that the jtextarea1 has no content before executing this code. 2012
for(int i=2;i<=5;i++)
jtextarea1.setText(jtextarea1.getText( )+””+Integer.toString(i*i) );
56.What will be the values of A and B after execution of the following code: 2011
int A=100,B;
for(B=10;B<=12;B++)
A+=B;
jOptionPane.showMessageDialog( this,”A:”+A+”B:”+B+” “);
57.What will be displayed in jTextArea1 after executing the following statement? 2012
jTextArea1.setText(“INDIA\nINCREDIBLE\tINDIA”);
58.Given a string object named Pay having value as”68000” stored in it.Obtain the output of the following 2012
jOptionPane..showMessageDialog(this,Pay.length( )+Integer.parseIng(Pay));
59.The following code has some error(s).Rewrite the correct code underline all the corrections made: 2011
Int P=3;sum=0;
{
sum=p;
p+=3;
}
While(p<=12)
jTextField1(Integer.tostring(sum));
60.What is the use of break keyword in Switch case statement? Illustrate with the help of an example.
**************************************************************************************
Wish you luck















JOptionPane
Their methods and their respective code and values to show message at output window.
MessagDialog
Value Equivalent Code Icon
-1 JOptionPane.PLAIN_MESSAGE No icon
0 JOptionPane.ERROR_MESSAGE X icon
1 JOptionPane.INFORMATION_MESSAGE I icon
2 JOptionPane.WARNING_MESSAGE ! icon
3 JOptionPane.QUESTION_MESSAGE ? icon
                                 
JOptionPane.showMessageDialog(null,"hello","love",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,"hello","love",0);  
                                       
JOptionPane.showMessageDialog(null,"hello","love",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"hello","love",1);

JOptionPane.showMessageDialog(null,"hello","love",JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(null,"hello","love",2);

JOptionPane.showMessageDialog(null,"hello","love",JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null,"hello","love",3);
 

ConfirmDialog
Return Value Equivalent Code Indication
0 JOptionPane.YES_OPTION YES button is pressed
0 JOptionPane.OK_OPTION OK button is pressed
1 JOptionPane.NO_OPTION NO button is pressed
2 JOptionPane.CANCEL_OPTION CANCEL button is pressed
-1 JOptionPane.CLOSED_OPTION User closed the dialog using X button

     int n= JOptionPane.showConfirmDialog(null,"WANT TO EXIT");
 
     if(n==0)
         JOptionPane.showMessageDialog(null,"YES BUTTON IS CLICKED","MESSAGE",1);
       
     if(n==1)
         JOptionPane.showMessageDialog(null,"NO BUTTON IS CLICKED","MESSAGE",1);
   
     if(n==2)
         JOptionPane.showMessageDialog(null,"CANCEL BUTTON IS CLICKED","MESSAGE",1);
 
     if(n==-1)
         JOptionPane.showMessageDialog(null,"CLOSE BUTTON IS CLICKED","MESSAGE",1);
   










61.What will be the output of  A and B after execution of the following code? 2011
int A=100,B;
for(B=1;B<=12;B++)
{
A+=B;
}
JOptionPane.showMessageDialog(this,”A:”+A+”B:”+B+” “);
62.What will be the content of the jTextArea1 after executing the following code:
for(int i=2;i<=5;i++)
{
jTextArea1.setText(jTextArea1.getText()+” “+Integer.toString(i*i));
}
63.What will be the content of the jTextArea1 after executing the following code
for(int c=2;c<=4;c++)
{
         jTextArea1.setText(jTextArea1.getText()+” “+Integer.toString(c*c));
}
64.What will be displayed in jTextField after executing following code.
int N=20;
N=N+1;
if(N<21)
jTextField.setText(Integer.toString(N+10));
else
jTextField.setText(Integer.toString(N+15));
65.Rewrite the following program code using a switch statement:
if(code==1)
Day=”Monday”;
else if(code==2)
Day=”Tuesday”;
else if(code==3)
Day=”Wednesday”;
else if(code==4)
Day=”Thursday”;
else
Day=”No Match”;
66.The following code has some errors. Rewrite the correct code underlining all the corrections made.
Int P=3;sum=0;
{
Sum=P;
P+=3;
}
While(P<=12)
jTextfield1(Integer.toString(sum));
67.The following code has some errors. Rewrite the correct code underlining all the corrections made:
int Total=0,jump=5
int I;
for(i=0;I=<15;i++)
{
Jump+=5;
Total+=Jump;
}
jTextArea1.showText(“”+Total);
68.What will be displayed in of jTextField1 after executing the following code?
int m=16;
m=m+1;
if(m<15)
jTextField1.setText(Integer.toString(m));
else
jTextField1.setText(Integer.toString(m+15));
69.Rewrite the following program code using switch statement.
if(code==1)
Month=”January”;
else if(code==2)
Month =”February”;
else if(code==3)
Month =”March”;
else if(code==4)
Month =”April”;
else
Month =”No Match”;
70.The following code has some errors. Rewrite the correct code underlining all the corrections made.
Int k=2;sum=0;
{
Sum=k;
K+=3;
}
While(k=<20)
jTextField1(Integer.tostring(sum));
71.The following code has some errors.Rewrite the correct code underlining all the corrections made.
Int Sum=0,Step=5;
int I;
for(i=0;i<=5;i++)
{
Step+=5;
Sum+=Step;
}
jTextArea1.showText(“”+Sum);
72.What message will be displayed after execution of the following code?
int Age=24,Relaxation=6;
int ModiAge=Age-Relaxation;
if(ModiAge<18)
JOptionPane.showMessageDialog(null,”Not Eligible”);
else
JOptionPane.showMessageDialog(null,Eligible”);
73.Rewrite the following program code using a If statement:
int C=jComboBox1.getSelectedIndex();
Switch(C)
{
case 0:FinalAmt=BillAmt;break;
case 1:FinalAmt=0.9*BillAmt;break;
case 2:FinalAmt=0.8*BIllAmt;break;
Default:FinalAmt=BillAmt;
}
74.What will be the values of variable ‘m’ and ‘n’ after the execution of the following code
int m,n=0;
for(m=1;m<=5;m++)
{
n+=m;
n--;
}
75.What is the effect of absence of break in switch case statement?
76.What happened if a semicolon is placed as the for and while statements terminator?
77.What is the difference between entry control and exit control loop?
78.Rewrite the following if else statement  construct using switch  case statement.
if(opt==1)
jlabel1.setText(“You entered one”);
else if(opt==10)
jlabel1.setText(“You entered ten”);
else if(opt==100)
jlabel1.setText(“you entered hundred”);
else if(opt==1000)
jlabel1.setText(“you entered thousand”);
else
jlabel1.setText(“invalid”);
79.What will be the corresponding outputs pf jTextField2 of the following code segment if the possible inputs in the jTextField1 are as follow?
i.10 ii.20 iii.30 iv.40 v.50
int Number;
String str=jTextField1.getText( );
Number=Integer.parseInt(str);
switch(Number)
{
case 10: jTextField2.setText(“ten thousand”); break;
case 20: jTextField2.setText(“twenty thousand”);
case 30: jTextField2.setText(“thirty thousand”); break;
case 40: jTextField2.setText(“forty thousand”);
default:  jTextField2.setText(“not enough”);
}
80.What will be the output of the following program segment?
int a=3;
a=a+1
if(a>5)
jlabel1.setText(Integer.toString(a));
else
jlabel1.setText(Integer.toString(a+5));
81.In the following if else statement which statement will be executed next if the value of a =5 and b=10?
a).if(a*a>=b)
a=a+1;
else
b=b+1;
b).if(a>4)||(b<7)
jlabel1.setText(“Greater”);
else
jlabel1.setText(“lesser”);
c).if((a*a)<b)
jlabel1.setText(a*a);
else
jlabel1.setText(a*b);
82.Find the output of the following program
for(int i=0;i<10;i++)
jTextArea1.append(String.valueOf(++i)+”\n”);
83.Find the output of the following program if lastnumber is 15
for(int i=0;i<=lastnumber;i++)
jTextArea1.setText(jTextArea1.getText()+” “+ Integer.toString(i) ) ;
84. Find the output of the following program
for(int i=12;i>5;i-=2)
jTextArea1.append(String.valueOf(i)+”\n”);
85. Find the output of the following program
int i,sum;
for(i=10,sum=5;sum<15;i++)
{
sum+=i;
jTextArea1.setText(“sum is:”+String.valueOf(sum)+”\n”);
}
86.Find the output of the following program
int c=0,i=2;
while(i<10)
{
c=++i-i*2;
}
jTextField1.setText(“c=”+String.valueOf(c)+”i=”+String.valueOf(i));
87.How many times will the following loops get executed?
x=5;y=36; while(x<=y)
x+=6;
88.Find the output of the following loop gets executed:
int i=1,sum=0;
while(i<=10)
{ sum=sum+ i;
i+=3;
} jTextField1.setText(String.valueOf(sum));
89.What will be the content of the jTextArea1 after executing the following code?
int Num=1;
do
{
jTextArea1.setText(Integer.toString(++Num)+”\n”);
Num=Num+1;
}while(Num<=10);
90.Find the output of the following program
int I,j,a=10,b=0;
for(i=0;i<=a;i++);
jTextField1.setText(String.valueOf(i));
for(j=0;j<=a;j++);
jTextField2.setText(String.valueOf(++j));
b=a;
++a;
b++
jTextArea1.append(String.valueOf(a)+”\n”+String.valueOf(b)+”\n”);
jTextArea1.append(String.valueOf(--b));
91.Find the output of the following program:
int N;
N=1;
while(N<=32)
{
N=2*N;
jTextArea1.append(String.valueOf(N)+”\n”);
}
92.Find the output of the following program:
int x,y;
x=5;
y=1;
while(x>0)
{
x=x-1;
y=y*x;
jTextArea1.append(String.vallueOf(y)+”\n”);
}
93.Find the output of the following code
int i=1;
while(i<10)
{
jTextArea1.append(String.valueOf(i)+”\n”);
i=i*2;
}
94.Write an appropriate for loop for the situation described below:
A loop is to be repeated 200 times, except the loop is to be terminated if the value of the variable X become 175.
95.How many times the following loop gets executed.
a.i=0;
do{
//statements
}while(i>20);
b.i=0;
while(i>20)
{ //statement }
96.Find out the output of the following
a. for(int i=10;i>6;i=i-2)
jTextArea1.setText(String.valueOf(i)+”\n”);
b.int i=1;
while(i<5)
{
jTextArea1.append(String.valueOf(i));
i=i*2
}
c.int total=0,sum=0,I;
for(i=0;i<10;i++)
sum+=I;
jTextField1.setText(String.valueOf(total));
d.for(int j=0;j<=10;j++)
jTextArea1.append(String.valueOf(++j));
97.What are the output of the following two code fragments ? Justify
a.int j=1,i=2;
while(++i<5)
j*=I;
jTextField1.setText(String.valueOf(j));
b.int j=1,i=2;
do
{
j*=i;
}while(++i<5);
jTextField1.setText(String.valueOf(j));
98. Find out the output of the following code
a. int i=0,x=0;
while(i<10)
{
if((i%2)==0)
{
x=x+i;
jTextArea1.append(String.valueOf(x)+”\n”);
}
i++;
}
b.int i=0;
for(i=1;i<=20;i++)
{
jTextArea1.append(String.valueOf(i)+” “);
i=i+2;
}
99.What will be the output of the following code
int i=0,x=0
do
{
if(i%5==0)
{
x++;
jTextArea1.append(String.valueOf(x)+” “);
}
++i;
}while(i<20);
jTextArea1,append(“\n”+String.valueOf(x));
100. What will be the output of the following segment?
int i,j,x=0;
for(i=0;i<5;++i)
{
for(j=0;j<I;j++)
{
x+=(i+j-1);
}
jTextArea1.append(String.valueOf(x)+” “);
}
101.What will be the output of the following segment?
int i=0,x=0;
for(i=1;i<10;i*=2)
{
x++;
jTextArea1.append(String.valueOf(x)+” “);
}
jTextArea1.append(“\n”+String.valueOf(x));
102.What will be the output of the following segment?
int i,j,k,x=0;
for(i=0;i<5;++i)
{
for(j=0;j<i;++j)
{
k=(i+j-1);
if(k%2==0)
x+=k;
else
if(k%3==0)
x+=k-2;
}
jTextArea1.append(String.valueOf(x)+” “);
}
103. What will be the output of the following segment.
int I,j,k,x=0;
for(i=0;i<5;++i)
{
for(j=0;j<I;j++)
{
switch(i+j-1)
{
case -1:
case 0: x+=1; break;
case 1:
case 2:
case 3: x+=3;
default: x+=3;
}jTextArea1.append(String.valueOf(x)+” “ );
}
jTextArea1.append(String.valueOf(x)+” “ );
}
104.What will be the output of following program segment?
int I;
for(i=0;i<10;i++)
{
if(i==5)
break;
jTextArea1.append(String.valueOf(i)+” “);}
105.What will be the output of the following segments?
a. int i;
for(i=1;i<10;i++)
  if(i==4)
jTextArea1.append(“I=”+String.valueOf(I));
b. for(int i=1;i<=3;i++)
for(int j=1;j<=4;j++)
jTextArea1.append(String.valueOf(i+j)+”\n”);
106.Find the output of the following program segment
for(int i=1;i<=5;i++)
{
jTextArea1.append(“\n”);
for(int j=0;j<=i;j++)
jTextArea1.append(“*”+” “);
}
107.What will be the output of the following program?
int v1=5,v2=10;
for(int x=1;i<=2;x++)
{
jTextArea1.append(String.valueOf(++v1)+”\t”+String.valueOf(v2--));
jTextArea1.append(“\n”+String.valueOf(--v2)+”\t’+String.valueOf(v1++));
}
108.Find the output of the following program
long number=7583241;
int first=0,second=0;
do
{
long r=number%10;
if(r%2!=0)
first+=r;
else
second+=R;
number/=10;
}while(number>0);
109.Analyze the following program segment and determine how many time the body of loop will e executed?
x=5,y=50;
while(x<=y)
{
y=y/x;
jTextArea1.append(String.valueOf(y)+”\n”);}
110.Convert the following segment into an equivalent do loop.
int x,c;
for(x=10,c=20;c>=10;c=c-2)
x++;
111. What will be the output of the following program?
int N;N=1;
While(N<=32)
{  N=N*2;
jTextArea1.append(String.valueOf(N)+”\n”);}
112.What will be the output of the following program?
int x,y;
x=5;
y=1;
while(x>0)
{
x=x-1;
y=y*x;
jTextArea1.append(String.valueOf(y)+”\n”);
}

113.What will be the output of the following program
String name;
int i;
boolean startword;
name=”Java NetBeans Programming”;
startword=true;
for(i=0;i<name.length( );i++)
{
if(startword)
jTextArea1.append(name.charAt(i)+”.”);
if(name.charAt(i)==’ ‘)
startword=true;
else
startword=false;
}
114.What is the difference between the use of jTextField and jPassword Field in a form?
115.”The variable/expression in the switch statement should either evaluate to an integer value or String value”.State true or false.
116.While making a form in Netbeans Ms Jaya Laxminathan wants to display a list of countries to allow the users to select their own country. Suggest her to choose most appropriate control out of listbox and combobox.
117.What is the purpose of break keyword while using switch case statement? Illustrate with the help an example.
118. What happened if we do not include Break statement with a Case in a Switch statemet?
119.Given the following  code fragement
if(a==0)
System.out.println(“Zero”);
If(a==1)
System.out.println(“One”);
If(a==2)
System.out.println(“Two”);
If(a==3)
System.out.println(“Three”);
Write an alternative code using If that saves on number of comparisons.
120.Rewrite the following using switch
if(ch==’E’)
eastern++;
if(ch==’W’)
               western++;
if(ch==’N’)
               northern++;
if(ch==’S’)
                southern++;
else
                unknown++;
121.How many times are the following loops executed?
a. x=5,y=50;
while(x<=y)
x=y/x;
b.int m=10,n=7;
while(m%n>=0)
{
m=m+1;
n=n+2;}
122.Given the following code fragment.
i=2;
do
{
System.out.println(i)
i+=2;
}while(i<51);
JOptionPane.showMessageDialog(nul,”Thank You”);
 Rewrite the above code using a while loop.
123. Given the following code fragment:
i=100;
while(i>0)
{
System.out.println(i--);
JOptionPane.showMessageDialog(null,”Thank You”);
Rewrite the above code using a do.while loop.
124.Rewrite following while loop into a for loop.
int
stripes=0;
while(stripes<=13) {
if(stripes%2==2){
System.out.println(“color code red”); }
Else{
System.out.println(“color code blue”);  }
System.out.println(“New Stripe”);
Stripes=stripes+1;}
125. Predict the output of following code fragment.
int n=0,j=7,i=3;
if(i>2)
{ n=1;
if(j>4)
n=2;
else
n=3;
} else
{ n=4;
if(j%2>=2)
n=5;
else n=6;}
JOptionPane.showMessageDialog(null,n);
126. Predict the output of the following code fragment
a. int i,j,n;
n=0;i=1;
do{
n++;i++;
}while(i<=5);
b.int i=1,j=0,n=0;
while(i<4)
{
for(j=1;j<=1;j++)
{
n+=1;
}i=i+1;
}System.out.println(n);
c.int i=3,n=0;
while(i<4)
n++;i--;
}System.out.prinln(n);
d.int j=1,s=0;
while(j<10)
{
System.out.print(j+”+”);
s=s+j;
j=j+j%3;
}System.out.println(“=”+s);
        << ....... This content is a copy of iphelpbyishwarskhangarot.blogspot.com's page but is                                                        slightly modifies for easy understanding ................>>
Take a look at MYSQL TUTORIAL   With sample questions :   http://adf.ly/1eXD8d or ipmysql.blogspot.com


and also mysql and netbeans JDBC connection to make any project with connectivity sample will be posted soon as http://adf.ly/1eXDB2 OR ipjdbc.blogspot.com (at present doesn't exists)



No comments:

Post a Comment