Thursday, November 22, 2012

Print a carriage return in java on windows




I need to print :q in a new line. I’m using a StringBuffer which prints a new line in this format

StringBuffer sBuffer = new StringBuffer();
sBuffer.append(String.format("Hello"));
sBuffer.append(String.format("\n"));
sBuffer.append(String.format(":q"));


The program works fine in Windows XP. :q will be printed in a new line when the program is executed.
Hello
:q


But in Windows 7, :q is printed in the same line.

Hello:q

The issue here is:
Different operating systems use different line separators.
In Java, \r is always carriage return, and \n is line feed. On Unix, just \n is enough for a newline, whereas many programs on Windows require \r\n. So you will have to modify the program like this to work on Windows 7.

StringBuffer sBuffer = new StringBuffer();
sBuffer.append(String.format("Hello"));
sBuffer.append(String.format("\r\n"));
sBuffer.append(String.format(":q"));

Wednesday, November 21, 2012

JNLP - Unable to launch application






Whenever I try to load my JNLP file, it is throwing the following exception.

com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://a.b.c.d/MyProgram/MS.jnlp
            at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
            at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
            at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
            at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
            at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
            at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
            at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
            at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
            at com.sun.javaws.Launcher.launch(Unknown Source)
            at com.sun.javaws.Main.launchApp(Unknown Source)
            at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
            at com.sun.javaws.Main$1.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)


Solution:

1. Start Java Control Panel (from windows control panel -> java, OR from Java folder)
2. On "General" tab click "Network settings..."
3. Choose "Browser Settings" instead of "Use Proxy server"
4. Click OK and you are done.

Thursday, November 1, 2012

Java Code to Replace character '+'


I need to replace the '+' sign in my string with some other string.

Code:

public class ReplaceString
{
            public static void main(String[] args)
            {
                        String st = "+++ My Data contains Plus sign";                       
                        String sData  = st.replaceAll("+", "Hello,");
                        System.out.println(sData);
            }          
}


But while executing it always throws error,

Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 0
+
^



Since '+' is a reserved character in regex, you need to escape it.The solution for this is to include the '+' character within square brackets or as \\+.

So the code looks like this:


public class ReplaceString
{
            public static void main(String[] args)
            {
                        String st = "+ My Data contains Plus sign";                       
                        String sData  = st.replaceAll("[+]", "Hello,");
                        System.out.println(sData);
            }          
}


or

public class ReplaceString
{
            public static void main(String[] args)
            {
                        String st = "+ My Data contains Plus sign";                       
                        String sData  = st.replaceAll("\\+", "Hello,");
                        System.out.println(sData);
            }          
}
 



Tuesday, October 9, 2012

Airports Authority of India - Manager (IT) Paper



Airport Authority of India
Manager – Information Technology
Examination held on 07/10/2012




1.      Parameter passing during function call is done by using _______memory
a.       Stack
b.      Heap
2.      Dynamic memory is allocated to a program using ________ area
a.       Heap
b.      Stack
3.      During function call, return address is stored in ________ area
a.       Heap
b.      Stack
4.      Operating System allows unlimited processes. Its ready queue should be implemented through __________
a.       Stack
b.      Linked List
c.       Heap
5.      Selective-repeat error-recovery protocol of data link layer is useful for _______
a.       Ethernet LAN
b.      WLAN
6.      Architecture of Pentium Microprocessor
a.       CISC
b.      RISC
c.       bit slice
7.      Maximum speed of WLAN
a.       2 Mbps
b.      5 Mbps
c.       54 Mbps
8.      IEEE standard of Ethernet LAN
a.       802.2
b.      802.3
c.       802.11
9.      Thread has its private ________ area
a.       Data
b.      PCB
c.       Stack
d.      Code
10.  Minimum frame size of Ethernet LAN
a.       64 bits
b.      64 bytes
c.       1500 bits
d.      1500 bytes
11.  Unix OS is based on ________ architecture
a.       Hierarchical
b.      Kernel
12.  Protocol of WLAN
a.       CSMA/CD
b.      CSMA/CA
c.       Token Bus
d.      Token Ring
13.  De-Morgan’s law
14.  Universal GATE
a.       NAND
b.      X-OR
  1. In which layer of ISO/OSI, generate frames
a.       Network layer
b.      Data Link layer
c.       Transport Layer
  1. Which Gate produces the following output
0
0
0
0
1
1
1
0
1
1
1
0
     

     


a.       X-OR
b.      X-NOR
  1. Normalization ____________
    1. Reduces data redundancy
  2. Developer 2000 is ______
    1. Front end program of Oracle
    2. Backend program of Oracle
    3. Front end program of DB2
    4. Backend program of DB2

  1. Primary key in Oracle should always be
    1. Unique and not null
    2. Unique
    3. Not null
  2. Architecture of oracle database
    1. Relational
  3. An object is
    1. Instance of class
    2. Instance of method
    3. A class itself
  4. What causes Internal fragmentation of memory
    1. Paging
    2. Demand paging
    3. segmentation
  5. Non maskable interrupt
a.       RST 4.5
b.      Trap
c.       RST 5.5
  1. Which is the fastest memory
a.       Primary Memory
b.      Secondary memory
c.       cache memory
  1. Access Hard disk and primary memory
a.       DMA
  1. In unix operating system ,file access is by
a.       Sequential
b.      indexed
c.       random
  1.   Operating system  variable s implemented using
    1. Semaphore
  2. Communication between two process is done through
    1. Shared memory
  3. Which of the following instruction is executed in Kernel
    1. MOV A B
    2. ADD A B
    3. SUB A B
    4. OUT DX, EAX
  4. Output of Java compiler is
    1. Byte code
    2. Class
  5. Time complexity of binary search
  6. Time complexity of quick sort
  7. Error probability of CRC 16
    1. 1
    2. 1/(2^16)
  8. Using 32 address lines how much memory can be addressed?
    1. 4 GB
    2. 2 GB
    3. 20 Mb
  9. Java virtual machine is an
    1. Interpreter
    2. Compiler
  10. Routing is done in which OSI layer?
    1. Network

General Knowledge
37.  Goldman award is related to ____
a.       Protection of environment
38.  Chinaman is related to which game
a.      Cricket
b.      Bridge
c.       Tennis
39.  Distance between a degree of longitude on the equator
a.       39 miles
b.      69 miles
40.  The person who received Nobel prize twice for the same subject
a.       Marie curie
b.      Fredrick Sanger
  1. How many hours of daylight does the North Pole get on June 21st?
    1. 18 hours
    2. 12 hours
    3. 0 hours
  2. Match the following
    1. Straight from the heart            Kapil Dev
    2. My Autobiography                 Shane Warne
    3. Cutting Edge                          Javed Miandad
    4. My side                                 David Beckham
  3. Which five year plan involved the improvement of weaker section of society?
    1. 12th
    2. 13th
    3. 2nd
    4. 3rd
  4. Match the following
    1. Ellora                           Rashtrakuta
    2. XXX                           Alaudin Khilji
    3. YYY                           Pallavas
    4. Lord of Vishnu             ZZZ
  5. By what name is the river Ganga known in Bangladesh ?
    1. Rupanarayan
    2. Padma
    3. Bhagirathi
    4. Nubra

English Questions

Synonyms and antonyms

1.      Exorbitant
2.      Insinuate
3.      Musty
4.      Placate
5.      Devout
6.      Tepid
7.      Curtail