• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

what does # mean in Java source code?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is part of Java code from a JDK src file ByteBufferAs-X-Buffer.java:
---------------------------
/*
* @(#)ByteBufferAs-X-Buffer.java1.17 04/05/03
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/

#warn This file is preprocessed before being compiled

package java.nio;


class ByteBufferAs$Type$Buffer$RW$$BO$// package-private
extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
{

#if[rw]

protected final ByteBuffer bb;
protected final int offset;

#end[rw]
...
...
---------------------------

I never seen such use of # in Java code before, e.g. #warn, #if, #end. I'm wondering where can I find more info about # usage in Java code?

Thanks.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not part of the Java language. The "#" lines are control statements for a preprocessor -- like, for example, the C preprocessor, but a different implementation.
 
Nancy Zhang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to recognize/distinguish such type of file from normal Java source code when my code trying to process ".java" files?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not going to find files like this, in general. There's no standard Java preprocessor, and furthermore, most of the time that someone uses one, they will name the source files something other than *.java -- it only makes sense.

But in this one case, you've found some code in the JDK source distribution which has to be built using a special preprocessor. If you're writing some kind of a tool to process the JDK source code, well, then maybe this is something you need to worry about -- but otherwise, I'd just forget about it.
 
Nancy Zhang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm, unforturnately JDK source is part of my test suite. And my program is expected to parse Java source codes first before doing other processing. For those "precompile purpose code", my parser can't process them correctly following standard Java grammar. Since those files are not real java file, I think I'd better find a way to exclude them. It's good there are only 7 such files in JDK source. And they have common part in file name, so...

Thanks very much for your help. Now I know what those files are and there's nothing wrong with my parser.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic