Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: converting into unicode using java

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default converting into unicode using java

    This is the code to convert string into unicode but I get an error as "illegal start of an expresssion"while running the code..
    import java.util.Scanner;
    import java.lang.String;
    import java.lang.Character;
    public class A
    {
    public static void main(String args[])
    {
     public static String GetUnicode(String str_code) // here i get the error
    {          
       String hexCode = Integer.toHexString(str_code.codePointAt(0)).toUpperCase();        
        String hexCodeWithAllLeadingZeros = "0000" + hexCode;
        String hexCodeWithLeadingZeros = hexCodeWithAllLeadingZeros.substring(hexCodeWithAllLeadingZeros.length() - 4);
        hexCodeWithLeadingZeros = "\\u" + hexCodeWithLeadingZeros;
        System.out.println("Unicode " + hexCodeWithLeadingZeros);
        return hexCodeWithLeadingZeros;
    }}    
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: converting into unicode using java

    I get an error
    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: converting into unicode using java

    The problem with your code is you define a method inside your main. You are not allowed to define a method inside another method's body.
    So rather then defining "GetUnicode" inside main.Move "GetUnicode" method outside main and make a call to "GetUnicode" in main.

Similar Threads

  1. java code related to unicode in cryptography
    By salinii in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 28th, 2014, 09:45 AM
  2. java swing textfiled sinhala unicode
    By stark9000 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: July 10th, 2013, 08:02 AM
  3. Need help converting Pseudocode to java
    By firebyrd in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 5th, 2011, 05:28 AM
  4. java and unicode ...
    By abesha in forum Java Theory & Questions
    Replies: 2
    Last Post: November 15th, 2010, 11:25 AM
  5. Use of Unicode 5.1 in MySQL DB with Java
    By Desert Fox in forum JDBC & Databases
    Replies: 2
    Last Post: November 12th, 2008, 08:29 AM

Tags for this Thread