We are an award-winning tech entrepreneurship website where trusted experts can provide value globally.

Since 1998, DevX has helped people start businesses, build websites, and provide enterprise technology to people globally. Interviewing the likes of Microsoft’s co-founder, Steve Ballmer, the publication brings comprehensive, reliable, and accessible insights to the Internet.

devxlogo

Trusted for 26 years

Over 30K Articles

1M+ Readers

Expert-reviewed

10K+ Tech Terms

As seen in:

microsoft logo
business_insider_logo
wired_logo
berkley
arstechnica_logo
hackernoon

The Latest

DevX - Software Development Resource

Multithreading Applets—the Right Way

The canonical design of multithreaded applets is inherently flawed. You know what I’m talking about: the run method with the repaint/sleep statements embedded in a while(true). Any self-respecting operating systems

DevX - Software Development Resource

Conversion Operators

Sometimes, an object must be converted into a built-in type (for instance, a string object passed as an argument to C function such as strcmp()) : //file Mystring.hclass Mystring {

DevX - Software Development Resource

Correct syntax for automatic object instantiation

When you instantiate an automatic object (e.g., on the stack) using its default constructor, mind that the correct syntax is: String str; //correct And not this: String str(); //entirely different

DevX - Software Development Resource

IsA or HasA?

When designing a class hierarchy, you may face a decision between inheritance (aka IsA ) vs. containment (aka HasA) relation. For instance, if you are designing a Radio class, and

DevX - Software Development Resource

A base class destructor should be virtual

If a class may serve as a base class for others, its destructor should be virtual. This ensures RTTI support for objects of this class and objects derived from it,

DevX - Software Development Resource

A Simple, Easy, and Efficient Way to Initialize Structs

Struct instances created on the stack are uninitialized (i.e., contain garbage values). The easiest, most efficient, and future-proof way to initialize them is: struct PlainData {char [20] name;long ID;char [15]

DevX - Software Development Resource

Speed Swing Setup

In Swing 0.7, and probably later versions as well, the DefaultListModel class notifies its ListDataListeners every time a new element is added to the list model. For very large lists

DevX - Software Development Resource

iostream vs. printf()

C-style I/O is still supported in C++. However, the iostream objects offer 2 advantages over the printf() family: type safety and support for user-defined types. Consider the following example: void

DevX - Software Development Resource

JavaScript Multi-Dimensional Arrays?

Multi-dimensional arrays can be represented by arrays of arrays. For example, suppose that you want to create a 3×3 matrix, called Brady, and fill it with the strings shown in

DevX - Software Development Resource

Many Unhappy I/O Returns

The class java.io.PushbackInputStream in JDK 1.1.3 returns the wrong value from its available() method. If you look at the source code, it returns pos + super.available(); when it should really

DevX - Software Development Resource

Stomping the Windows File Bug

This bug workaround identifies Windows operating systems and adds an identifier to the absolute root directory path to avert file problems. File root;String tmp;tmp = System.getProperty(“user.dir”);root = new File(tmp);while((tmp =

DevX - Software Development Resource

Advantages of automatic storage vs. heap storage

Using operator new (or malloc() in C) to create objects on the heap is expensive in terms of performance (allocating heap memory usually involves a long negotiation with the OS),

DevX - Software Development Resource

delete vs. delete[]

Objects created using new [] must be released using delete [] as in this example. It

DevX - Software Development Resource

How to define an object-internal constant?

When you need a constant integer member in an object, the easiest way to create one is by using a nameless enum, which can be used like any const int:

DevX - Software Development Resource

Passing unmodifiable arguments as constobjects

Passing large objects by value as function arguments is very inefficient. On the other hand, passing them by reference/address is dangerous since it enables the callee to change its arguments

DevX - Software Development Resource

Prefer References Over Pointers

Even experienced C++ programmers who have prior experience with C tend to use pointers excessively whereas references may be a better choice. Pointers may result in bugs like the following:

DevX - Software Development Resource

Copy constructor and operator= go together

If you do not define a copy constructor and operator = , the compiler will create them automatically for you. However, there are cases when you have to define them

DevX - Software Development Resource

Better alternative to #define constants

Using #define to create macro constants is not ideal. Macros are substituted by the preprocessor, so the compiler usually cannot detect anomalies such as type mismatch (see example); furthermore, most

DevX - Software Development Resource

Explicit destructor invocation

One of the good things about destructors is that they are called automatically. There are rare cases, however, when you want to invoke an object

DevX - Software Development Resource

Make the Right Comparison

Although Java’s String package is a lot more friendly than C’s string handling, you can still find yourself surprised by its behavior at times. Consider this code: import java.lang.String;public class

DevX - Software Development Resource

What are we Looking at?

To present your applet in a visually pleasing way, it’s often handy to know the size of the screen that’s available for output. Fortunately, a built-in AWT function makes determining

DevX - Software Development Resource

A const member function

Whenever you define a class member function which does not (and should not) change its object, it’s a good idea to define it as a const member function. There are

DevX - Software Development Resource

Activate Your Applets

Did you ever feel the urge to use a nice Java class you just wrote as an ActiveX object on your Windows machine? Good news: you can do it in

DevX - Software Development Resource

Linked List vs. File I/O

Question: Can you explain to me how a linked list works with FILE I/O. For example, how do you add, modify, delete, and search for a student record in a

DevX - Software Development Resource

CL.EXE Error

Question: I installed MS Visual C++ 5.0 at work and on my home machine. At work it’s fine running on Windows NT with 96 megs of RAM. On my home

DevX - Software Development Resource

Variable-length data in structs

Question: Can I have variable length fields in a structure. I have tried something like: typedef struct { int length; char data[length];}; but that won’t compile. Is there a way,