I want to remove the last character from a string. I’ve tried doing this: Getting the length of the string – 1 and replacing the last letter with nothing (deleting it), but every time I run the program, it deletes middle letters that are the same as the last letter. For example, the word is “…
Tag: java
SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”
My application is to be deployed on both tcServer and WebSphere 6.1. This application uses ehCache and so requires slf4j as a dependency. As a result I’ve added the slf4j-api.jar (1.6) jar to my war file bundle. The application works fine in tcServer except for the following error: However, when I deplo…
Gibberish at the end of a String byte array passed to native code
I am writing an applet to wrap a proprietary .dll that can be used in the browser. To achieve this, I am using JNA. The .dll connects to a check scanner peripheral, and can pull images from the devices memory. I have to make a Windows API call in Java, using JNA, to get the image: When the code saves
Does a hasDuplicate array method without using java.util exit? Is O(n) achievable with it?
I had an interview today which involved this very question and in order to widen my algorithmic knowledge. I am trying to see if there are any better suggestions. I was trying to find duplicates in an …
How to Convert Int to Unsigned Byte and Back
I need to convert a number into an unsigned byte. The number is always less than or equal to 255, and so it will fit in one byte. I also need to convert that byte back into that number. How would I do that in Java? I’ve tried several ways and none work. Here’s what I’m trying to do now:
PKCS#12 : DerInputStream.getLength() exception
I generate a certificate using the keytool command: Then if I try to load it using java security API, after getting the file as a byte[] : I get a DerInputStream.getLength(): lengthTag=127, too big exception. What is wrong? Answer I had this problem and I’ve searched the depths of google and still could…
Splitting strings through regular expressions by punctuation and whitespace etc in java
I have this text file that I read into a Java application and then count the words in it line by line. Right now I am splitting the lines into words by a But I know I am missing out on some words from the text file. For example, the word “can’t” should be divided into two words “can…
OrientDB having trouble with Unicode, Turkish, and enums
I am using a lib which has an enum type with consts like these; While I am debugging in Eclipse, I got an error: As I am using a Turkish system, there is a problem on working i>İ but as this is an enum const, even though I put every attributes as UTF-8, nothing could get that STRING is what
Nested functions in Java
Are there any extensions for the Java programming language that make it possible to create nested functions? There are many situations where I need to create methods that are only used once in the context of another method or for-loop. I’ve been unable to accomplish this in Java so far, even though it c…
Does anyone know how to decode and encode a string in Base64 using Base64?
I am using the following code, but it’s not working. Answer First: Choose an encoding. UTF-8 is generally a good choice; stick to an encoding which will definitely be valid on both sides. It would be rare to use something other than UTF-8 or UTF-16. Transmitting end: Encode the string to bytes (e.g. tex…