Difference between isEmpty() and isBlank() Method in java 11
Java 11 has added A new instance method
What's the basic difference between the existing
isEmpty and newly added
The java string
isEmpty()method checks if this string is empty. It returns true, if the length of the string is 0 otherwise false
String str =""; String str2 =" "; System.out.println(str.isEmpty()); // Prints - True System.out.println(str2.isEmpty()); //Prints - False
java 11 - isBlank()
The new instance method
returns true if the string is empty or contains only white space, where whitespace is defined as any codepoint that returns true when passed to Character#isWhitespace(int).
boolean blank = string.isBlank();
Before Java 11
boolean blank = string.trim().isEmpty();
After Java 11
boolean blank = string.isBlank();
See also questions close to this topic
Can searchResponse.getHits().getHits(); throw nullpointer exception
We are getting a nullpointerexception at searchResponse.getHits().getHits(); I'm totally new to elastic search and don't know how it works but need to analyse this issue.
Let me know if it throws nullpointerexception in any case ? If it throws how to handle this ?
Is it possible to disable SSL certificate checking in the amazon kinesis consumer library v2?
When developing a Kinesis Consumer using Version 2 of the Kinesis Consumer Library and overriding the Dynamo DB endpoint to a localstack endpoint the library fails to create the leasing table due to SSL handshake errors.
I can confirm that creating the table succeeds when using AWS' Dynamo DB, but as soon as I override the endpoint url to a localstack url the Dynamo DB client fails to create the lease table after multiple retries. The stack trace isn't that useful but Wireshark shows all of the SSL handshake errors so I can only assume the Amazon SDK is not accepting the localstack certificate. I cannot find any mention of how to disable certificate verification using the
Region region = Region.of("us-east-1"); DefaultCredentialsProvider credentialsProvider = DefaultCredentialsProvider.create(); DynamoDbAsyncClient dynamoClient = DynamoDbAsyncClient.builder() .region(region) .endpointOverride(URI.create("https://localhost:4569")) .credentialsProvider(credentialsProvider) .build();
/edit This is based off the example from Amazon found here: https://docs.aws.amazon.com/streams/latest/dev/kcl2-standard-consumer-java-example.html
Problem creating an OracleDataSource correctly from tomcat context.xml
In the project im working at the following problem occurs:
We use Database connections defined in our tomcat context.xml. For now this has worked without problems.
<Resource auth="Container" driverClassName="oracle.jdbc.driver.OracleDriver" logAbandoned="true" maxIdle="10" maxTotal="100" maxWaitMillis="5000" name="NAME" password="PASSWORD" removeAbandonedOnMaintenance="true" removeAbandonedTimeout="60" type="javax.sql.DataSource" url="URL" username="USERNAME" />
This type of resource definition is used in the webapp for every database connection, retreiving the datasource like this:
InitialContext ctx = new InitialContext(); DataSource dsAux = (DataSource) ctx.lookup(dbCon);
The problem begins here. Oracle queues are being used with jms (Java Message System) for a lot of processes. For this, as it is coded right now, we need an OracleDataSource that can be created having only the db url, password and username.
My question is, is it possible in any way or form to get all the data needed from the context for this type of datasource correctly? I have tried changing the datasource type without any luck, unwrapping the already created datasource to try and create an OracleDataSource, in the end, the only possible solution I have come up with is to change how database connections are saved.
Find trailing slash and delete all after it then delete slash
I have a URL that looks as follows:
In my php code, I trim everything after card the code to get the name (for setting SEO tags):
$cname = $_SERVER['REQUEST_URI']; $cname = substr($cname, strpos($cname, "card/") +6); $cname = substr($cname, 0, -1);
This is working as intended. The issue is, when I link to this subdomain from my main domain, Google Analytics adds on a tag at the end:
So now my SEO tags are affected when this happens. I need to be careful with removing slashes as there can often be a name that contains a slash:
I need to locate the last slash and remove everything after it, then I can use something like rtrim to remove the last slash.
What is the difference between %[^\n] and %[^\n]s?
Why some writers use
%[^\n]sspecifier instead of
%[^\n]? Which one is correct?
Convert string to an integer
I'm having trouble converting a String to Integer in VB.net
I tried the following, but it wont quite work:
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged My.Settings.ydelay = Convert.ToInt32(TextBox3.Text) End Sub
My.Settings.ydelay = Textbox3.Text My.Settings.ydelay = Convert.ToInt32(Textbox3.Text)
My.Settings.ydelay = Convert.ToInt32(Textbox.3Text) My.Settings.ydelay = Textbox3.Text
My.Settings.ydelay = Textbox3.Text Convert.ToInt32(Textbox3.Text, My.Settings.ydelay)
I am pretty much going crazy over this maybe im just missing a little detail but I cant figure it out. Help would really be appreciated if you need more details let me know.
Soap Webservice Response Differing on Tomcat 9 and Java 11
I am migrating my application to Java 11 and Tomcat 9 from Java 8 and Tomcat 7. With some version updates, minor implementation changes and adding few maven dependencies, I have been able to successfully compile and run my application. However, I have few integration tests written to test the Soap based webservices in my application which are failing. This is happening due to mismatch in the expected Soap response and the actual response.
Here are the two responses: Actual is :
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <S:Body xmlns:ns2="http://www.acd.org/cact/namespaces/StandardBusinessDocumentHeader" xmlns:ns3="urn:global:cpci-query:xsd:1" xmlns:ns4="urn:global:cpci-masterdata:xsd:1" xmlns:ns5="urn:global:cpci:xsd:1"> <ns3:GetResult> <string>SimpleDataQuery</string> <string>SimpleQuery</string> </ns3:GetResult> </S:Body> </S:Envelope>
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns5:GetResult xmlns:ns5="urn:global:cpci-query:xsd:1"> <string>SimpleQuery</string> <string>SimpleDataQuery</string> </ns5:GetResult> </soapenv:Body> </soapenv:Envelope>
The pom has following updated entries :
<dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-ri</artifactId> <version>2.3.2</version> <type>pom</type> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>javax.activation-api</artifactId> <version>1.2.0</version> </dependency>
Can there be any impact of Java 11 on WS responses' elements order being disturbed ? If yes, then is this due to some outdated dependencies or we need to modify some implementations?
Does Spring Version 4.3.20 work with Java 11?
I am confused when it comes to the supported java-versions of spring 4.3.20. Updating a Spring 4.3.20 project to Java 11 worked without any hiccups what so ever. All my tests work fine, the webapp starts up and all the features of Spring that require bytecode-magic like
@Cacheablework. How is this even possible? From what I understand I should have to update to Spring 5+. I checked the language level in my maven settings and bytecode version of the generated
.class-files and they indeed use
major version: 55.
What am I missing?
I build with Java 11 and launch my local tomcat with Java 11. I double checked all my settings and used
visualvmto verify that tomcat indeed runs with Java 11.
Heres the output of
Java -version conflicting with Java_Home Cannot get system to recognize Java-11
Trying to get Windows-10 system to recognize Java-11. I have configured my PATH, my JAVA_HOME and have installed the unpacked JDK in the right place but still the computer refuses to show Java-11 as my java -version reads as:
java -version java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09)<br> Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)*<br><br>
C:\Users\>echo %java_home% C:\Program Files\Java\jdk-11.0.1
My steps so far are:
- Unpacked JDK in
PATH = C:\Program Files\Java\jdk-11\binin Edit System Variable. Per another note I put
JAVA_HOMEat the top of the PATH
C:\Program Files\Java\jdk-11.0.1in Edit System Variable.
Java Control Panel shows both 1.8 and 11 as installed but only 11 is enabled.
C:\Program Files\Java\jdk-11.0.1\bin\javaw.exe - **enabled** C:\Program Files\Java\jre1.8.0_201\bin\javaw.exe - **NOT enabled**
I am looking to see
java -versionbe pointed to Java-11
- Unpacked JDK in