Search Results

Search found 33640 results on 1346 pages for 'java generics'.

Page 168/1346 | < Previous Page | 164 165 166 167 168 169 170 171 172 173 174 175  | Next Page >

  • Casting Class into String and Vice Versa in JAVA

    - by topgun_ivard
    I have a program in which I need to store a Class object into memory by casting it into String. Is it possible to convert the String back into the original Class so that I can use that class variables? I am doing this in JAVA. Example: test.java class hello{ public String h1; public String h2; } public class test { public static void main(String[] args) { hello h = new hello(); h.h1 = "hello"; h.h2 = "world"; String s = h.toString(); System.out.println("Print s : "+s); // Now I need to convert String s into type hello so that // I can do this: // (hello)s.h1; // (hello)s.h2; } } NOTE: this is not a homework, this is a personal project and I would be grateful if anyone can help! Thanks! Ivar

    Read the article

  • Benchmark of Java Try/Catch Block

    - by hectorg87
    I know that going into a catch block has some significance cost when executing a program, however, I was wondering if entering a try{} block also had any impact so I started looking for an answer in google with many opinions, but no benchmarking at all. Some answers I found were: Java try/catch performance, is it recommended to keep what is inside the try clause to a minimum? Try Catch Performance Java Java try catch blocks However they didn't answer my question with facts, so I decided to try it for myself. Here's what I did. I have a csv file with this format: host;ip;number;date;status;email;uid;name;lastname;promo_code; where everything after status is optional and will not even have the corresponding ; , so when parsing a validation has to be done to see if the value is there, here's where the try/catch issue came to my mind. The current code that in inherited in my company does this: StringTokenizer st=new StringTokenizer(line,";"); String host = st.nextToken(); String ip = st.nextToken(); String number = st.nextToken(); String date = st.nextToken(); String status = st.nextToken(); String email = ""; try{ email = st.nextToken(); }catch(NoSuchElementException e){ email = ""; } and it repeats what it's done for email with uid, name, lastname and promo_code. and I changed everything to: if(st.hasMoreTokens()){ email = st.nextToken(); } and in fact it performs faster. When parsing a file that doesn't have the optional columns. Here are the average times: --- Trying:122 milliseconds --- Checking:33 milliseconds however, here's what confused me and the reason I'm asking: When running the example with values for the optional columns in all 8000 lines of the CSV, the if() version still performs better than the try/catch version, so my question is Does really the try block does not have any performance impact on my code? The average times for this example are: --- Trying:105 milliseconds --- Checking:43 milliseconds Can somebody explain what's going on here? Thanks a lot

    Read the article

  • java service could not be initialized (debugging help)

    - by vikasde
    I have a jar package that I wrote using netbeans. This package is called from other java file. The jar calls a webservice and is supposed to do something with it. Now everything works fine locally. I compiled the files and locally and uploaded them to the server and when I run it, I get the "Service could not be initialized".I am not sure how to debug this. I am pretty new to java. What is the best approach here to solve the issue?

    Read the article

  • Equivalent for Java's System.getProperty("java.io.tmpdir") in C ?

    - by B_
    As the title says, the java.io.tmpdir property in Java is really nice, and I can't find an equivalent for C. I'm writing for Windows and in Visual Studio. I don't want to just use something like C:\Temp because in later versions of windows the appropriate directory could be something like C:\Users\[UserName]\AppData\Local\Temp and a way to retrieve this would be much easier. I want a directory and not just a temp file because I'm downloading and executing a file from the internet. As a side note, if anyone can give me tips about how to better google for C stuff it would be much appreciated :)

    Read the article

  • web service client in java

    - by user622222
    I want to generate a client program using the service I am unable to display the results, how can I do so? import java.rmi.RemoteException; public class searchtry { public static void main(String[] args) throws RemoteException { SearchRequest request=new SearchRequest(); SearchRequestType1 type1=new SearchRequestType1(); query.setAppId("*********************************"); //Windows Live gave this id for using that service query.setSources(new SourceType[]{SourceType.Web}); query.setQuery("Java"); aratip.setParameters(request); SearchResponseType0 answer= client.search(type1); System.out.println(answer.toString()); }

    Read the article

  • Call javascript function from Java (Groovy) class

    - by ashkanr
    Hi, I have a javascript function (very big one!) that I need its functionality in a Java (Groovy) class. It is a simple calendar converter. I can rewrite it in groovy but just want to know if it is possible to call javascript function from a java (groovy) method? I guess functional testing libraries like selenium and Canoo should have something like this, am I right? PS: I don't want to wake up a real-world browser in order to use its JS runtime env. Thanks,

    Read the article

  • Java: global values inside a class?

    - by HH
    I want less methods. I want a common global TestClass from which I could use any of its value inside the class. import java.util.*; import java.io.*; public class TestClass { TestClass(String hello){ String hallo = hello; String halloSecond = "Saluto!"; } public static void main(String[] args) { TestClass test = new TestClass("Tjena!"); System.out.println("I want "Tjena!": " + test.hallo); TestClass testSecond = new TestClass("1"); System.out.println("I want Saluto!:" + test.halloSecond); System.out.println("I want Saluto!:" + testSecond.halloSecond); } }

    Read the article

  • Java: how to take a screenshot fast

    - by user350789
    I am implementing a simple eye tracker, which requires fast screenshoting of what is happening on the screen simultaneously with capturing the video from webcam. The thing is that the way of doing it with Robot, mentioned here: http://stackoverflow.com/questions/2475303/java-library-for-capturing-active-window-screenshot is extremely slow. By the way, retrieving the video from a webcam works much faster and returns the byte array, which is very fast to be processed. Does anybody know a faster solution? C++ libraries, which can be linked to Java for doing this may help as well. Thank you!

    Read the article

  • Please , Explain these java code ..?

    - by soma
    I want understand these code before java lab exam especially methode import javax.swing.; import java.util.; import java.text.*; public class EnglishCalendar { public static String[] months = { "January" , "February" , "March", "April" , "May" , "June", "July" , "August" , "September", "October" , "November" , "December" }; public static int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; private void showMonth(int m, int y) { int lead_spaces = 0; if (m < 0 || m > 11) { System.out.println("It should be 1 to 12"); } else { System.out.println(); System.out.println(" " + months[m] + " " + y); System.out.println(); GregorianCalendar cal = new GregorianCalendar(y, m, 0); System.out.println("Su Mo Tu We Th Fr Sa "); lead_spaces = cal.get(Calendar.DAY_OF_WEEK); int day_of_month = days[m]; if (cal.isLeapYear(cal.get(Calendar.YEAR)) && m == 1){ day_of_month++;} for (int i = 0; i < lead_spaces; i++) { System.out.print(" "); } for (int i = 1; i <= day_of_month; i++) { if (i < 10) System.out.print(" "); System.out.print(i); if ((lead_spaces + i) % 7 == 0) { System.out.println(); } else { System.out.print(" "); } } System.out.println(); } } private static void doSimpleDateFormat() { Calendar now = Calendar.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); System.out.print(" \n It is now : " + formatter.format(now.getTime())); System.out.println(); } public static void main(String[] args) { String mo = JOptionPane.showInputDialog("Month"); String ye = JOptionPane.showInputDialog("Year"); int mon = new Integer(mo).intValue(); int yea = new Integer(ye).intValue(); EnglishCalendar k = new EnglishCalendar(); k.showMonth(mon - 1 , yea); doSimpleDateFormat(); } }

    Read the article

  • New to JEE; architecture suggestions for a service/daemon?

    - by Kate
    I am brand new to the JEE world. As an exercise to try and familiarize myself with JEE, I'm trying to create a tiered web-app, but I'm getting a little stuck on what the best way is to spin up a service in the background that does work. Parameters of the service: It must open and hold a socket connection and receive information from the connected server. There is a 1-to-1 correlation between a user and a new socket connection. So the idea is the user presses a button on the web-page, and somewhere on the server a socket connection is opened. For the remainder of the users session (or until the user presses some sort of disconnect button) the socket remains open and pushes received information to some sort of centralized store that servlets can query and return to the user via AJAX. Is there a JEE type way to handle this situation? Naturally what I would think to do is to just write a Java application that listens on a port that the servlets can connect to and spawns new threads that open these sockets, but that seems very ad-hoc to me. (PS: I am also new to Stack Overflow, so forgive me if it takes me some time to figure the site out!)

    Read the article

  • Vectors for a 2D/3D World in Java

    - by jax
    I reading about Mathematics in Games and am wondering what is the best way to represent a Vector location in Java. I know there is a Vector class but I don't think this is what I need. There is also a Matrix class which looks like it may be what I want (a 1 dimensional matrix maybe). In particular, if I were to create a location Vector such as: v(x,y,z) where x,y and z are the coordinates in 3D space, what would be the best way to represent this in Java. It would be nice if I could also add, subtract and find the dot-product of Vectors. ideas?

    Read the article

  • Have an external java application by notified of changes to Entity EJBs in JBoss AS

    - by John
    I'm trying to connect an external application to a JBoss AS container. The external application is a Java application that is currently being notified of changes to database entities through a JMS topic. I've added an EntityLifecycleListener class to all my entities that publishes a serialized (and unwrapped) copy of the entity to the JMS topic. The problem is that this implementation ignores the transaction boundaries of the JBoss container. For example, the @PostUpdate event can be fire, generating the JMS message for that entity, but the transaction could be rolled back causing the external application to be notified of an invalid change and become unsync'd. I need my external application to only be notified of successful commits to the database, but I need to be able to publish the entire java POJO to the external application. Is there an official way of doing this?

    Read the article

  • Calling a JAVA method from C++ with JNI, no parameters

    - by PRNDL Development Studios
    Please bear with me, I am an iPhone developer and this whole android this confuses me a bit. I have some c++ methods that are called from a cocos2d-x CCMenuItem. Therefore I cannot send any parameters, according to the docs. I need to open a url with the android browser which will require me to call a JAVA function to start a new intent. I understand that I need to create a VM, however the below code gives me the error: jni/../../Classes/MyClass.cpp:184: error: 'JNI_CreateJavaVM' was not declared in this scope I was looking at this thread: Calling a java method from c++ in Android But he uses parameters, and I can't do that. And I don't see where those are in his code to just make them myself. I don't know what the string should be in the 'Find Class' method. Also, I assume it is pretty terrible to create a new VM instance in every method I need to call. How would I create one as a singleton to use across the board? This is my c++ code called by my menu item: #include <jni.h> ... JavaVM *vm; // Global ... void OptionsScene::website(){ JNIEnv *env; JavaVMInitArgs vm_args; vm_args.version = JNI_VERSION_1_2; vm_args.nOptions = 0; vm_args.ignoreUnrecognized = 1; jint result = JNI_CreateJavaVM(&vm, (void **)&env, &vm_args); // This line still errors jclass clazz = env->FindClass("com/prndl/project/WebExecute"); jmethodID method = env->GetMethodID(clazz, "website", "(Ljava/lang/String;)V"); env->CallVoidMethod(NULL,method); vm->DestroyJavaVM(); And this is the JAVA Method that I need to call: public class WebExecute extends Activity{ public void website(){ Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); startActivity(browserIntent); } } Honestly, I am struggling with this, any help is appreciated. Thanks.

    Read the article

  • Secure Gmail login on web browser from external Java program

    - by Zach Scrivena
    Is there a secure way of logging into a Gmail account on a web browser, from an external Java program? I know the following works, but is there a safer alternative? Desktop.getDesktop().browse(new URI( "https://www.google.com/accounts/ServiceLoginAuth?continue=http://mail.google.com/gmail" + "&service=mail&Email=LOGIN&Passwd=PASSWORD&null=Sign+in")); Clarification: The external Java program is GmailAssistant, a Gmail notifier that already uses the IMAP capabilities of JavaMail. I just need a way of allowing the user to access the account directly in a web browser.

    Read the article

  • Quick to develop web app in Java

    - by Mike Q
    Hi all, I need to develop a basic web app very quickly (1 week) for a demo. My requirements are Java (I need to make use of existing Java libraries to access the relevant data) 2 screens One for static data view, maybe some search parameters Other for basic form entry No fancy AJAX required Ideally easy for a web designer to come in and tart it up as necessary, without having to rewrite everything My first stop was going to be to checkout Wicket as I've heard good things about it. I don't have the time right now to dive into anything heavy, which probably writes off JSF in my mind (I played with JSF1, steep learning curve which I've now slid back down). I'm happy to treat the result as throwaway so if there's a framework which starts of well but then doesn't scale up to bigger projects, that would be ok. Any suggestions appreciated on frameworks/approach.

    Read the article

  • Sending Email using Java

    - by Sunny
    Hi Guys, I want my Java application to send out emails to users. But I cant get a good solution. Now, I got some on Google but they use a SMTP server which I dont have. I was wondering if setting up one on my Linux machine would be easy? So, I am using mailx now to send out emails but it sends emails from root which is definately not good. Is there any way to send out emails from a proper email using java? like you can do in php and other languages?

    Read the article

< Previous Page | 164 165 166 167 168 169 170 171 172 173 174 175  | Next Page >