Soan Tai Lieu Lec Java
-
Upload
thuyhongluu -
Category
Documents
-
view
221 -
download
0
Transcript of Soan Tai Lieu Lec Java
-
8/9/2019 Soan Tai Lieu Lec Java
1/10
Lec java
Chapter 1: introduction to programming
1. define what the programming languages are
a computer can only work from a set of instruction in order to execute a
specific task. A set of instruction combinaed into a file is called a program.2. define what the programming language are:
3.differentiate Interpriter and compilers:
Compiler
- is the program that translate source code program into computer language
- first the source code is read into the computer memory
- then it will be translated into a kind of in between code: Object code
- a program will have many different object and libraries that need to be
linked together into one executable
the result is an executable file or program
interpreter
- is a program that read and executes instructions written in the from of a
program
- the trick of an interpreter is that is loads the source code and translates the
instruction into executable machine language line by line
- in order run a program you have to load the interpreter first then laod the
source code into the computer and then typerun to execute the program.
Chapter 2. the design processor
1. understand what the program specification is :the starting point for the design of any computer program must be a
proper(thich hop) specification of its intended behavior.2. list down different file types
- File types
- Serial file
- Sequential file
- Indexed sequential file
- Direct access file
-
8/9/2019 Soan Tai Lieu Lec Java
2/10
Chapter 3 the basic java application
1. basically understand of building a java application:
2. explain comment and command line arguments with sample code:
Comment
Comment is a program are entirely ignored by the computer; they are there
for human readers only. This doesnt mean that they are unimportant.
Program are meant to be read by people as well as by computer, and
without comments , a program can be very difficult to understand.
Command line arguments
OurHello World program still isnt very general. We can be change the
name we say hello to without editing and recompiling the source code.what
we need is a way to change the name at runtime rather than at compile time.For example: public class helloworld {
// a program to diplay the message
// hello world on standard output
Public static void main(string[]args) {
System.out.println(Hello);
System.out.println(args[0]);
}
}
3. define arithmatic operators and relational operators: arithmetic operators: include addition (+),substraction (-),
multiplication(*), and division(/).these operations can be used on
numeric type: int, long, short,... when calculate 2 values, they mustbe in type.if not the program will automatically convert one to
another. For example: 10+34.2. first, computer will change 10 to
10.0 then calculate 10.0+ 34.2
relational operation: used to test whether 2 values are equal,not
equal,or greater here are the meaning of operations:
A==B A equal to BA!=B Anot equal toB
AB A Greater than B
A=B AGreater than or equal B
-
8/9/2019 Soan Tai Lieu Lec Java
3/10
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 booleanoperators. 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.
A Loop is used to repeat a given Statement over and over.
3. what the use of loop provider some examples using different types of loops.
While loop: format of while loop: while (boolean expression) {statement}
For example: int n=1;
While (n
-
8/9/2019 Soan Tai Lieu Lec Java
4/10
Statement
}
While (boolean expression)
For example:
Int n=1;
Do{System.out.println(n)
n=n+1;
} while (n
-
8/9/2019 Soan Tai Lieu Lec Java
5/10
2. explain how to declare, allocate and initialize arrays:
Declaring arrays: like other variables in java, an array must have a specific typelike 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 operationk=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 oFor example:
K[0]=2;K[1]=3;
K[2]=5;
3. 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
-
8/9/2019 Soan Tai Lieu Lec Java
6/10
//sort the array
While (! sorted)
{
Sorted=true;
For(int i=0; 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
-
8/9/2019 Soan Tai Lieu Lec Java
7/10
contructor: is call to a special type of subroutne called a construcor. Every
class a contructor. If the programmer doesnt 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 protected4. explain garbage collection
Garbage collection in the responsibility of the system,not the programmer to keep
track of which object are gardege.if an object stored in several varialbes.the objectdoesnt become garbage until all those references have been dropped.
5.define inhertance,polymorphism and abstract classes
Inhertance:
- it refer to the fact that one class can inherit part or all of its structure and
bbhavior from another class.
- The class that does the inherting is said to be a subclass of the class from
which it inherits.
Polymorphism
- three classes,rectange,oval, and RoundRect,could be used to represent the
three types of shaped.
- These three classes would hava a common super class,shape, to represenet
features that all three shapes have in common.
- The shape class could include instance variables to represent the color,position, and size of a shape.it could include instance methods for changing
the color, position, and size of a shape.
Astracture class:
An abstract class is one that is not used to construct object, but only as a
basic for making subclasses. An abstract class exit only to express thecommon properties of all its subclasses.
It exists merely specify the common interface of all the actual, concrete
version of redraw () in the subclasses of shape. There is no reason for the
abstract redraw() in class shape to contain nay code at all.
Chapter 7 recursion and linked data structures
1. define recursion
A recursion is one that uses the concept or thing that is being defines as
part of the definetion.for example: an ancestor is either parent or an
ansestor of a parent. A recursion subroutine is one that calls itself directlyor indirectly.2. explain quick sort
Quick sort : quickly than bubble sort. Quick sort apply recursion algorithms
that base on a simple but clever idea: give a list of items, select any itemfrom the list.this item is called a pivot.move all items that smaller than
pivot to the left and all item that larger than the pivot the right.3.explain what is linked list with the illustraction and sample code
-
8/9/2019 Soan Tai Lieu Lec Java
8/10
Link List
A link list consists of a chain of object of the same type, linked together by
pointers from one object to the next. This is much like the chain of supervisor
between emp and the boss in the above example. Its possible to have move
complex situaltions, in which one object can contain links to serveral other
object.
For example:
Class employee {
//an object of type employee hold data about one employeeString name; // name of the employee
Employee supervisor; //the employees supervisor.
}
4. define stacks and queues
Stack: an, item, lower down on the stacks can only be removed after allthe items on top of it has been popped off the stack.s
Queue
- a queue has two ends called the front and the back of a queue.
- Items are always added to the
- Queues at the back and removed from the queue at the end
5. define what the binary tree means
-
8/9/2019 Soan Tai Lieu Lec Java
9/10
A binary tree : is a tree data structure in which each node has at most two
children. Typically the child nodes are called left and right.binary trees are
commonly used to implement binary search trees and binary heaps.
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 users
requirements, so it has to change.
-
8/9/2019 Soan Tai Lieu Lec Java
10/10