• Post Reply Bookmark Topic Watch Topic
  • New Topic

who to know the platform  RSS feed

 
Ankur khetan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In C/c++ through conditional compilation the code come to know that which code we have to compile on which platform i.e. win or mac...

How we come to know this in java?
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ankhur,

Here's a very basic tip in java:


Most java compilers (maybe all) will discard the code in backets at compile-time. So the code won't be present in bytecode.

Hope that helps,
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

In general, you don't compile Java code for one particular platform; that's the whole point. You might be compiling on a Mac, but that same code might be used on Windows or Linux. Java has binary portability.

Now, sometimes, occasionally, you need to do something different at runtime on the different platforms. In this case, you can detect the platform in your code at runtime based on the value returned from System.getProperty("os.name"), and decide what to do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!