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
Get real performance insights from real users
LVL 1
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Please help, I am trying to run my project through debug as it helps me see my break points and if my code it working line by line but now when i try to debbug i get this exception. I tried using this link below to resolve my issue but now I am worried it could be something in my code.

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014690354 

When I run it straight with the server its fine but I want to debug. I am fairly new in JAVA and feel very very DUMB



[2017/08/16 10:03:01:061 CAT] 00000087 LocalTranCoor E   WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[2017/08/16 10:03:01:061 CAT] 00000087 webapp        E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[GenericServletWrapper]: javax.el.ELException: Unable to find ExpressionFactory of type: com.ibm.javart.debug.resolution.InterpExpressionFactory
      at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:190)
      at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:118)
      at com.ibm.ws.jsp.configuration.JspConfiguration.<init>(JspConfiguration.java:63)
      at com.ibm.ws.jsp.configuration.JspConfigurationManager.getConfigurationForUrl(JspConfigurationManager.java:99)
      at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.translateJsp(AbstractJSPExtensionServletWrapper.java:560)
      at …
0
I need to send a POST request using java. The server i am trying to access has a username and password i need to pass those parameters as well.

1.) I have installed Tomcat in my machine and configured the developer environment. I am using eclipse. There are different types of projects i could create using Eclipse, and i need to know what is the best project i should create to develop my application ?

2.) Can someone show me some sample code or tutorial which would help me to develop my task ?

My Eclipse version : Eclipse Java EE, Indigo service release 2

EDIT

Is it a JPA project, Enterprise Application Project, Dynamic Web Project, Dynamic Web Application, EJB project, Application Client project, Static Web Project.
1
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
Oracle 11g forms/reports not running due to JAVA updates

We have our application running on Oracle forms/reports with JAVA 7 updates 21. Recently on some computers with Windows10, our application is not able to open through IE11. When we click on our application, it will redirect page to JAVA.com website for update. But our application won’t run on latest updates other than JAVA 7 updates 21

Please advise if any solution for this ?
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
tomcat wont start in debug

where as tomcat is staring fine in regular mode.

i increased time out from 45 to 450 still similar error.

Server Tomcat v8.0 Server at localhost was unable to start within 450 seconds. If the server requires more time, try increasing the timeout in the server editor.
i wonder why server starts in regular mode but takes forever to start in debug mode.

regular startup happens in 10 seconds asap.

Aug 14, 2017 5:40:21 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:wsdlfirstws' did not find a matching property.
Aug 14, 2017 5:40:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.39
Aug 14, 2017 5:40:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Nov 9 2016 08:48:39 UTC
Aug 14, 2017 5:40:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.39.0
Aug 14, 2017 5:40:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 10
Aug 14, 2017 5:40:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.0
Aug 14, 2017 5:40:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Aug 14, 2017 5:40:21 PM org.apache.catalina.startup.VersionLoggerListener log…
0
Hi,

I have  abc.zip which i unzipped and imported to eclipse as maven project.

Later i got updated version of abc2.zip. I extracted to differnt folder called new_folder. Now when i try to import abc2.zip i am getting error as

 Project wsdlfirstws already exists
 Add a version or custom suffix using "Name template" in "Advanced" settings



how to fix this error and import updated abc2 project
0
The Java community is the largest programming community in the world and Java is adding more and more features which is making it a powerful programming language and keeping ahead with other programming languages. Java 9 has become more powerful with the introduction of JShell Java’s REPL (read-eval
0
Hi,

I have created a custom exception class which is having constructor

public class BusinessException extends Exception {

	private static final long serialVersionUID = -8817025373765348946L;

	public BusinessException (String key) {
		super(ErrorType.BUSINESS, key);
		this.key = key;
	}

	public BusinessException (String key, String[] args) {
		super(ErrorType.BUSINESS, key);
		this.key = key;
		if (args != null) {
			this.errorArgs = Arrays.copyOf(args, args.length);
		}
	}

	public BusinessException (String key, String defaultMessage) {
		super(ErrorType.BUSINESS, key);
		this.key = key;
		this.defaultMessage = defaultMessage;
	}

	public BusinessException (String key, String[] args, String defaultMessage) {
		super(ErrorType.BUSINESS, defaultMessage);
		this.key = key;
		if (args != null) {
			this.errorArgs = Arrays.copyOf(args, args.length);
		}
		this.defaultMessage = defaultMessage;
	}
}

Open in new window



From my dao layer i am throwing exception
new BusinessException ("error occurred", "raj","23")


while catching the exception in controller layer how will i get the values "raj","23"?
0
Free Tool: Path Explorer
LVL 9
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Hi,

I need to create a common method which handles all the exception.There are controllers,logic layers,dao layers.
Flow is

isValidLogin() calls the method of logic layer validUserLogic() further goes to dao layer (validUserDAO) ,Now exception occurrred in the dao layer and the exception is thrown using (throw new AppBussinessException)

What i need is when exception is thrown from dao layer it should go to common classs which will take care of the exception.

How to achieve this?
0
Hi,

I have downloaded tomcat 9 zip file and extracted to local windows laptop.

i then added as new server in eclipse by pointing to tomcat location.

when i start tomcat now getting below error


i see tomcat 8.5 download page
https://tomcat.apache.org/download-80.cgi

I do not see tomcat 8 download page.
https://tomcat.apache.org/tomcat-8.0-doc/index.html
how to resolve this

any  good video tutorials on this tomcat installationa nd integrating to eclipse
i hate window service installer version on my windows 10 laptop


Aug 11, 2017 11:29:22 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:hellows' did not find a matching property.
Aug 11, 2017 11:29:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/9.0.0.M26
Aug 11, 2017 11:29:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Aug 2 2017 20:29:05 UTC
Aug 11, 2017 11:29:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         9.0.0.0
Aug 11, 2017 11:29:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 10
Aug 11, 2017 11:29:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.0
Aug 11, 2017 11:29:22 PM org.apache.catalina.startup.VersionLoggerListener log…
0
I need to download a sharepoint file to Android.  I know how to easily download files to android from repositories which does not need any kind of authentication.

But Sharepoint being an authenticated system, I need to understand how I can achieve this programmatically.

I know about jshare which is a paid solution. I do not want to go for a paid solution. But I would like to have a free program solution for this.

Any help is much appreciated.
0
Hi Experts,

I have written the below code to read from multiple files and write it into another file.

i have a parent folder
C:/Users/Test/Desktop/alert/read/New folder
under this there are two subfolders-->jj and kk
these two folders might have n no files but i am looking  for INFO.txt
both sub folders will have this INFO.txt file but content will be different may be one or two lines duplicated.

so i have created another file to write the data
C:/Users/Test/Desktop/alert/read/New folder2/INFO.txt

to avoid duplicate lines i have use hash set.
From the below code i am getting expected result.

Can some one help me this code is perfect or need improvement.
 
public class FileWritingExample {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		BufferedWriter bw = null;
		BufferedReader br = null;
		Set<String> lines = new LinkedHashSet<String>();
		File parentDir = new File(
				"C:/Users/Test/Desktop/alert/read/New folder");
		String[] names = parentDir.list();
		System.out.println(names.length);
		File outputFile = new File(
				"C:/Users/Test/Desktop/alert/read/New folder2/INFO.txt");
		for (String name : names) {
			if (new File("C:/Users/Test/Desktop/alert/read/New folder/"
					+ name).isDirectory()) {
				File path2 = new File(
						"C:/Users/Test/Desktop/alert/read/New folder/"
								+ name);
				File[] listOfFiles = path2.listFiles();
				System.out.println("list " + 

Open in new window

0
Hi, I'm Pradip Kumar, Java Developer. I need some help to Develop My Java application for my desktop.
To show registry key, subregistry key till n number,
To show control panel Installed software under J Frame Java .
0
I'm Developing an application for my windows. I want to show all missing registry key file path, and unused applications.
I want to show control panel under Jframe In java Technologies. Please any body help me.
0
While installing tomcat how to know which http free port is free?8080 is always busy occupied by glassfish etc.

any tool or software etc which tells all free and occupied ports on my windows laptop to decide which port to allocate to tomcat?

what is ajp/1.3 conector port 8009 which shows while installing?
please advise
0
#TodayILearned that sometimes, the #Java #CharBuffer can't give an #array of the #CharSequence it #wrap ped.
 
That happened with a #StringBuilder instance, which implements CharSequence.
 
A CharBuffer's array() method normally returns the char[] array that backs it. But the method will throw an #UnsupportedOperationException if no such array is available. And that is exactly the case I encountered today, when I had it wrap a StringBuilder.
 
So instead, we use CharBuffer.get(dest), in which we define dest as a char buffer of the desired size.
 
In my case:
 
final char[] buffer = new char[input.length()];
CharBuffer.wrap(input).get(buffer);
 
Happy coding!
0
I have a java ldap query where I pull all users that exist in a group. However, I now need to filter out disabled accounts. How do I modify my search to exclude disabled users?

Below is my current java ldap query.

    private LdapContext getTM1users(MbElement parser) throws FileNotFoundException, SQLException, IOException, MbException, NamingException
      {
            LdapContext ctx = null;
            MbElement start = null;
            Attributes attrs = null;
            NamingEnumeration answer = null;
            String group = null;
            String location = null;
            
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "Factory");
        env.put(Context.SECURITY_AUTHENTICATION, "Simple");
        env.put(Context.SECURITY_PRINCIPAL, "UserID");
        env.put(Context.SECURITY_CREDENTIALS, "Password");
        env.put(Context.PROVIDER_URL, "ldapURL");
       
        ctx = new InitialLdapContext(env, null);
            SearchControls constraints = new SearchControls();
        constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        String[] attrIDs = {"sAMAccountName"};
        constraints.setReturningAttributes(attrIDs);
       
        Hashtable<String, String> ht = new Hashtable<String, String>();
            ht.put("Agent_Comm", "Agent_Comm");
            ht.put("Elec_Finance", "Elec_Finance");
            ht.put("Freight", "Freight");
            ht.put("Vids", "Vids");
            
            Set<String> keys = ht.keySet();
            
            for(String key : keys)
            {
                  group = …
0
Get 15 Days FREE Full-Featured Trial
LVL 1
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

how to install RabbitMQ using erlang and how to make SSL certificate to work
i am getting an error I am unable to run the server(RabbitMQ )
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.10\sbin>rabbitmq-server.bat

              RabbitMQ 3.6.10. Copyright (C) 2007-2017 Pivotal Software, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: C:/Users/anoop/AppData/Roaming/RabbitMQ/log/RABBIT~1.LOG
  ######  ##        C:/Users/anoop/AppData/Roaming/RabbitMQ/log/RABBIT~2.LOG
  ##########
              Starting broker...


BOOT FAILED
===========

Error description:
   {could_not_start,rabbit,
       {{case_clause,
            {error,
                {{shutdown,
                     {failed_to_start_child,
                         {ranch_listener_sup,
                             {acceptor,{0,0,0,0,0,0,0,0},5672}},
                         {shutdown,
                             {failed_to_start_child,ranch_acceptors_sup,
                                 {listen_error,
                                     {acceptor,{0,0,0,0,0,0,0,0},5672},
                                     eacces}}}}},
                 {child,undefined,'rabbit_tcp_listener_sup_:::5672',
                     {tcp_listener_sup,start_link,
                         [{0,0,0,0,0,0,0,0},
                          5672,ranch_tcp,
                          [inet6,
                           {backlog,128},
                          …
0
http://codingbat.com/prob/p168493
public Map<String, String> firstChar(String[] strings) {
  Map<String, String> map=new HashMap<String, String>();
  
  for(String str:strings){
  int len=str.length();
    map.put(""+str.substring(0,1), ""+str(0,len));
  }
  return map;
}

Open in new window


Compile problems:


cannot find symbol str(int,int) line:6

see Example Code to help with compile problems

I am getting above error. What is int, int here. How to fix this error and improve my code. please advise
0
http://codingbat.com/prob/p117630
public Map<String, Integer> wordCount(String[] strings) {
  Map<String, Integer> map=new HashMap<String, Integer>();
  for(String str: strings){
    int i=0;
    if(str.equals(str)){
      i++;
    }
    map.put(str,i);
  }
  return map;
}

Open in new window

Expected      Run            
wordCount(["a", "b", "a", "c", "b"]) → {"a": 2, "b": 2, "c": 1}      {"a": 1, "b": 1, "c": 1}      X      
wordCount(["c", "b", "a"]) → {"a": 1, "b": 1, "c": 1}      {"a": 1, "b": 1, "c": 1}      OK      
wordCount(["c", "c", "c", "c"]) → {"c": 4}      {"c": 1}      X      
wordCount([]) → {}      {}      OK      
wordCount(["this", "and", "this", ""]) → {"": 1, "and": 1, "this": 2}      {"": 1, "and": 1, "this": 1}      X      
wordCount(["x", "y", "x", "Y", "X"]) → {"x": 2, "X": 1, "y": 1, "Y": 1}      {"x": 1, "X": 1, "y": 1, "Y": 1}      X      
wordCount(["123", "0", "123", "1"]) → {"0": 1, "1": 1, "123": 2}      {"0": 1, "1": 1, "123": 1}      X      
wordCount(["d", "a", "e", "d", "a", "d", "b", "b", "z", "a", "a", "b", "z", "x", "b", "f", "x", "two", "b", "one", "two"]) → {"a": 4, "b": 5, "d": 3, "e": 1, "f": 1, "one": 1, "x": 2, "z": 2, "two": 2}      {"a": 1, "b": 1, "d": 1, "e": 1, "f": 1, "one": 1, "x": 1, "z": 1, "two": 1}      X      
wordCount(["apple", "banana", "apple", "apple", "tea", "coffee", "banana"]) → {"banana": 2, "apple": 3, "tea": 1, "coffee": 1}      {"banana": 1, "apple": 1, "tea": 1, "coffee": 1}      X      
other tests
X      

how to fix and improve my code for above challenge?
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
we've IBM Cognos software program established with it is personal custom tomcat server. Is there any manner i will deploy my java EE aplication to this server and use it throught net browser? there may be trendy tomcat /webapps folder and that unpacks my .warfare report into precise folder as general tomcat does, however i'm just now not able to get to my application in web browser. there is some sort of filtering that always redirects me to "IBM Cognos Connection" or invalid web page.
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.