Is it a good idea to have basic code that works such as classes print lines array definitions ect ect in your own library in word or something so you can copy and paste it and then edit it to suit what you are doing or is this a bad idea and you should right everything from scratch...
trying to get into Java and jump into just programming an idea.I want to go through an array of numbers at a certain pace and call different sounds as it goes through.
Java Code: import jxl.read.biff.BiffException; import java.io.*; import java.util.*; import jxl.*; import jxl.write.*; public class MainProgram{ public static void main(String[]args){ try{ Workbook workbook = Workbook.getWorkbook(new File("myfile.xls"));
[Code]...
Not sure why this code isnt working for me, it makes an empty excel file called output, but never copies the contents in "myfile" to that output file. I have Excel 2010 but I saved both of them as 97-2003 workbooks. Am I missing something? Do you have to go cell by cell to copy an excel file with JXL?
public class Cash { //Quanity Field and RetailItem Object field private int total_units; private Retail myRetail;
//Create first constructors public Cash() { this(0,null);
[Code] ....
I'm seriously need to understand the concept of making shallow copies and deep copies. My book has shown me that its better to perform deep copies and I have followed that method. if you guys look in my constructor of the cash class
//Create a a constructor public Cash(int total_units,Retail myRetail) { this.total_units=total_units; this.myRetail=new Retail(myRetail);
Apparently I have field in Cash Class named
Retail myRetail
When I pass in an argument from my demo, I'm making a copy of that object from the demo class. In my retail class, I have the following copy constructor .
//Make a copy constructor public Retail(Retail Object1) { Item_Name=Object1.Item_Name; Item_Number=Object1.Item_Number; // if I use this then my program would work//this.cost=Object1.cost;
//if I use this part of code below, my program won't work at all and I would get an error saying Exception in thread "main" java.lang.NullPointerException this.cost.Item_Cost=Object1.cost.Item_Cost; this.cost.Wholesale_Cost=Object1.cost.Wholesale_Cost; }
My question is why can't I perform a deep copy there. I know if I do
this.myRetail=myRetail
in my cash constructor it would work, but then the book says its not a good method;
I am developing a web application in java(JSF 2.0 - Prime Faces). I need to do below operation. My appllication is running on WLS server. WLS is deployed on a server(say Machine-X). In my application i have a requirement , where i have to copy file from Machine-X to another Machine-Y. The Machine-Y is access restricted.
When i tried to copy the file from my app, getting no access exception. I have full control over Machine-Y. We cannot use SFTP as SFTP cannot be installed on target machine(Machine-Y). Robocopy is failing for some use cases. Is there any other way we can copy/write file from one server to other by providing userid/password in java
How do u copy all the elements in an array eg A into another array eg B? This is the question:
An array A contains integers that first increase in value and then decrease in value,
For example, 17 24 31 39 44 49 36 29 20 18 13
It is unknown at which point the numbers start to decrease. Write efficient code to code to copy the numbers in A to another array B so that B is sorted in ascending order. Your code must take advantage of the way the numbers are arranged in A.
This is my program:
This is the error message:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at Quest30.CopyAndSortArray.main(CopyAndSortArray.jav a:16)
import java.util.ArrayList; import java.util.Random; public class NumSorting { public static int numOfComps = 0, numOfSwaps = 0; public static void main(String[] args)
[Code] ....
What is wrong with my code in this sorting program? It won't copy the random generated numbers to the sort method. How to get the random generated numbers to copy to the sort method. Below is what the program is displaying.
I have a file(source.txt) that contains some texts. Now, the java code is to run through each line in the source file and check if that line begins with a number and if true, copy that line to the destination file(destination.txt). I have the code but I am not sure why I can't loop through each line in the source.txt file. Below is my java code:
public static void copyFile(File source, File destination) { BufferedReader br; try { FileWriter fw = new FileWriter(destination.getAbsoluteFile()); PrintWriter bw = new PrintWriter(fw); br = new BufferedReader(new FileReader(source)); String line = new String();
[Code] ....
As shown in the source.txt file, there are 4 lines in the file but when the execution gets to while ((line = br.readLine()) != null) , it executes to false.. Why this is so?
below is the source.txt file
12 is a number Green is bad 5 is not so cool you are right
I am currently working on a project where I need to return data from a database over RMI to a client who requests it. Some of the fields in the Data Object can not be seen by the client so I need to create another object to send over the network instead. The method I use is this...
public static SerializableObject createSerializableObjectFromDataObject(DataObject dataObject){ SerializableObject serializableObject = new SerializableObject(); serializableObject.setField(dataObject.getField()); serializableObject.setAnotherField(dataObject.getAnotherField()); return serializableObject; }
Is there a better way of doing this? I am creating many subclasses DataObject which all require this static method to be implemented and I can't push it into the superclass because each one needs custom behaviour.
My perfect idea is to have a Hashmap that would increase size each Key & value added, it's almost like a self-increasing array. I mean I could just create a very large Hashmap for me to add objects to anytime I want with a key to be able to find the object. Is this the most efficient way, because I'm trying to make my Object Library compatible with any amount of Objects, however, I know there's a limit to how many values you can have in an array, but it's larger than I'll ever need.
Let's say I'm making a number storage program, and I may need from 3 to 8 numbers to be stored with a key to find them easily using a Hashmap, rarely I may need below 3 or above 8. So is it efficient for me to create a Hashmap that has 10 placeholders? Or can I make this more efficient. Note, my Library is static.
I have written a library in one project but cannot seem import to import it into my main project whenever I try Maven says it cant find it though it is installed in the repository and the .jar file is in the classpath.
Stack trace org.jclarion.clarion.lang.ClarionCompileError: Class Not Found:com.MyProj.app.MyClass near line:310 (selma012.clw) at org.jclarion.clarion.lang.Lexer.error(Lexer.java:190) at org.jclarion.clarion.compile.grammar.AbstractParser.error(AbstractParser.java:111) at org.jclarion.clarion.compile.grammar.AbstractParser.importJava(AbstractParser.java:463) at org.jclarion.clarion.compile.grammar.AbstractParser.emptyLex(AbstractParser.java:258)
I was a bit confused of the code generated by the Axis2 Code Gen.
I have created a logIn(String username, String password) method in my service and used Axis2 Code Gen to generate the Stub.
I try to access the logIn method from my Client using the Stub like below:
TestServiceStub stub = new TestServiceStub("http://localhost:8080/axis2/services/TestService"); String test = stub.logIn("user","pass").
but instead of UserName and password as the parameters, the Stub created a Login object as the parameter for the logIn method. like the one below:
stub.logIn(Login login1);
I wanted to try the logIn method by providing a static userName and password but it seems impossible because the Stub changed the parameter for the logIn method.
The code here I have works fine if I just want to ask the user to enter four digits: //java application that asks user to input binary numbers(1 or 0) and convert them to decimal numbers import java.util.Scanner; //program uses class scanner public class binarynumber{
//main method that executes the java application public static void main(String args[]){ //declares variables
int digit; int base=2; int degree; double decimal; int binary_zero=0; int binary_one=1; //create scanner for object input
[code]....
The thing is, I want the java application to input more than four digits for the user and I want it to loop it manytimes f until the user ask it to stop.
I want to download objects (css , jpeg, html ,png ) using sockets in java without using httpurlconnection . How can i do this with simple socket library ?