devxlogo

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

Exception specification

A function that may throw an exception can warn its users about that by specifying a list of exceptions it may throw, thus helping its users to catch such exceptions

Operator overloading rules of thumb

When overloading an operator to support a user-defined type (object), it is best to adhere to the basic semantics of that built-in operator. For instance, the built-in operator ==, which

Advantages of bool type

Standard C++ supports a built-in Boolean type: Bool. Variables of this type are can be assigned either a true or false values exclusively ( true and false are now reserved

Struct assignment

Both standard C and Standard C++ support struct assignment using = . In fact, C++ programmers are often surprised to discover that assignment operator applies also to plain structs, and

Object I/O

Question: How can i add many java objects to a file then retrieve them as Java objects from the file? Answer: Java 1.1 introduced a concept called serialization. Serialization isa

Constant pointers

There are cases when you need to define a constant pointer to a variable/object; for instance, when taking a function address, or when you want to protect a pointer from

Namespaces are open

Unlike structs, classes, enums, and unions, the enclosing brace of a namespace definition does not prohibit you from further extensions to that namespace. A namespace can be extended this way:

Garbage Collection

Question: Is it possible to preserve an object from garbagecollection (to live as long as the applet)? Answer: Yes, it is possible to preserve an object from garbage collection andlive

Unix Signal Handling

Question: Is there a way in Java to handle Unix signals(i.e. to trap a Control C signal)? Answer: You can handle Unix signals only by writing native code. However, theJava

byte array to int conversion

Question: I have just read a packet of data into a byte array from a socket. At offsets 5-8, 9-12, and 13-16 are binary integers. How can I get them

Invocation of methods of a dynamically loaded clas

Question: I have two classes in two separate files. I don’t want to use an interfacebecause the types of objects I’ll instantiate dynamically can be quitedifferent each time. What can

Java OOP

Question: What exactly is a Factory or Factory class? Answer: A Factory is a class that you use to create sets of related objects withoutexplicitly invoking their constructors. You usually

Single bit assignment

Question: Is there an easy way to assign each bit in a byte, and how do Iaccess those bits individually? Answer: Usually, if you come from a C programming background,

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

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 {

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

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

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,

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]

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

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

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

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

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 =

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),

delete vs. delete[]

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

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: