Académique Documents
Professionnel Documents
Culture Documents
this operators be can used to cmpare values of any numric type and char
type and they can not be used for string type.
For example : int a,b;
If(a==5) B=a;
Boolean operators: “And”, “&&”, “Or” (//), “not” (!) are boolean
operators. For example: (x==0) && (y==0): return true only when x=0
and y=0
A|| B: if A true or B is true
A!B: return true only when A different from B
Chapter 4 java control structures
1. explain how you understand the “Blocks” in programming:
the blocks(chuong ngai vat) is the simplest type of structured statement.
Its purpose(muc dich) is simply to group a se quence of statements into
a single statement.
Two example of blocks: {
System.out.println(“the answer is”);
System.out.println(ans); } {
//this block exchanges the value of the x and y
Int temp=x; //save a copy of the value of x in temp
x = y; //copy the value of y into x.
y= temp; //copy the value of temp into y. }
2. explain what the “loop” means in programming and.
3. what the use of “loop” provider some examples using different types of loops.
• Declaring arrays:
like other variables in java, an array must have a specific type like byte, string
or double. When you declare an array variable you suffix the type with [] to
indicate that this variable is an array.
For example:
Int[] k; Float [] yt;
String [] names;
Allocating Arrays:
to create the an array, use the new operation
k=new int[3];
the number in the brackets is dimension of the array.
• Initializing array: each element of array are referenced by
name and by an integer which represent position in the array.it begin with o
For example:
K[0]=2; K[1]=3; K[2]=5;
2. explain “bubble sort” with the exmple java code.
Bubble sort: is one of the simplest and the most popular algorithms.the idea of
bubble sort is to start at the top of the array,compare each element to the next
element.if it is greater than that element then we swap the two and so on. At
the end of process, then smallest value bubbles up to the top of array while the
largest value sinks to the bottom.
For example java code:
Import java.util.*;
Class bubbleSort {
Public static void main(string args[]) {
Int[] n; n=new int[10];
random myRand=new Random();
//initialize the array
For (int i=0, i<n.length; i++)
n[i] =myRand.nextInt(); }
//print the arrays initial order
System.out.println(“before sorting:”);
For (int i=0; i<n.length;i++) {
System.out.println(“n[“+i+”] =” + n[i]); }
boolean sorted= false ; //sort the array
While (! sorted) { Sorted=true;
For(int i=0; i<n.length-1; i++)
If (n[i] > n[i+1 ]) //swap if greater than….
Int temp=n[i]; N[i]=n[i+1];
N[i+1]=temp; Sorted =false;
} //if } //for } //while
//print the sorted array
System.out.println();
System.out.println(“after sorting:”)
For (int i=0; i<0; i++) {
System .out. println(“n[“+i+”]=” + n[i]);
} } //main } // class
Chapter 6 Object Oriented programming
1. understand the basic concept of object oriented programming
object-oriented programming (OOP) represent an attempt to make programs
more closely model the way people think about and deal with the world. In the
older styles of programming, a programmer who is faced with some problem
must identify a computing task that needs to be performed in order to solve the
problem.
3. define “object”and ”classes”
object: is a meaningful entity.it relates to the real world. It may be concept or it
may have an actual physical state.object are distanct in that two object may
have similar properties but they would still be considered as separate object.an
object instance refers to single object.
Classes: is a set or collection of abstracted object that share common
characteristics.it is a template for defining the method and variable for a
particular type of object .all object of a given class are identical in form and
behaviour but contain different data in their variables.classes contain object
with the same data structure and behaviour.
4. defin “constructor”
contructor: is call to a special type of subroutne called a construcor. Every
class a contructor. If the programmer doesn’t define one, the program will
provider a default constructor the only allocate memory and initialize instance
variable. A constructor does not hava return type the name of constructor must
be the same as the mane of class in which its defined .in particular,constructor
cant be declared static. It must be public ,private and protected
Chepter 10 debugging
1. dicuss why debugging is needed
- the environment does not remain static for very long therefore the
enterprise keeps changing and system also has to change
- during the working of system,it must be develop to meet user’s
requirements, so it has to change.