Adding to the classpath on OSX

If you want to make a certain set of JAR files (or .class files) available to every Java application on the machine, then your best bet is to add those files to /Library/Java/Extensions. Or, if you want to do it for every Java application, but only when your Mac OS X account runs them, then … Read more

Why is the range of bytes -128 to 127 in Java?

The answer is two’s complement. In short, Java (and most modern languages) do not represent signed integers using signed-magnitude representation. In other words, an 8-bit integer is not a sign bit followed by a 7-bit unsigned integer. Instead, negative integers are represented in a system called two’s complement, which allows easier arithmetic processing in hardware, … Read more

Difference between static modifier and static block [duplicate]

In this example, there’s one subtle difference – in your first example, foo isn’t determined to be a compile-time constant, so it can’t be used as a case in switch blocks (and wouldn’t be inlined into other code); in your second example it, is. So for example: switch (args[0]) { case foo: System.out.println(“Yes”); break; } … Read more

Regular Expressions and GWT

The same code using RegExp could be: // Compile and use regular expression RegExp regExp = RegExp.compile(patternStr); MatchResult matcher = regExp.exec(inputStr); boolean matchFound = matcher != null; // equivalent to regExp.test(inputStr); if (matchFound) { // Get all groups for this match for (int i = 0; i < matcher.getGroupCount(); i++) { String groupStr = matcher.getGroup(i); … Read more

How to ignore PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException?

I have used the below code to override the SSL checking in my project and it worked for me. package com.beingjavaguys.testftp; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.net.URLConnection; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import java.security.cert.X509Certificate; /** * Fix for Exception in thread “main” javax.net.ssl.SSLHandshakeException: * sun.security.validator.ValidatorException: PKIX … Read more

Java creating .jar file

In order to create a .jar file, you need to use jar instead of java: jar cf myJar.jar myClass.class Additionally, if you want to make it executable, you need to indicate an entry point (i.e., a class with public static void main(String[] args)) for your application. This is usually accomplished by creating a manifest file … Read more