write a programme to show in which programming language i have written this programme

Dani AI

Generated

The original request is ambiguous: it can mean (A) have a program report which language itself was written in, or (B) write a tool that guesses the language of some other program. suspected a joke, noted possible confusion with an OS-detection task, and suggested the OP might be trying to detect the language of another app. Both interpretations are valid but require different approaches.

For a reliable self-reporting answer the usual, practical solution is to record the language at build time (a constant, build script variable, assembly attribute, etc.). There is no universal runtime API that says “this binary came from C++/Pascal/etc.” — outside of managed runtimes or embedded metadata you must rely on heuristics or explicit metadata. (stackoverflow.com)

To guess another file’s language, use a tiered heuristic rather than a single magic test:

  • Scripts: check the shebang line (#!) or filename extension to identify the interpreter. (en.wikipedia.org)
  • Java: JARs are ZIP archives with META-INF/MANIFEST.MF and other Java metadata — a quick file/zip inspection reliably flags Java archives. (docs.oracle.com)
  • .NET: PE images that contain a CLR/COM descriptor (the IMAGE_COR20_HEADER) are managed assemblies and therefore produced by some .NET language. (learn.microsoft.com)
  • Python bytecode: .pyc files start with a version-specific magic number and header (PEP 552 describes the layout). (peps.python.org)

A minimal practical checklist (shell-style) is often enough: check shebang, then extension, then signatures inside the file (zip manifest, PE CLR header, pyc magic). If those fail, fall back to file, strings, symbol demangling, import tables, or dedicated detectors (PEiD/Enry/Linguist); note that packers, static linking, and obfuscation can defeat heuristics.

Example quick heuristic (illustrative):

#!/bin/sh
f="$1"
head -n1 "$f" | grep -q '^#!' && head -n1 "$f" && exit
case "$f" in
  *.jar) echo "Java (JAR)"; exit;;
  *.pyc) echo "Python bytecode"; exit;;
esac
file "$f"

As pointed out, the next sensible step for anyone working this as an exercise is to show the code already tried — the detection strategy depends on whether source, bytecode, or a native/executable file is available.

Recommended Answers

All 3 Replies

Is this just a silly joke? If not, then write it yourself.

commented: Awsome reaspose (Liz) +1

I think this is an assignment for school and it's possible his English isn't the greatest. Or at least his explanation. He also posted that he needed to try to write a program that would show what operating system the program is running on at that time. At least that's my thought. I'm still not clear on what he needs/wants.

I can't imagine he's just asking us to do his assignment for him . . .

his other post:

http://www.daniweb.com/forums/thread145076.html

Arupa,

Show us what code you have so far and maybe we can help you figure out your next step or get past where you're stuck.

I think the OP is trying to write an app to detect what language any other app was written in.

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.