File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Binary literal problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Binary literal problem" Watch "Binary literal problem" New topic
Author

Binary literal problem

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583



F:\Binary Literal>javac BinaryLiterals.java
BinaryLiterals.java:3: error: ')' expected
System.out.println(0b10101010101010101010101010101011d);
^
BinaryLiterals.java:3: error: illegal start of expression
System.out.println(0b10101010101010101010101010101011d);
^
2 errors


Tell the difficulties that i am difficult.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Since binary literals are a new feature in Java 7, can you confirm that you tried to compile that code with a Java 7 compiler?
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Paul Clapham wrote:Since binary literals are a new feature in Java 7, can you confirm that you tried to compile that code with a Java 7 compiler?


Yes,I on 7.With letter L code is working but why not with d letter.And if i delete d letter then it will compile fine.But as i know ,d is for integer, we write or not it shouldn't effect compilation then why it is giving compile error if i use d letter. thanks
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4374
    
    8

saloni jhanwar wrote:But as i know ,d is for integer

What makes you think that? d indicates a double, i.e. not an integer literal, so you can't mix it with an integer-specific literal form. Are you getting confused with format strings?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Oracle's page describing binary literals starts out by saying this:

Oracle wrote:In Java SE 7, the integral types (byte, short, int, and long) can also be expressed using the binary number system.
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Thanks Matthew Brown & Paul Clapham.I got confused because of my mindset d for integer
BalaMurali dhar
Ranch Hand

Joined: Apr 14, 2012
Posts: 60
This is the code
public class BinaryLiterals {
public static void main(String args[]){
System.out.println("0b10101010101010101010101010101011d");
System.out.println("0b10101010101010101010101010101011L");
}
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Binary literal problem