I guess I edited the post before you replied. Please excuse me, English is not my mother tongue & its a little difficult to frame a sentence that would mean what I think. I just want to know about .Net
Prabakar 77 Posting Whiz
sciwizeh 62 Posting Pro in Training
No, it all relies on machine instructions, as does C++ itself.
Sure you can: http://www.google.com/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=java+to+exe
But you give up platform portability and may lose out on JVM/JIT improvements down the road. You can do it, it's just not a good idea for most cases.
actually, i heard, and read that Windows is also written in C, i know that that doesn't mean that c doesn't rely on machine code, but even when you go to the OS it is still C.
as for .exe's with java you don't need them, jar files serve the same purpose, double click on one and it runs. and DLL's again you don't need them, jar files serve that purpose too, make sure the compiler knows about them and you can use any class in any package that is in it,
import java.util.*; public class Testing_Something_5 extends Object{ Integer i1 = 999, i2 = 888, i3 = 777; int l = 9999999, m = 1; public Testing_Something_5(){ System.out.println(this.toString() + " Constructed!"); } public static void main(String[] args) throws Throwable{ Runtime rt = Runtime.getRuntime(); // memory before garbage collector is called-- System.out.println("Free Memory: " + rt.freeMemory() + " Total Memory: " + rt.totalMemory()); long initialFreeMemory = rt.freeMemory(); Testing_Something_5 ts5 = new Testing_Something_5(); // object with reference new Testing_Something_5(); // anonymous object rt.runFinalizersOnExit(true); // unsafe method - deprecated warning { Testing_Something_5 ts5_2 = new Testing_Something_5(); // object defined within block scope through pointer } rt.gc(); // runs the garbage collecter, finalizing any objects that no longer have a reference pointing to them // finalization of anonymouse object-- // notice no finalization of block scope - proof that Java reference-variables are indeed pointers // displaying the memory bump after garbage collector called-- System.out.println(rt.freeMemory() - initialFreeMemory); // Displaying the new amount of free memory System.out.println("Free Memory: "+rt.freeMemory() + " Total Memory: " + rt.totalMemory()); // pausing the program to differentiate between garbage collected objects and objects still being referenced Thread.sleep(3000); // all objects should be finalized before exit due to deprecated method } @Override protected void finalize() throws Throwable{ try{ System.out.println(this.toString() + " No longer has references pointing to it and fell out of scope!"); }catch(Throwable t){ System.out.println(t); }finally{ super.finalize(); // calls the finalize method of the base Object of this class System.out.println(this.toString() + " was finalized!"); } } }
this line long initialFreeMemory = rt.freeMemory();
should be before this line: System.out.println("Free Memory: "+rt.freeMemory() + " Total Memory: "+rt.totalMemory());
so that you have a more accurate memory, a long is 8 bytes, which could effect the results, not much, but if you want to be accurate
sarehu 84 Posting Whiz in Training
A big advantage of C++ that has undermentioned is that it has a much more flexible type system. Object oriented programming as seen in C++, Java, and C# is extremely restrictive in what you can do -- inheritance is fine for defining plain old polymorphic datatypes but retardedly broken for the task of generic programming. C++'s templates aren't as broken, at least when the types are known at compile time.
sciwizeh 62 Posting Pro in Training
java generics work pretty well, is there something wrong with them that i haven't encountered?
Alex Edwards 321 Posting Shark
java generics work pretty well, is there something wrong with them that i haven't encountered?
There's a huge difference between Java's Erasure type vs C++ Templates.
Erasure removes instances of the Generic data (Edit) as they are used whereas Templates literally replaces the template with the specified type during compile-time which builds a type of meta-program (or program within a program).
Here's a quote to explain, more in detail, about Type Erasure
When a generic type is instantiated, the compiler translates those types by a technique called type erasure — a process where the compiler removes all information related to type parameters and type arguments within a class or method. Type erasure enables Java applications that use generics to maintain binary compatibility with Java libraries and applications that were created before generics.
For instance, Box<String>
is translated to type Box, which is called the raw type — a raw type is a generic class or interface name without any type arguments. This means that you can't find out what type of Object a generic class is using at runtime. The following operations are not possible:
public class MyClass<E> {
public static void myMethod(Object item) {
if (item instanceof E) { //Compiler error
...
}
E item2 = new E(); //Compiler error
E[] iArray = new E[10]; //Compiler error
E obj = (E)new Object(); //Unchecked cast warning
}
}
The operations shown in bold are meaningless at runtime because the compiler removes all information about the actual type argument (represented by the type parameter E) at compile time. Type erasure exists so that new code may continue to interface with legacy code. Using a raw type for any other reason is considered bad programming practice and should be avoided whenever possible.
Edited by happygeek because: fixed formatting
CoolGamer48 65 Posting Pro in Training
as for .exe's with java you don't need them, jar files serve the same purpose, double click on one and it runs. and DLL's again you don't need them, jar files serve that purpose too, make sure the compiler knows about them and you can use any class in any package that is in it,
a .jar files only runs if the computer it's running on has the JVM (which, granted, most do), but an .exe file can run without the JVM, all you need is the OS itself (assuming your running windows). DLLs can be used by other languages as well (I believe), so being able to create DLLs would still be a benefit.
sciwizeh 62 Posting Pro in Training
Alex, that is something i truly didn't know.
an .exe will run on a computer that is doesn't have a VM, and are not run on Linux or Mac, using jar files ensures platform independence.
i'm primarily a java developer, so i am bias, though i am learning c++ too.
Alex Edwards 321 Posting Shark
Alex, that is something i truly didn't know.
an .exe will run on a computer that is doesn't have a VM, and are not run on Linux or Mac, using jar files ensures platform independence.
i'm primarily a java developer, so i am bias, though i am learning c++ too.
http://en.wikipedia.org/wiki/Template_metaprogramming
Here is an example of Meta programming. Just play around with one of the N values in the recursive Fibonacci method and you'll understand what I mean by "templates are literally replaced by the specified type"
#include <cstdlib>
#include <iostream>
#include <vector>
#define VALUE_ 13
using namespace std;
/**
Fibonacci series using template recursion -- successful
*/
class Fibonacci{
private:
vector<bool> analyzed;
bool start;
unsigned __int64 current, firstN;
public:
Fibonacci(): analyzed(0), current(0), start(false) {};
template< unsigned __int64 N >
inline unsigned __int64 series(){
if(!start){
start = true;
vector<bool> tempVector(N, false);
analyzed = tempVector;
(firstN = N);
}
if(analyzed[N] == false){
analyzed[N] = true;
if((this->series<N>() <= firstN)){
cout << (this->series<N>()) << " " << flush;
}
}
if(N%2 == 0)
return(this->series<N - 2>() + ((this->series<N - 1>())));
else return (this->series<N - 1>() + ((this->series<N - 2>())));
}
static void reset(Fibonacci &fib){
fib.start = false;
}
};
template<>
inline unsigned __int64 Fibonacci::series<1>(){
if(analyzed[1] == false){
analyzed[1] = true;
cout << 1 << " " << flush;
}
return 1;
};
template<>
inline unsigned __int64 Fibonacci::series<0>(){
if(analyzed[0] == false){
analyzed[0] = true;
cout << 0 << " " << flush;
}
return 0;
};
#ifdef NUM
#undef NUM
#define NUM VALUE_
#else
#define NUM VALUE_
#endif
int main(int argc, char *argv[]){
Fibonacci fib;
fib.series<NUM>(); //prints out the entire series up to N
Fibonacci::reset(fib);
cout << endl;
fib.series<NUM - 6>();
cin.get();
#undef NUM
#undef VALUE_
return 0;
}
sciwizeh 62 Posting Pro in Training
something is wrong with my browser i cannot see Alex's code... i can see it in the reply, but it and the rest of the page are cut off in the actual thread, o well,
looking at it now, i am way out of practice when it comes to c++, or i'm too used to using allegro and no templates, wither way, i don't use templates much, or generics for that matter.
well as said many times both C++ and Java have their Strength and weaknesses.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.