Q:

Can Java be faster C++ in any situation?

Is it possible for a Java application to be faster than a program written in C++?  Also, what is release mode in compilation ? 

A:

Unlike some people here, I'm going to be reasonable and answer the question that I know the OP intended to ask, even though his statement of it could have been better.
Yes, a typical java implementation can be faster than a typical C++ implementation for real-world things.  Even though Java has a few handicaps from being a safe, VM language, it makes up for some of them, too.
For one thing, since Java has a very abstract memory management scheme that does not allow raw pointers or untyped memory blocks to be manipulated, it can use a moving garbage collector.  In C++, untyped memory regions, unions, etc. would break this.  Therefore, when a GC does not need to be run, allocations in Java can simply be a pointer bump.  There is no practical way to do this in C++, since a fully moving GC cannot be implemented in a language that supports the kind of low level manipulations that C++ does.
Furthermore, the VM of a typical implementation of Java is a double-edged sword relative to the statically compiled typical C++ implementation.  The VM has some inherent overhead, but also allows some extra optimizations.  For example, let's say you have some kind of virtual function like (Please excuse incorrect syntax, as I don't regularly use Java):
abstract class Foo {
    void stuff() {}
}

class Foo1 extends Foo {
    void stuff()  {
        System.out.println("Foo1");
    }
}

class Foo2 extends Foo {
    void stuff()  {
        System.out.println("Foo2");
    }
}

// Somewhere in program initialization:
Foo foo;
if(args[0] == "Foo1")
    foo = new Foo1();
 else foo = new Foo2;
 for(int i = 0; i < 1000000; i++)
     foo.stuff();

In C++, a virtual function call on foo.stuff() would likely have to be performed for all 1,000,000 iterations.  In Java, the VM might be able to replace this with a direct call at runtime, after realizing that there is no semantically legal way for foo to be rebound to an object of class Foo2.

A:

Languages don't have a speed. A good Java compiler may generate more efficient code than a bad C++ compiler, and vice versa. So which one is "fastest"? 
Execution speed depends on several factors:

The compiler. Different compilers generate different output code from the same input.
Your source code. Some operations are cheap in one language, but expensive in others. allocating memory with 'new' is far slower in C++ than in a managed language like C# or Java, for example)
The system it's running on. (CPU's vary in how fast they can execute different code. What if your Java compiler turns out to generate code that runs really well on a Core 2, but my C++ compiler generates code that runs well on a Phenom? Which is fastest then?

But the language is in principle irrelevant. Each language enforces certain guarantees which, might prevent certain optimizations. But a clever compiler may determine that these guarantees can be safely bypassed in this particular case, making the optimization anyway. (For example, a Java compiler will often try to eliminate the bounds-checking that is required by the language). So it depends on the code you're testing (Java code ported to C++ will probably run better in the Java version, and vice versa), and on how you compile it and where you run it.
So as Martin York says, it's a silly question. It's impossible to answer.
Of course Java can be faster than C++ in some situations. For example, if you write really good Java code and really bad C++ code. Or if you use a lousy C++ compiler. Or if any of a million other things just so happen to favor the Java version a bit.
Say after me: Languages don't have a speed.
Which is fastest? English or french? Both are just ways to associate meaning with sounds, or squiggles on paper.
The same applies to programming languages. A programming language is just a way to associate semantics with a sequence of characters in one or more files.

A:

I think there are plenty of questions you can browse through that are similar. Have a look here, for example: C++ Performance vs. Java/C#

