MY mENU


Tuesday 3 April 2012

Encapsulation:


“Encapsulation is defined as the process of binding the data and code together”. The concept of class achieves this. Member fields are treated as data and member functions are treated as
code. Both the members are protected from the external access by various access privileges. “Encapsulation is the process of grouping your application into logical parts”, “Encapsulation is
protecting the data members from external misuse”. 

      And, “Encapsulation is about separating information from other parts of the application that you want not to mess with that information. Encapsulation is not only protecting the data but, it's actually separating the data in such a way that there is no way to misuse them. The idea is, concern mainly with separation rather than protection but, ultimately you should attain protection”.

Object

An object is a simulation of the real-world entities. These simulated objects are capable of doing all or subset of activities that the real-world entities can do, depending upon the processing power and code that was used to simulate the object.



NOTE: “Designing an object” means designing a class and “Creating an object” means instantiating a class.


For example, consider a programer writing code for Car Race game. He is actually simulating
the real-world entity Car. He is now having a car object. This car object, he simulated, is capable of moving front, suddenly stop while moving, accelerate or decelerate the speed etc. But it is not capable to make you feel the odor of the smoke. The idea is, objects are simulation of real-world entities. Objects make programming easier. Objects are designed by programmer. Hence ultimately, programmer should design the object appropriately to make the programming easier.

To work with objects, we should be able to identify three key characteristics of objects:

  •  The object's behavior— what can you do with this object, or what methods can you apply to    it?
  •  The object's state— how does the object react when you apply those methods?
  •  The object's identity— how is the object distinguished from others that may have the same behavior and state?

Object's behavior: Objects have behavior. Behavior means what an object can do or more specifically how an object will respond for a particular thing. The behavior of an object is simulated via methods. The most obvious behavior of a car object is moving front. A programmer can simulate this in a method named moveFront().

Object's state: The combination of the values for all the attributes of an object is called the object’s state. The state of an object is achieved by the member fields. A programmer can have a field named isMoving to represent the moving state of the car object. See how the field fuelLevel change the reaction of the car object.

class Car{
public float fuelLevel;
                            //represent how much fuel is left in the fuel tank
public String no;
Car(String no){
this.no = no;
}
public void move(float speed){
//code simulating move
if(fuelLevel >1.0)
System.out.println(“Car Moving at speed “ + speed);
else //field fuelLevel changes the behaviour
System.out.println(“Car can't move:Low fuel level);
}
}

Object's identity: Even though many objects are of same type and same behavior, individually they are all different. So, we should have certain way to distinguish them. Java uses instances to achieve this. In the car race example car A, car B and car C are all have same behavior, are all of same type, but all are individually different. The instance of car A uniquely represents car A. new operator is used to instantiate an object.

Car myCar = new Car();
Car myNewCar = new Car();

myCar and myNewCar will never be equal and they uniquely represent two cars. Object Relationships.The most common relationships between classes are

• Aggregation ("has–a")
• Inheritance ("is–a")

We often use the phrases “is a” and “has a” while speaking. For example car is a vehicle, and
car has a music system. 

Aggregation (has-a) Relationship has-a relationship can be achieved by having a reference for a class in another class. Design a class MusicSystem and have a reference to it in the class Car.

Inheritance (is-a) Relationship Is-a relationship can be achieved by inheritance. Just create a class Vehicle, next create another class Car by extending Vehicle.

Disable Unsigned Driver Dialogue


First go to: Start Run

Then type: gpedit.msc and hit enter. Browse the folder tree to the following location User Configuration Administrative Templates System. Right-click Code signing for Device drivers and select Properties. On the Settings tab, either select  enable, and then select ignore from the appearing listbox..  or click the disable option. Click apply and Ok and your set!

Alternatively especially for XP Home users:

Open "System" properties (Windows key + pause or Right click 'My Computer' - properties or Control Panel - System).On the Hardware tab click the "Driver Signing" button. In the dialogue that comes up choose "Ignore" to install the new driver anyway.

Stop Noise


When using 3rd party burning software (eg, Nero Burning Rom) to copy audio CD,some noise may be heard at the end of each track. To prevent this,try the following method:
1. Enter System Properties\device manager
2. Select IDE ATA/ATAPI controllers
3. Double click on thee CD writer IDE channel
4. Select advance setting
5. Change the transfer mode to 'PIO Only'
6. Restart Computer

Automatically Killing Tasks on Shutdown


You know the drill. You start to shut down the computer, you wait a few moments, and then you see a dialog box asking if you want to kill an application or service that is running. Instead of prompting you, you can make Windows XP take care of the kill task automatically. Here's how:
1. Open the Registry Editor.
2. Navigate to HKEY_CURRENT_USER\Control Panel\Desktop.
3. Highlight the value AutoEndTasks and change the value to 1.
4. Close the Registry Editor.

Reducing the Wait Time


When you start to shut down Windows XP, it has to quit, or "kill," any live applications or processes that are currently running. So close all applications first. However, some applications and processes are always running in the background. You can reduce the amount of time that Windows XP waits for those applications and processes to close before Windows XP kills them.
1. Open registry editor
2. Navigate to HKEY_USERS\.DEFAULT\Control Panel\Desktop. Set theWait To Kill App Timeout and set the value to 1000. Select the HungAppTimeout\newline value and set it to 1000 as well.
3. Navigate to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control. Select the WaitToKillServiceTimeout value and set it to 10000.
4. Close the Registry Editor.

Speeding Up Your PPPoE Connection


If you use a Point-to-Point Protocol connection over Ethernet (PPPoE), you may notice a delay in using the PPPoE connection after startup. By default, there is a 120 second delay but you can stop this behavior by manually configuring an IP address for the network adapter card. If you do not use a PPPoE connection, you can skip this section.
1. Select Start/Connect to/Show All Connections.
2. Open the TCP/IP properties for your LAN network interface card.
3. Manually set the IP address on the TCP/IP properties to an appropriate IP address and subnet mask for your network.

FTP

File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host to another host over a TCP-based network, such as theInternet. It is often used to upload web pages and other documents from a private development machine to a public web-hosting server. FTP is built on aclient-server architecture and uses separate control and data connections between the client and the server.

HTTP

The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web.

When should a type cast be used?


There are two situations in which to use a type cast. The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly. The second case is to cast pointer types to and from void * in order to interface with functions that expect or return void pointers. For example, the following line type casts the return value of the call to malloc() to be a pointer to a foo structure. struct foo *p = (struct foo *) malloc(sizeof(struct foo));
36.What is a null pointer? There are times when it's necessary to have a pointer that doesn't point to anything. The macro NULL, defined in , has a value that's guaranteed to be different from any valid pointer. NULL is a literal zero, possibly cast to void* or char*. Some people, notably C++ programmers, prefer to use 0 rather than NULL. The null pointer is used in three ways:
 1) To stop indirection in a recursive data structure 
 2) As an error value
 3) As a sentinel value.

What is a "null pointer assignment" error? What are bus errors, memory faults, and core dumps?


These are all serious errors, symptoms of a wild pointer or subscript. Null pointer assignment is a message you might get when an MS-DOS program finishes executing. Some such programs can arrange for a small amount of memory to be available "where the NULL pointer points to" (so to speak). If the program tries to write to that area, it will overwrite the data put there by the compiler. When the program is done, code generated by the compiler examines that area. If that data has been changed, the compiler-generated code complains with null pointer assignment. This message carries only enough information to get you worried. There's no way to tell, just from a null pointer assignment message, what part of your program is responsible for the error. Some debuggers, and some compilers, can give you more help in finding the problem. Bus error: core dumped and Memory fault: core dumped are messages you might see from a program running under UNIX. They're more programmer friendly. Both mean that a pointer or an array subscript was wildly out of bounds. You can get these messages on a read or on a write. They aren't restricted to null pointer problems. The core dumped part of the message is telling you about a file, called core, that has just been written in your current directory. This is a dump of everything on the stack and in the heap at the time the program was running. With the help of a debugger, you can use the core dump to find where the bad pointer was used. That might not tell you why the pointer was bad, but it's a step in the right direction. If you don't have write permission in the current directory, you won't get a core file, or the core dumped message. 

Why should we assign NULL to the elements (pointer) after freeing them?

This is paranoia based on long experience. After a pointer has been freed, you can no longer use the pointed-to data. The pointer is said to "dangle"; it doesn't point at anything useful. If you "NULL out" or "zero out" a pointer immediately after freeing it, your program can no longer get in trouble by using that pointer. True, you might go indirect on the null pointer instead, but that's something your debugger might be able to help you with immediately. Also, there still might be copies of the pointer that refer to the memory that has been deallocated; that's the nature of C. Zeroing out pointers after freeing them won't solve all problems;

Can a variable be both const and volatile?


 This is possible and mostly used in embedded system.The example is Interrupt Status Register.As it is a status register , in the program we should not modify this variable.So it should be a constant.But this variable can be changed by the processor or hardware based on the interrupt condition.So when in the program ,we want to read the value of this varible , it should read the actual value with out any optimisation.For this reason ,the variable can be declared as volatile too.

How do you print an address?


we can print the address of a variable or a function using the following specifiers %u,%p here %u prints address in decimal form and %p prints in hexa decimal form,but remember these two format specifiers print only offset address but they doesn't print code segment address there is a another specifier %Fp which prints both the code segment and offset address

When function say abc() calls another function say xyz(), what happens in stack?


When some function xyz() calls function abc(). all the local variables, static links, dynamic links and function return value goes on the top of all elements of function xyz() in the stack. when abc() exit it's return value has been assigned to xyz().

Can include files be nested?

 Yes. Include files can be nested any number of times. As long as you use precautionary measures , you can avoid including the same file twice. In the past, nesting header files was seen as bad programming practice, because it complicates the dependency tracking function of the MAKE program and thus slows down compilation. Many of today's popular compilers make up for this difficulty by implementing a concept called precompiled headers, in which all headers and associated dependencies are stored in a precompiled state. Many programmers like to create a custom header file that has #include statements for every header needed for each module. This is perfectly acceptable and can help avoid potential problems relating to #include files, such as accidentally omitting an #include file in a module.

Can static variables be declared in a header file?


 You can't declare a static variable without defining it as well (this is because the storage class modifiers static and extern are mutually exclusive). A static variable can be defined in a header file, but this would cause each source file that included the header file to have its own private copy of the variable, which is probably not what was intended.

How can I open a file so that other programs can update it at the same time?

Your C compiler library contains a low-level file function called sopen() that can be used to open a file in shared mode. Beginning with DOS 3.0, files could be opened in shared mode by loading a special program named SHARE.EXE. Shared mode, as the name implies, allows a file to be shared with other programs as well as your own. Using this function, you can allow other programs that are running to update the same file you are updating. The sopen() function takes four parameters: a pointer to the filename you want to open, the operational mode you want to open the file in, the file sharing mode to use, and, if you are creating a file, the mode to create the file in. The second parameter of the sopen() function, usually referred to as the "operation flag"parameter, can have the following values assigned to it: Constant Description O_APPEND Appends all writes to the end of the file O_BINARY Opens the file in binary (untranslated) mode O_CREAT If the file does not exist, it is created O_EXCL If the O_CREAT flag is used and the file exists, returns an error O_RDONLY Opens the file in read-only mode O_RDWR Opens the file for reading and writing O_TEXT Opens the file in text (translated) mode O_TRUNC Opens an existing file and writes over its contents O_WRONLY Opens the file in write-only mode The third parameter of the sopen() function, usually referred to as the "sharing flag," can have the following values assigned to it: Constant Description SH_COMPAT No other program can access the file SH_DENYRW No other program can read from or write to the file SH_DENYWR No other program can write to the file SH_DENYRD No other program can read from the file SH_DENYNO Any program can read from or write to the file If the sopen() function is successful, it returns a non-negative number that is the file's handle. If an error occurs, –1 is returned, and the global variable errno is set to one of the following values: Constant Description ENOENT File or path not found EMFILE No more file handles are available EACCES Permission denied to access file EINVACC Invalid access code Constant Description