Sunteți pe pagina 1din 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 type”run ” 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
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 doesn’t 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
Our Hello World program still isn’t 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 must
be 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” B


A!=B A”not equal to”B
A<B A”Less then”B
A>B A “Greater than” B
A<=B A”Less than or equal to” B
A>=B A”Greater than or equal” B
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.

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<100)
{
System.out.println(n);
n=+ n;
• Do…while loop: format of do…while statement:
Do {
Statement
}
While (boolean expression)
For example:
Int n=1;
Do
{
System.out.println(n)
n=n+1;
} while (n<100);

• For loop: format of for loop


For (initialization; continuation condition; update)
Example: giong o tren.

4. explain what the exception is and how it can be handled.


Exception handling(the try…cacth statement)
The goal of exception handling is to be able to define the regular flow of the program in
part of the code without worrying about all the special cases.then, in a separate block of
code, you cover the exception cases. This produces more legible code since you don’t
need to interrupt the flow of the algorithm to check and respond to every possible
strange condition.
In practice what you do is write blocks of code that may generate exception inside try-
cacth block example’
Class exceptionHello {
Public static void main(string args[])
{ try
{ system.out.println(“Hello”)
System.out.printlin(args[])
}cacth(exception e) {
System.out.println(“hello whoever you are”)
} }}

Chapter 5 Array,File I/O and Streams


1. define “Array” with examples
- an array consists of contiguous chumks memory of predetermineds size
- arrays are fixed in size, so resources must be anticipated ans consumed in
advance.each element is the same size and must contain the same data type
- access to a particular element is very fast, because its location in memory can be
determined mathematically and accessed directly (offset from start of array
=subscript* element size).
For example:
2. explain how to declare, allocate and initialize arrays:
• 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;

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<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
4. 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 object
doesn’t 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 the
common 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 directly
or 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 item
from 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
• 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. It’s 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 employee
String 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 all
the 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


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 user’s
requirements, so it has to change.

S-ar putea să vă placă și