Java

99K

Solutions

33K

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

When I try to update a document exists on SOLR7 I got this message:

TransactionLog doesn't know how to serialize class java.util.UUID; try
implementing ObjectResolver?

With the stack trace:


{"data":{"responseHeader":{"status":500,"QTime":3},"error":{"metadata":["error-class","org.apache.solr.common.SolrException","root-error-class","org.apache.solr.common.SolrException"],"msg":"TransactionLog 
doesn't know how to serialize class java.util.UUID; try implementing 
ObjectResolver?","trace":"org.apache.solr.common.SolrException: 
TransactionLog doesn't know how to serialize class java.util.UUID; try 
implementing ObjectResolver?\n\tat 
org.apache.solr.update.TransactionLog$1.resolve(TransactionLog.java:100)\n\tat 
org.apache.solr.common.util.JavaBinCodec.writeVal(JavaBinCodec.java:234)\n\tat 
org.apache.solr.common.util.JavaBinCodec.writeSolrInputDocument(JavaBinCodec.java:589)\n\tat 
org.apache.solr.update.TransactionLog.write(TransactionLog.java:395)\n\tat 
org.apache.solr.update.UpdateLog.add(UpdateLog.java:524)\n\tat 
org.apache.solr.update.UpdateLog.add(UpdateLog.java:508)\n\tat 
org.apache.solr.update.DirectUpdateHandler2.doNormalUpdate(DirectUpdateHandler2.java:320)\n\tat 
org.apache.solr.update.DirectUpdateHandler2.addDoc0(DirectUpdateHandler2.java:239)\n\tat 
org.apache.solr.update.DirectUpdateHandler2.addDoc(DirectUpdateHandler2.java:194)\n\tat 
org.apache.solr.update.processor.RunUpdateProcessor.processAdd(RunUpdateProcessorFactory.java:67)\n\tat 

Open in new window

0
Exploring SharePoint 2016
LVL 13
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Our application built with C# and SOLR search.

One of my requirement to implement partial updates with SOLR.I am getting an error while posting JSON data into SOLR server.

Error Response from SOLR API:

{
    "responseHeader": {
        "status": 400,
        "QTime": 30
    },
    "error": {
        "metadata": [
            "error-class",
            "org.apache.solr.common.SolrException",
            "root-error-class",
            "org.apache.solr.common.SolrException"
        ],
        "msg": "Atomic document updates are not supported unless <updateLog/> is configured",
        "code": 400
    }
}

Open in new window

0
Any idea how to fix the following compile error :

InputParsing.java:48: error: unreported exception NegativeNumberException; must be caught or declared to be thrown
                                throw e;
InputParsing.java
0
Would anyone wish to comment on the algorithm here, which finds the GCDs of two numbers? (I'm not asking about number format exceptions etc., just the math and algo elements).


import java.util.*;

class Euclid {


int m;
int n;
int commonDivisor;


    public static void main(String[] args){
    
    
            Scanner scanner  = new Scanner(System.in);
            
            System.out.println();
            System.out.print("Number for higher figure > ");
            Integer higher = new Integer(scanner.nextInt());
            
            System.out.print("Number for lower figure > ");
            Integer lower = new Integer(scanner.nextInt());
            System.out.println();
                   
            Euclid euclid = new Euclid();
            euclid.n = lower.intValue();
            euclid.m = higher.intValue();
            euclid.commonDivisor = euclid.findLargestCommonDivisor(euclid.m, euclid.n);
            
            if(euclid.commonDivisor == -1){System.out.println("These numbers, (or, at least, the higher of the two is), or are, prime. They have no (greatest) common divisor.");}
            else{System.out.println("The largest number that divides both "+euclid.m+" and "+euclid.n+" "+"is . . . . "+euclid.commonDivisor);}

    }
    
    
    private int findLargestCommonDivisor(int m, int n){
    
        int n1 = 0;
        int nPrev = 0;
        
        
        if(m % n == 0){
        
            return n;
            
        }
        

Open in new window

0
Hi,
I came across the following in the book java concurrency in practice :
Screen-Shot-2019-03-13-at-2.32.25-PM.png
Frankly speaking i dont understand why all of these conditions are required.
Unable to find any reasons for all this.

Please help me understand it.

Thanks
0
Hi Team,

I need an help in compiling my java program. I do not have admin writes to set the path variable in my system to point to JDK installed directory.
I need to compile my Employee.java file in D:\JavaProject folder. My JDK is installed in the c:\Program Files\Java\JDK1_8\bin

From D:\JavaProject folder I need to run  javac command
javac Employee.java

Iam getting the below error
unrecognised command  for javac

is there a way to compile the code without having to set the path variable  and mention the JDK path in javac command. Its very urgent

javac  <path of JDK> Employee.java
0
Hi,
I have the following program :
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test implements  Runnable{
    private static SynchronizedInteger synchronizedInteger = new SynchronizedInteger();

    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(5);
        Runnable runnable = new Test();
        executor.execute(runnable);
        System.out.println("After runnable");
        synchronizedInteger.set(100);
        System.out.println("After set 100");
    }


    @Override
    public void run() {
        while(synchronizedInteger.get()!=100) {
            System.out.println("not 100");
        }
        System.out.println("its 100");
    }
}

Open in new window


The program prints the following :
not 100
not 100
After runnable
After set 100
not 100
its 100

But after that doesnt exits.
Why is that ? I guess something related to the thread that is started with executor.execute(runnable)
But dont know the exact reason

Thanks
0
For sending requests to a webservice that deserializes Json, what items in this list are 'required' by the webservice?

HTTPMethod:  
SSLTimeout:  
SSLApplicationID:
SSLCertStore:
SSLCertStorePassword:
SSLVerifyPeer:  
SSLVerifyHost:  
HTTPVersion:
# BasicAuthUser:
# BasicAuthPassword:
# ProxyURI:
# ProxyUser:
# ProxyPassword:
# SendHTTPHeaders:
# HeaderCookieData:
# ResponseCookieFile:
# HeaderSOAPAction:
# HeaderUserAgent:
# HeaderAccept:
# HeaderHost:
# HeaderReferer:
# HeaderConnection:
# HeaderContentType:
# CustomHeaderName(1): Authorization
# CustomHeaderValue(1):
# InputCcsid: 0
# OutputCcsid: 0
# EnableExpectHeader:  
# LocalInterface:
# Enable IPv6:
0
I've got a reasonable knowledge of Java, but this quote from Java in a Nutshell 6th Ed., seems a bit unsettling for some reason to me :

The following code shows that even after a call to manipulate(), the value contained in variable c is unaltered - it is still holding a reference to
a Circle object of radius 2. If Java was [sic] a pass-by-reference language, it would instead be holding a reference to a radius 3 Circle:

   
public void manipulate(Circle circle){
    
        circle = new Circle(3);
        
    }
    
    Circle c = new Circle(2);
    manipulate(c);
    System.out.println("Radius: "+ c.getRadius());

Open in new window


 . . . when contextualised thusly :

class RefDemo {

Circle c;

    public int /*void*/ manipulate(Circle circle){
    
        circle = new Circle(3);
        return circle.getRadius();
        
    }

    
    public RefDemo(){this.c = new Circle(2);}
    
    public static void main(String[] args){
  
        RefDemo rd = new RefDemo();
        
        System.out.println("Radius:"+(rd.manipulate((rd.c))));
        System.out.println("Radius: "+ rd.c.getRadius());

    }
  
  
  public class Circle {
  
  private int radius;
  
    public Circle(int r){
    
        this.radius = r;
    
    }
    
    public int getRadius(){return this.radius;}
  
  }
  
}

Open in new window

0
Hi Experts,

could you suggest the best way to convert custom application text log file to json format please

Read the whole file and convert line by line to json on a windows server.

Since application generate log in its custom location, may be I should read this directory for each file > convert each line to json object, place it in a different location. Also we should not duplicate or read the same line again :)

Also is it possible to apply similiar logic to windows events log.

please advice
0
Introduction to R
LVL 13
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

I am currently learning Java.

I would like to create a class that contains a constant variable (it should not be changed by anyone) that is structured in a similar way (I will use JSON to show an example):
{
	"key_1": "value_1",
	"key_2": "value_2",
	"object_1": {
		"object_1_key_1": "object_1_value_1",
		"object_1_key_2": "object_1_value_2",
		"object_1_key_2": "object_1_value_3",  
	}
}

Open in new window


What would be the best Java data structure to obtain such result?

I thought a HashMap could've been a good start but then if I use:
private HashMap<String, String> myHash;

I am then forced to just use strings...

Can you please suggest a solution?

Thanks for your time and patience.
0
Suggestions for an appropriate way to retrieve a running Java programme into its state prior to such things as sockets and streams being opened, and threads run, variables set etc ?
0
I study a Java code and what the meaning of  "<T extends Shape> void printValidColors()" ?  Why does the data type appear as "<T extends Shape> " ?  For calling this method, do I always need to provide the format like "ShapeDriver.<Rectangle>printValidColors();" ?

    
public class ShapeDriver {

    public static void main(String args[]) {
        System.out.println("Valid Shape colors:-");
        ShapeDriver.<Shape>printValidColors();
        System.out.println();

        System.out.println("Valid Rectangle colors:-");
        ShapeDriver.<Rectangle>printValidColors();
        System.out.println();

        System.out.println("Valid Circle colors:-");
        ShapeDriver.<Circle>printValidColors();
        System.out.println();

private static <T extends Shape> void printValidColors() {
        final int nthWrapEvery = 5;
        for (int i = 0; i < T.getNumOfValidColors(); i++) {
            System.out.print(T.getValidColor(i) + " ");
            if ((i + 1) % nthWrapEvery == 0) {
                System.out.println();
            }
        }
    }

Open in new window

0
I need to check with you how to OR two Booleans please.

They need to be Booleans as they’ll be exchanged over a Socket. But they can be booleans locally of course. What’s the suggested best approach?
0
vec = new Vector<String>(fArr.length); // Vector<String> vec declared earlier.
    
                        
            for(File fi : fArr){vec.add(fi.getName());}
            
            for(Object s : vec.toArray()){System.out.println((String)s);} // this prints the filenames to the console
            
            System.out.println("Files length is  "+fArr.length);// prints whatever length the array is
            System.out.print("vec is "); 
            System.out.println(vec==null); // prints TRUE !!

Open in new window

0
When displaying the contents of the credential file, I'm trying to apply each column of data to a variable. For example:


a = griffen.keyes

b = 108....

c = alphabet soup

d = zookeeper


The "c " variable it's not working correctly. Java is seeing this as two values despite the "".

How do I fix that?

Attached is a screenshot that I am reading from.
Below is my code so far.





package openCredFile;
import java.util.*;
import java.io.*;

public class TestingRandomMethods {
   public static void main(String[] args)throws IOException{
       TestingRandomMethods T = new TestingRandomMethods();  
       T.openFile();
       T.readFile(); //The main method calls these methods and executes them. It's the readFile method that prints the info.
       T.closeFile();
       
}
       
    Scanner CredData; //Putting this outside of the method makes it available to all methods?
    public  void openFile() throws IOException {    //I had an error until I added "throws IOException" when trying to open the file.
         
        try{
        CredData = new Scanner(new File("credentials.txt")); //Opens the file.
    }
        catch(Exception e){
            System.out.println("Could not find file.");
        }
        }
    public void readFile(){
        while(CredData.hasNext()){ //will loop until it reaches the end of the file. hasNext means to read the entire file.
            String a = CredData.next();
            …
0
All,

I'm trying to read and output the contents of a file called credentials.txt. The code is below and attached is the error I'm getting.

package testingrandommethods;
import java.util.Scanner;
import java.io.*;

public class TestingRandomMethods {

   
    public static void main(String[] args) throws IOException {    //I had an error until I added "throws IOException" when trying to open the file.
         
        FileInputStream fileByteStream = null;
        Scanner credFile = null;
        String credData = "";

        //Attempt to open file
        fileByteStream = new FileInputStream("credentials.txt");
        credFile = new Scanner(fileByteStream); //credFile now contains what's in credentials.txt.
        System.out.println("Reading and printing data.");
        credData = credFile.next(); //credData now contains what's in credentials.txt as well. It allows me to read through the file.
       
        while (credData.charAt(0)){
            System.out.println(credData);
           
            credData = credFile.next();
        }
        System.out.println(credData);
       
        //Close the file
        System.out.println("Closing the credential.txt file.");
        fileByteStream.close();
        return;
    }
   
}

ErrorMessage.png
0
Hi,

I am trying startup jboss-cli.sh, however, i keep getting the following errors.

the domain controller service is up without issues, I can login http://<dc_ip>:9990

JBOSS: EAP 6.4 update 21

======================================
[jboss@domainController bin]$ ./jboss-cli.sh
Exception in thread "Thread-2" java.lang.RuntimeException: broken pipe
      at org.jboss.aesh.console.reader.ConsoleInputSession$2.run(ConsoleInputSession.java:95)
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /]
[jboss@domainController bin]$
====================================

anyone can help? much appreciated
0
Hi,

I have a java app, which acts as an oracle client/bridge between a mobile app ( data visualisation) and oracle database. The java app is capable to multithread if more than one request is made at a time.
No issues here, all works fine. The aim was to refrain from plugin mobile devices to the db.
Apart from the mobile app side, it's possible to run queries against the db on a scheduler i.e. every 5 mins and keep results in a buffer.

Anyway, In a production environment, my app was connected to a client database for a couple of weeks and suddenly the below error stopped the oracle form working causing a massive issue to the customer of mine.

ORA-01034: ORACLE not available ORA-27102: out of memory Linux-x86_64 Error: 12: Cannot allocate memory


Obviously, suspicion is that my product caused the Oracle problem. Apparently, oracle ran out of "accessible memory"  ( whatever that means - it wasn't techy guy who talked to me)

...so my question to you is if running queries against DB can cause any memory issues?

As far as I know, a bad sql ( there wasn't any in this case) can cause long-running queries/sessions, which can consume a lot of CPU and indeed can slow oracle down...

what's your view on this, please ?
0
OWASP: Forgery and Phishing
LVL 13
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Hello
Can someone help me out to set a format (###,##0.00) to JavaFx editable Double TableColumn.
Here is my code so far
....

	taux.setCellFactory(TextFieldTableCell.<CoursChange, Double>forTableColumn(new DoubleStringConverter()));
		taux.setOnEditCommit(event -> {
            TablePosition<CoursChange, Double> pos = event.getTablePosition();
            double newVal = event.getNewValue();
            int row = pos.getRow();
            CoursChange xcours = event.getTableView().getItems().get(row);
            xcours.setTaux(newVal);
            
            dataService.updateRecord(xcours.getId(), AppSettings.COMPANY_ID, newVal);
            
        });
...

Open in new window


Thanks a lot
0
Hi Team,

I need an clarification in regard to creatiionn of  strings

for example when I create a string using string literals , i know it gets created in string constant pool .

Case 1 :
But when i  create it using the below code , does it get created in heap at runtime
String str="Hello";
String str1= str + "Welcome to Strings"; -- My question is does this string gets created in heap and a copy of the string is placed in scp by JVM.

Case2:
The reason why iam asking this question is
I created one more string as below
String str2="Hello Welcome to Strings";  and then compared str1 and str2 using == it gave me false

Case3:
The same thing I tried the other way
String str="Hello";
String str1= str + "Welcome to Strings";
str1=str1.intern();
String str2="Hello Welcome to Strings";

If (str1==str2)  -->it return true.

My question is based on the above scenarios , does it mean that when I create a string using non lietrals and non compile time constants it
creates the object in heap and stores a copy of the string in String constant pool.
0
Hi Team ,
Below is the code Iam using running jdbc application , Iam new to Java . Iam not getting the excpected output


folder NAme : jdbcprograms
in this folder I have ojdbc6.jar and DBConnection.java file and class file.

import java.sql.*;

public class DBConnection
{
      public static void main(String [] args)
      {
            try
            {
      
                  Class.forName("jdbc.odbc.JdbcOdbcDriver");
                  Connection conn = DriverManager.getConnection("jdbc:odbc:Oracle-Hr","HR","orcl");
                  System.out.println(conn.getClass().getName());
            if (conn==null)
            {
                  System.out.println("Connection not established");
            }
            else
            {
                  System.out.println("Connection is  established");
            }
            }
            catch(SQLException e)
            {
                  System.out.println(e);            
            }
            catch(ClassNotFoundException e)      
            {
                  System.out.println(e);            
            }
            catch(Exception e)
            {
                  System.out.println(e);            
            }            
      }
}


When I run the code as below , I get the below output , but not getting the connection established output. Any help is really appreciated

D:\JdbcPrograms>java -jar ojdbc6.jar DBConnection
Oracle 11.2.0.1.0 JDBC 4.0 compiled with JDK6

Expected Output
Class Name Output for Connection Class
Connection established.
0
Hi: I am using Java to amend a text file. There are 80 fields (csv) in the file so I have split into 80 string arrays.
However, one amendment requires me to subtract one array from another. It is the last amendment I need to do!
Does anybody know how to change a string array in java to a number?
I attach the csv file I am trying to amend, plus the java I have written so far. Don't laugh; I am just a novice at this stuff.
Line 166 in the java is where i have 'added' the two arrays  - String d4 = (x[62])+ (x[63]);
I need to subtract!
Thanks!
1907D45C.CSV
filesweeper.txt
0
In selenium is it possible to know the type of the locator whether it is given in css or xpath or id or name or linktext etc..

the requirement is i get the locator in the form of a string and i have to know whether it is CSS or xpath

By selector = driver.findElement(By.cssSelector(locator));

if(selector == null){

  selector = driver.findElement(By.xpath(locator)); }

Open in new window

as the very first statement throws an exception if it is a different locator, is there an easy way that we can identify the type and handle and type of locator
0
Hello
I m new in Java and i need help with a question i have.
Protected Constructors can be accessed form subclasses from other packages too.
Can i create one object from this subclasses? And if yes is there any sample code ?
thank you in advance.
0

Java

99K

Solutions

33K

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.