Exception in thread “main” java.net.ConnectException: Connection refused: connect Socket Programming Java

There are 2 issues in your program: You use the port 80 which is part of the well-known ports or system ports (0 to 1023), so you need to launch your server with the admin rights or change it for 8080 for example. You forgot to call bw.newLine() after each bw.write(sendMessage) such that it waits for ever since on the other side you call br.readLine() which means that it … Read more

Difference between string object and string literal

When you use a string literal the string can be interned, but when you use new String(“…”) you get a new string object. In this example both string literals refer the same object: Here, 2 different objects are created and they have different references: In general, you should use the string literal notation when possible. It is easier … Read more

Iterator for a linkedlist

1) SortedLinkedList extends BasicLinkedList but both have this is wrong. If you want to inherit those field in the sub class, you should mark the variables as protected in the super class and remove them from the subclass. 2) Same goes for private class Node. You are declaring the Node class in both the SortedLinkedList and BasicLinkedList. What you should do is declare … Read more

Problems Generating A Math.random Number, Either 0 or 1

You could use boolean values of 0 or 1 based on value of Math.random() as a double between 0.0 and 1.0 and make the random generator much simpler. And you can get rid completely of the coinToss() method. Remove the coin toss method and replace the first conditional with the code above. Math.random(); by itself will return a value between … Read more

Get an OutputStream into a String

I would use a ByteArrayOutputStream. And on finish you can call: or better: For the String constructor, the codepage can be a String or an instance of java.nio.charset.Charset. A possible value is java.nio.charset.StandardCharsets.UTF_8. The method toString() accepts only a String as a codepage parameter (stand Java 8).

How can I convert a char to CharSequence?

I give you an example: Syntax of String contains method Parameters String “e” − This is the sequence to search Return Value This method returns true only if this string contains “e” else false. Exception NullPointerException − if the value of the parameter is null. Example

Size has private access in ArrayList

You are attempting to access a private member of ArrayList, part of its internal working that are not supposed to be used externally If you want to get the size of the arraylist you want the method: Why is it like this This gives the ArrayList class the option to store size in whatever way it wants. Does … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)