Java

98K

Solutions

32K

Contributors

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi I am new to java and need help with Arraylist example. I have a list something like :
ArrayList<String> newlyAddedTypes=new ArrayList<String>();
        newlyAddedTypes.add("test1");
        newlyAddedTypes.add("ring");
        newlyAddedTypes.add("pass");
        if(newlyAddedTypes.contains("test")){
          	 System.out.println("conatins test"); 
        }
        else{
        	System.out.println("does not conatins test"); 
        }

Open in new window


Using contains checks exact value in arraylist I want to know how can I check substring so if I check test it should match test1 as well?
I am using Java 7.
0
Free Tool: SSL Checker
LVL 9
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Below line gives error as below as        device.getInternetConnection() return enum not String.            
callableStatement.setString("InternetConnection", device.getInternetConnection());


Multiple markers at this line
      - The method getInternetConnection() is undefined for the type Device
      - The method setString(String, String) in the type CallableStatement is not applicable for the arguments (String,
       Device.getInternetConnection)


Here  device.getInternetConnection()); returns the enum  InternetConnection

      public enum InternetConnection{
            
            WIFI("08"),
            CELLULAR("06");
            
            InternetConnection(String ip){
                  this.ip = ip;
            }
            
            private final String ip;
            
            public static InternetConnection getFromIP(String ip) {
                  for(InternetConnection pc : InternetConnection.values()) {
                  if(pc.getIP().equals(ip))...
                       ......
                  }
                  throw new IllegalArgumentException("This iP: " + iP + " does not exist");
            }
            
            public String getIP() {
                  return ip;
            }
      }

How to change my callable statement setter to accommodate enum instead of string?
please advise
0
Hi,

while creating client from wsdl using web servicesw getting below error




public class CustomerOrdersWS {

      public static void main(String[] args) {
            // TODO Auto-generated method stub
            CustomerOrdersService service=new CustomerOrdersService(new URL{"http://localhost:8080/wsdlfirstws/services/customerOrders?wsdl"});
            

      }

}




Multiple markers at this line
      - Type mismatch: cannot convert from String[] to
       CustomerOrdersService
      - Syntax error on token(s), misplaced construct(s)
      - Syntax error on token ")", delete this token

i wonder what it mean by above error and how to resolve it please advise
0
http://codingbat.com/prob/p126332

public Map<String, String> pairs(String[] strings) {
  Map map=new HashMap();
  for(String str:strings){
    int len=str.length();
    map.put(str.substring(0,1), str.substring(len-1,len));
  }
  return map;
}

Open in new window

xpected      Run            
pairs(["code", "bug"]) → {"b": "g", "c": "e"}      {"b": "g", "c": "e"}      OK      
pairs(["man", "moon", "main"]) → {"m": "n"}      {"m": "n"}      OK      
pairs(["man", "moon", "good", "night"]) → {"g": "d", "m": "n", "n": "t"}      {"g": "d", "m": "n", "n": "t"}      OK      
pairs([]) → {}      {}      OK      
pairs(["a", "b"]) → {"a": "a", "b": "b"}      {"a": "a", "b": "b"}      OK      
pairs(["are", "codes", "and", "cods"]) → {"a": "d", "c": "s"}      {"a": "d", "c": "s"}      OK      
pairs(["apple", "banana", "tea", "coffee"]) → {"a": "e", "b": "a", "c": "e", "t": "a"}      {"a": "e", "b": "a", "c": "e", "t": "a"}      OK      
other tests
OK      

I wrote as above and passing all steps. Any improvements to my code. please advise
0
http://codingbat.com/prob/p152303
For above challenge i wrote my code like below and passing all tests
public Map<String, Integer> word0(String[] strings) {
 
Map<String, Integer> map=new HashMap<String, Integer>();

for(String string : strings){
  map.put(string,0);
    map.put(string,0);
}
return map;
}

Open in new window

Expected      Run            
word0(["a", "b", "a", "b"]) → {"a": 0, "b": 0}      {"a": 0, "b": 0}      OK      
word0(["a", "b", "a", "c", "b"]) → {"a": 0, "b": 0, "c": 0}      {"a": 0, "b": 0, "c": 0}      OK      
word0(["c", "b", "a"]) → {"a": 0, "b": 0, "c": 0}      {"a": 0, "b": 0, "c": 0}      OK      
word0(["c", "c", "c", "c"]) → {"c": 0}      {"c": 0}      OK      
word0([]) → {}      {}      OK      
other tests
OK      
any improvements to my code. please advise
0
Are there any instructors like
simon allardice
from lynda.com, plursight.com
who explain computer science concepts without using a scripting language.

Just verbally.

Please add (or subtract) zones
0
Hi,
I  get data in xml format from client. The xml displays as a single line in notepad++. I have to use Pretty print feature of xmltools plug-in which inserts line breaks, so I can validate and visually edit. If I open in web browser, the line breaks are automatically inserted.
I would like to know what is industry standard for xml docs. Should they have explicit line breaks. If there is such, I would like to point that out to my client. If there isn't then I wonder how you can edit them? (without using notepad++ xmltools plug-in.
0
Hi,

We have a problem with passing a variable from JS to Java class. Here is our code:

<script type="text/javascript">
function displayModal(buttonClicked, waitMessage) {

    $.ajax({
            //url:'xxrsv.oracle.apps.ibe.tcav2.EndCustomer',
            data:{value123: document.querySelector('#csu').value},
            type:'post',
            cache:false,
            success:function(){
                console.log('success');
                otherTransactionSubmit (buttonClicked); // bug 9860747, scnagara
            },
            error:function(){
                console.log('error');
            }
        }
    );
 }
</script>

<%@ page import="xxrsv.oracle.apps.ibe.tcav2.EndCustomer" %>

Open in new window


public class EndCustomer extends HttpServlet{

    public void doPost(HttpServletRequest request, HttpServletResponse response)   throws ServletException, IOException {
        String id = request.getParameter("value123");
        EndCustomer.setEndCustomer(id);
    }

Open in new window


Please advise.
0
Windows 2008 R2
Tomcat 8.0.33

Trying to create SSL and install from a CA:
Step 1.
"%JAVA_HOME%\bin\keytool" -genkey -alias ecwinttomcat -keyalg RSA -keystore c:\ecwint.keystore
NO Password, hit enter.  
Step 2.
 
"%JAVA_HOME%\bin\keytool" -certreg -keyalg RSA -alias ecwinttomcat -file c:\ecwint.csr -keystore c:\ecwint.keystore

Get Error about -certreg illegal operation.
Cannot convert to a csr.
0
Hi!

I need to write a program that calls each of the methods of the Math class from the list below and provides output showing the method called, values sent to the method, and the returned results. Each listed method will tell you which values to use.  For example:
Listed method:
double pow(double a, double b): use 2.0 and 3.0

My program should display:
Math.pow(2.0, 3.0) = 8.0

Here is the list of Math classes and a sample of the Output:

double pow(double a, double b): Use 3.0 and 2.0
double sqrt(double x): Use 25.0
int max(int a, int b): Use 6 and 2
double max(double a, double b): Use -50.0 and 7.0
static double random()

Math.pow(3.0, 2.0) = 9.0
Math.sqrt(25.0) = 5.0
Math.max(6, 2) = 6
Math.max(-50.0, 7.0) = 7.0
Math.random() = 0.7131281909476174

Then I need to add a method to my program called randomStudy that has no parameters and returns no value and in this method:
a. Declare three int variables: total, min, and max. Set total to 0, min to 11, and max to -1.
b. Create a loop that will run 1,000 times and in the body of the loop, generate a random int value between 1 and 10, inclusive, and add this number to your total. If this number is less than min, update min with the new number and if it is greater than max, update max with the new number.
c. After the loop, display the following:
Min value: x
Max value: y
Average: z
Replace x and y with the  min and max values and Calculate z by dividing total by 1000d.

And finally, call the …
0
Industry Leaders: We Want Your Opinion!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Ok, I need to write a program in a class named "whatever" and ignore the main method for a moment.

In this class, I need to create a static method with one parameter of type int[ ] and Inside the method
a. Keep all output on one line I guess using System.out.print( )
b. Display an opening square bracket character.
c. Loop through the array that was passed into the method, display the values in the array, add a comma
and a space after every value except the last one.
d. then display a closing square bracket character...I guess using System.out.println().

Then, in my main method I've got to create an array and pass the reference to this array to the "printArray" method.
    int[ ] oneD = {5, 6, 7, 8};
Then in my main method, I need to add a blank println() statement after the method call just made.
and in the class, create an overloaded static method  with one parameter of type int[ ] [] named "arr" and inside:
a. Use println() to display an opening square bracket character.
b. Loop through the two-­dimensional array that was passed into the method.
     i. First, use System.out.print() to display two space characters.
     ii. Every element of this two­-dimensional array that you are looping through is a one­-dimensional
         array of int. Call the other printArray method and pass to it each one­-dimensional array in the
         two­-dimensional array.
c. Using println(), display a closing square bracket character.

Then in the main method, I need …
0
I am trying to access a website through proxy server.I am using httpclient.

This is the code which is working fine:

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;

public class Working {
private static  String PROXY_HOST = "proxy.test.org";
private static  int PROXY_PORT = 80;

    public static void main(String[] args) {
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod("https://www.example.org");
    HostConfiguration config = client.getHostConfiguration();
    config.setProxy(PROXY_HOST, PROXY_PORT);

    try {
          client.executeMethod(method);
            if (method.getStatusCode() == HttpStatus.SC_OK) {
           String response = method.getResponseBodyAsString();
           System.out.println("Response = " + response);
                        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
  …
0
Hi experts, is there way (util, script, open source/ licensed product) to receive Jason and generate HTML pls?
0
Hi,


what is difference between below 3 lines




 map.put("ab", map.get("a").concat(map.get("b")));



map.put("ab", map.get("a")+ map.get("b"));

map.put("ab", "null" + map.get("b"));


I passed all tests
http://codingbat.com/prob/p107259
Looking for ways to improve my code and also avoid Null pointer exceptions


Expected	Run		
mapAB({"a": "Hi", "b": "There"}) → {"a": "Hi", "ab": "HiThere", "b": "There"}	{"a": "Hi", "ab": "HiThere", "b": "There"}	OK	
mapAB({"a": "Hi"}) → {"a": "Hi"}	{"a": "Hi"}	OK	
mapAB({"b": "There"}) → {"b": "There"}	{"b": "There"}	OK	
mapAB({"c": "meh"}) → {"c": "meh"}	{"c": "meh"}	OK	
mapAB({"a": "aaa", "ab": "nope", "b": "bbb", "c": "ccc"}) → {"a": "aaa", "ab": "aaabbb", "b": "bbb", "c": "ccc"}	{"a": "aaa", "ab": "aaabbb", "b": "bbb", "c": "ccc"}	OK	
mapAB({"ab": "nope", "b": "bbb", "c": "ccc"}) → {"ab": "nope", "b": "bbb", "c": "ccc"}	{"ab": "nope", "b": "bbb", "c": "ccc"}	OK

Open in new window


please advise
0
The below I am mentioned my coding while am trying to get Hard Disk Serial Number. But I am getting error command on server side
 
My Code is :
 
$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');
 
echo  $serial;
localhost Result : SerialNumber 202020202020202020202020365a4445334*****
 
BUT Server Result :
 
sh: wmic: command not found
kindly revert me as Correct Solution.
0
Hi,

public Map<String, String> topping2(Map<String, String> map) {
  if(map.get("ice cream")!=null){
    map.put("yogurt", map.get("ice cream"));
  }
  if(map.get("spinach")!=null){
    map.put("nuts", map.get("spinach"));
  }
  else{
    map=map;
  }
  return map;
}

Open in new window

how above code different from below code

public Map<String, String> topping2(Map<String, String> map) {
//public Map < String, String > topping1(Map < String, String > map) {
   // map.put("spinach", "nuts");
    if (map.containsKey("spinach")) {
        map.put("spinach", "nuts");
   }
      if (map.containsKey("ice cream")) {
        map.put("yogurt", map.get("ice cream"));
       // map.put("ice cream", map.get("ice cream"));

   }
    return map;
}

Open in new window


my above first code fails below test
http://codingbat.com/prob/p196458

Expected      Run            
topping2({"ice cream": "cherry"}) → {"yogurt": "cherry", "ice cream": "cherry"}      {"yogurt": "cherry", "ice cream": "cherry"}      OK      
topping2({"spinach": "dirt", "ice cream": "cherry"}) → {"yogurt": "cherry", "spinach": "nuts", "ice cream": "cherry"}      {"yogurt": "cherry", "spinach": "dirt", "ice cream": "cherry", "nuts": "dirt"}      X      
topping2({"yogurt": "salt"}) → {"yogurt": "salt"}      {"yogurt": "salt"}      OK      
topping2({"yogurt": "salt", "bread": "butter"}) → {"yogurt": "salt", "bread": "butter"}      {"yogurt": "salt", "bread": "butter"}      OK      
topping2({}) → {}      {}      OK      
topping2({"ice cream": "air", "salad": "oil"}) → {"yogurt": "air", "ice cream": "air", "salad": "oil"}      {"yogurt": "air", "ice cream": "air", "salad": "oil"}      OK      
0
Hi,

How below solution is different from

public Map<String, String> topping3(Map<String, String> map) {
 // Map<String, String> map=null;
  if(map.get("potato")!=null){
    map.put("fries",map.get("potato"));
  }
    if(map.get("salad")!=null){
    map.put("spinatch",map.get("salad"));
  }
  else
  map=map;
  return map;
  
}

Open in new window


below solution

public Map < String, String > topping3(Map < String, String > map) {
   // map.put("bread", "butter");
    if (map.containsKey("potato")) {
        map.put("fries", map.get("potato"));

    }
     if (map.containsKey("salad")) {
        map.put("spinach", map.get("salad"));

    }
    return map;
}

Open in new window



please advise.

First one does not pass all tests from
http://codingbat.com/prob/p128461
Expected      Run            
topping3({"potato": "ketchup"}) → {"potato": "ketchup", "fries": "ketchup"}      {"potato": "ketchup", "fries": "ketchup"}      OK      
topping3({"potato": "butter"}) → {"potato": "butter", "fries": "butter"}      {"potato": "butter", "fries": "butter"}      OK      
topping3({"salad": "oil", "potato": "ketchup"}) → {"spinach": "oil", "salad": "oil", "potato": "ketchup", "fries": "ketchup"}      {"salad": "oil", "spinatch": "oil", "potato": "ketchup", "fries": "ketchup"} missing: "spinach": "oil"      X      
topping3({"toast": "butter", "salad": "oil", "potato": "ketchup"}) → {"toast": "butter", "spinach": "oil", "salad": "oil", "potato": "ketchup", "fries": "ketchup"}      {"toast": "butter", "salad": "oil", "spinatch": "oil", "potato": "ketchup", "fries": "ketchup"} missing: "spinach": "oil"      X      
topping3({}) → {}      {}      OK      
topping3({"salad": "pepper", "fries": "salt"}) → {"spinach": "pepper", "salad": "pepper", "fries": "salt"}      {"salad": "pepper", "spinatch": "pepper", "fries": "salt"} missing: "spinach": "pepper"      X      
other tests
OK
0
Jul 27, 2017 3:53:05 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Java\jdk1.7.0_79\bin\;C:\Program Files\nodejs\;C:\Users\khushboo.sharma\AppData\Roaming\npm;.
Jul 27, 2017 3:53:05 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:ALNTUI' did not find a matching property.
Jul 27, 2017 3:53:05 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8082"]
Jul 27, 2017 3:53:06 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jul 27, 2017 3:53:06 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1911 ms
Jul 27, 2017 3:53:06 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 27, 2017 …
0
Hi Experts,

I have a list of files all the file names will be stored in one text document.
now i want to know all the filenames are available in souce directory.
how to identify it.
Please refer the attachment.
0
New benefit for Premium Members - Upgrade now!
LVL 9
New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Hi
I can find all the users I want to entice to my cause, because they like certain Twitter posts.
Can I send them each a DM in Java code?
0
I'm using 11.2.0.4 for Windows 64bit. It comes with Java 5 as part of the install (I'm assuming so you don't need to have Java installed to use Oracle). How do I update that version of Java? I'm running into an error where I need the unlimited crypto package but I can't use it on Java 5 (I tried and it grenaded parts of Windows if I update the security files). I did then install Java 8 on the system but Oracle seems to look at it's own vs what is installed outside of Oracle.
0
We have a small java program that connects to an Oracle (11.2.0.4 Windows) DB. There is a jks file that has the certs in it (4096 key size). When we try to connect we get:

sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: Algorithm constraints check failed: MD5withRSA

If I make changes to entries below in the java.security file in Java:

jdk.certpath.disabledAlgorithms
jdk.tls.disabledAlgorithms

and remove MD5 and MD5withRSA parameters it works. From what I've read this is supposed to be an issue in JRE 7.4 and above but it is only supposed to happen when they key length is 1024 or less. Not sure why it's happening with a 4096 key length cert.
0
hi,

in eclipse java project i have below stored procedure in a DAO class say LMN.java


abc_TerminalXYZ_Select

wen i search on it eclipise not finding.
how to find all the stored proc similar to above in all DAO classes?
what are best search strategies to find what i want in eclipise?
please advise
0
I'm trying to configure SSL(https) for tomcat 8 and have done below steps but still its not working

1) Create the keystore file using

keytool -genkey -alias myservername -keyalg RSA

Open in new window


2) Generated CSR as below

keytool -certreq -alias myservername -file C:\tomcat_ssl\local_machine\test.csr -keystore C:\tomcat_ssl\local_machine\test.keystore

Open in new window


3) Then we had Generated the Certificate and then imported the chain certificate and certificate as below

keytool -import -alias root -keystore C:\tomcat_ssl\local_machine\test.keystore -trustcacerts -file C:\tomcat_ssl\local_machine\srv_chain.cer

Open in new window


keytool -import -alias myservername -keystore C:\tomcat_ssl\local_machine\test.keystore -file C:\tomcat_ssl\local_machine\srv_main.cer

Open in new window


4) Finally Did the changes in tomcat server.xml as below

<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="C:\tomcat_ssl\local_machine\test.keystore" keystorePass="123" keystoreAlias="myservername"/>

Open in new window


Restarted the tomcat and its not working and showing below screen

Tomcat Error Screen for SSL
In tomcat logs it's not showing any errors and also i have tried other options like keeping cipher tag in connection, Enabled TLS 1,2,3 , changing https port etc no avail.

Also i have tested the https port 443 and it's showing as listening when i netstat. Any idea why this is not working
0
At what point should I be concerned with learning data structure and algorithm in Java. I have discovered that it's a very important strategy  to be good in writing codes in any computer language.
0

Java

98K

Solutions

32K

Contributors

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.