Can A Class Be Broken Into Multiple Source Files?
Apr 3, 2014
The problem is what to do when the source file for a class gets too big ( a judgment call for sure). Is it possible for one class to be defined in multiple files and if so how do you do it, and is it good practice?
I do see ways to refactor into a base class or move code into a helper class but sometimes the abstraction is cleaner as a single class that does a lot of stuff. My problem is how to organize a BIG class?
View Replies
ADVERTISEMENT
Apr 23, 2015
I'm having another issue. I have 2 java source files(see below). They are place in the same directory. How do I compile them using classpath?
I have already tried 1st attempt :
javac -cp com.companyname.interview.DuplicateReplace.java DuplicateReplaceTest.java [did not work!]
2nd attempt: javac -cp DuplicateReplace.java DuplicateReplaceTest.java [again, did not work!]
package com.companyname.interview;
public class DuplicateReplace { /* code */}
[Code] ....
View Replies
View Related
Apr 3, 2015
In using javac, I have installed the JDK, set the PATH and JAVA_HOME. When I run this:
"C:Program FilesJavajdk1.8.0_40injavac" -cp C:Gj_javacHTMLCarbonResults.java
I get: javac: no source files
Since I placed the source file path in the command line, I don't understand why it can't find the one .java file.
View Replies
View Related
Apr 10, 2014
my course material is due for term 1 of my cert 4 programming course, but My lecture will not pass my java projects because there is no source files generated for them in the net beans project structure, tried building, cleaning and building, all i can think of?, tried IDE's 7.4 and 8.0 .
View Replies
View Related
Feb 14, 2014
I am looking for a way to compile Java Source-Files at runtime and save them all in an executable jar; almost like an IDE would do. I know that there is the javax.tools package which provides a JavaCompiler interface and you can use ToolProvider.getSystemJavaCompiler() to get an instance of a compiler. However, this method has one important problem: it only works on machines that have the JDK installed. Not when only the JRE is installed.
I guess at this point that I need some kind of third party library that offers an implementation of a JavaCompiler. Unfortunately, this is really complicated to search for on the internet since all top listings when searching "compile java at runtime jre" do not really provide a solution to the problem.
I am writing a (somewhat) complex simulation software right now which is supposed to be used by people who have absolutely no knowledge of programming. At the same time, this software should provide the user with a certain amount of flexibility and control over the flow of the simulation.
My previous take on this problem was to build a complex system to interprete user settings from a GUI. I would basically read the GUI input, output it to some kind of own scripting syntax which I just quickly made up and have that interpreted at runtime. Then I realized, that is a silly concept and I threw it out before I got far into the developement.
The much better solution I came up with is taking the input from the GUI, create java source code from it and compile it at run-time. Seems much cleaner and nicer to me; will also probably have a better performance, but thats not really an issue anyways.
View Replies
View Related
Jun 3, 2014
What's wrong with my code. It says 'you win' even when I guess an incorrect number. And then the 'win' message keeps repeating. I'm thinking I need a way to generate a new input? And then maybe take the 'win' message out of the loop, but that breaks it too.
View Replies
View Related
Oct 9, 2014
"If you define a public class or an interface in your class, then it should match the name of the java source code file."
Does the statement above mean the following should compile fine ?
public class Animal{
public class Animal{ }
}
The author gives an example saying that if you have a class Multiple.java and in that class, you have:
public class Multiple{}, then it should compile.
But this does not compile. I tried it.
View Replies
View Related
Nov 3, 2014
I am having hard time to grasp the concept of java as i am beginner. according to different sources found in internet, only one class is written in one source file. and all those class can be accessed through the main class.
my question is
1.can we access one class present in one source file, through another class present in another source file [not through the class containing main method]?
2.can we create more than 1 class in same source file?is there special way to do it? i do get error always when i try to do so
3.can multiple classes contain main method? or should there be only single class containing it?
View Replies
View Related
Oct 20, 2014
I have a question about the following snippet concerning the steps the javac compiler follows to compile a program:
[...]at first, searching a class within a package is discussed if the latter doesn't contain a full package name[...]
It is a compile-time error if more than one class is found. (Classes must be unique, so the order of the import statements doesn't matter.)
The compiler goes one step further. It looks at the source files to see if the source is newer than the class file. If so, the source file is recompiled automatically. Recall that you can import only public classes from other packages. A source file can only contain one public class, and the names of the file and the public class must match. Therefore, the compiler can easily locate source files for public classes.
However, you can import nonpublic classes from the current package. These classes may be defined in source files with different names. If you import a class from the current package, the compiler searches all source files of the current package to see which one defines the class. I don't quite understand the red fragment. I wondered if the word "import" nonpublic classes from the current package weren't a synonym for the word "use", since why would we want to import a class from the same package when compiler searches the current package automatically anyway?
However I wanted to test nonpublic classes that are contained in source file which name doesn't match the class name:
NonpublicClass.java:
Java Code:
package com.work.company;
class NonpublicClass
{
public void description() {
System.out.println("Working!");
}
} mh_sh_highlight_all('java');
[Code] ....
Everything's fine when the source file names are the same as above. However, when I change NonpublicClass.java to a different name, there's an error "cannot find symbol" in:
Java Code: NonpublicClass v = new NonpublicClass(); mh_sh_highlight_all('java');
I noticed that the class file for NonpublicClass isn't even generated so that's probably the cause. If I change to the directory of the package the NonpublicClass is contained in and compile it directly, i.e. issue for example:
Java Code: javac NonpublicClass_different_name.java mh_sh_highlight_all('java');
Then a proper class file is generated with the class name, that is NonpublicClass.class, and afterwards I can compile the main program in Start.java.
So the question is what am I missing regarding the cited quote that reads:
If you import a class from the current package, the compiler searches all source files of the current package to see which one defines the class.
? Because adding such an import to CompanyClass.java:
import com.work.company.NonpublicClass;
didn't work either...
View Replies
View Related
Apr 4, 2014
I need to download multiple files from my jsp,My jsp will receive a string array,and in that each array will have a filePath.I ggot the solution to download multiple files by Using ZipOutPutStream,But i don't want to Zip Them,I need to download them in a folder.In that folder i should have all the files.
<c:set var="streamValue" value="${streamValue}"/>
<%!
void addFile( ZipOutputStream outZip, File f, String name ) {
FileInputStream in = null ;
try {
// Add ZIP entry to output stream.
outZip.putNextEntry( new ZipEntry( name ) ) ;
[code].....
View Replies
View Related
Nov 24, 2014
I am downloading around 50 PDF files programmatically using Java program(like a servlet service) one after another in for loop. I am observing that , i'm getting timeout error after few files are downloaded itself. How to solve this problem and download more files programmatically using java? The files are in my server at different location.
View Replies
View Related
Jun 17, 2014
I have multiple text files that contain several docs. my files look like this:
<doc id 1> some text </doc>
<doc id 2> some more text</doc>
...
As output I want to extract the text between the tags and then write the text into several files like 1.txt, 2.txt ......
here is my code so far:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
[Code] ....
I can not seem to get around how to print the text into several files.
View Replies
View Related
Feb 7, 2014
I'm going through a file (MySQL dump) and I wish to take the SQL and create individual files for each table (as opposed to what I do now, which is just run through the whole thing).
<code>
BufferedReader myDumpfileReader = new BufferedReader(new FileReader(tfDumpfile.getText())); BufferedWriter myDumpfileWriter = new BufferedWriter(new FileWriter("/users/linehanp/mydb/bin/tgac_dump/Vanilla.sql"));
while((dumpFileLine = myDumpfileReader.readLine()) != null){ DoStuff();
MyDumfileWriter.write("Whatever");
}
myDumpfileReader.close();myDumpfileWriter.close();
</code>
Now, this all works fine - but what I want to do is create a separate .sql file for each table.
However, I can't figure out the best way to do this - how do I create a new FileWriter (or instance of whatever class is required) as I'm going through the while loop? That or pointing the same one to different files as I go through the loop.
It can be assumed that the file may exceed RAM - I want to do it line by line rather than slurping the entire file as a string and "cheating" that way.
There appear to be many (a bewildering amount of) I/O options and I'm just unsure.
View Replies
View Related
Mar 31, 2015
I have a multi scene JavaFX FXML application [URL] ....
I have added a TextField to Scene2.fxml and Scene3.fxml files each scene has its own Controller Class with a ScreensController class that loads a HashMap with Id name, Node screen that is defined in the ScreensFramework
class (Main class)
public void addScreen(String name, Node screen) {screens.put(name, screen);}
So each time you click a Button on a screen (scene) you fire an ActionEvent and move to another screen
myController.setScreen(ScreensFramework.screen2ID);
What I would like to do if it is possible is use the value in the TextField on Sceen2 and transfer it to the TextField on Scene3. I have discovered that unless both FXML files are loaded this is so far not possible. This is a desktop application. So how do you create a variable that is GLOBAL and has a life after one class is unloaded or one FXML file is unloaded?
At this point I do not want a database to accomplish this task.I have developed in Visual Basic 6 where I would just declare a global variable that could be used through out the application.
View Replies
View Related
May 17, 2014
I am trying to compile multiple jar files into one jar file from inside a java program. I know how to do this with shell scripts but I would rather have a universal application than one that will only run on Mac, Windows, or Linux. This is my current compiler code:
if(System.getProperty() == "Mac OS X"){
Runtime.getRuntime().exec("javac -classpath jar1.jar; jar2.jar");
}
I would then continue this on for Linux and Windows, but this limits my application.
View Replies
View Related
Aug 30, 2014
I am using itext to create pdf files , i have filtered some records (preferably i can say around 90) which has the option to open pdf for individual record. Now I need to open all the pdf's of filtered records on a single click , without asking for a open dialogue box. How to go about this ??
View Replies
View Related
Mar 31, 2015
Within tomcat "webapps" directory, have lots of scanned PDF files (size in KB and MB).Using Java and JSP, I want to search for any user entered text in these scanned PDF files.The result must display the name of those PDF files which has that entered text.
View Replies
View Related
Mar 21, 2015
Lets say I have a desire to convert and entered value to Centigrade or Fahrenheit and that I have two Radio Buttons to designate the type of conversion with the Answer posted to a TextField on Scene Two from a button click event on Scene One ok Now I would like to convert the value in the TextField on Scene Two to Kelvin and reflect the value on Scene Three in a TextField by clicking a button on Scene Two
lets say I have 4 FXML files sceneONE sceneTWO and scenMain and I created 4 controllers ControllerONE and MasterController
So far I can navigate to the different scens with just the MasterController code below...
BUT because I have two FXML files I can not capture the value in the first FXML file and pass it to the second scene
This project is my attempt to adapt the FXML style code from this web site
Switching to Different Screens in JavaFX and FXML | JavaFXTutorials
Which uses this code to switch scenes
//get reference to the button's stage stage=(Stage) btnS1.getScene().getWindow();
//load up OTHER FXML document
root = FXMLLoader.load(getClass().getResource("ATTwo.fxml"));
But will not permit variable transfer due to scope of variables which reside in two different FXML files
public class MasterController implements Initializable{@FXML public Button btnS1;
@FXML public Button btnS2;
@FXML public Label lblS1;
@FXML public Label lblS2;
@FXML public TextField txfS1;
@FXML public TextField txfS2;
@FXML public AnchorPane root;
[Code] .....
View Replies
View Related
May 22, 2014
My requirement is - I need to browse the folder and select multiples and upload all the selected files at once. note that here i need to use single browse button ONLY.
View Replies
View Related
Oct 25, 2014
I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my
set("", "");
method, it only sets the last one that is called.
Example:
set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");
Only section3 would get set, and not the others.
Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.
Here's how I set the data to the file:
public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);
[code]....
And here is how a retrieve the data and set them to my arraylist/hashmap:
public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();
[code]....
View Replies
View Related
Apr 29, 2015
In the current program I am trying to read multiple text files from a folder. I keep getting the following syntax error
"Syntax error on token ";", { expected after this token".
I highlighted the line where im getting this error in red.
import java.io.*;
import java.util.*;
public class CacheData {
// Directory path here
String path = "C:myfiles*.txt";
[Code] ....
View Replies
View Related
Apr 22, 2015
How to create object for "class B" and call the "function_B" from other different class D where class D has no connection with class A? Here is my program.
public class A(){
void print(){}
}
class B{
void function_B(){}
}
class C{
void function_C(){}
}
Here, A, B, C are in the same package. But class D is in different package.
View Replies
View Related
Sep 13, 2014
Is it possible to have multiple methods in one class?And can I use the Scanner in methods other than the main method?
View Replies
View Related
Jul 29, 2014
I need to store the data of a bunch of objects of a particular class in files in a predefined directory. Later, I want to get all the files from the directory and turn them into the objects again. Ideally, I'd like to have one file per object and have the files be human-readable and editable without too much difficulty. The class used by the objects will likely be subject to change in the future, as well. To keep things simple, all the data members are either primitives, Strings, or arrays of them. What is the best library/API to use to deal with this situation? Or should I write my own classes for these operations?
I read into serialization, but I read that it doesn't deal well with classes that are frequently modified. I also found articles on Preferences, but none of the ones I saw seem to explain how to best handle reading and writing to and from multiple objects, especially when I don't know a prior all the objects that were written to disk.
View Replies
View Related
May 15, 2007
Is it possible to generate a javadoc from .class files?
View Replies
View Related
Aug 1, 2014
I want to have two threads running in my class, one will be downloading info from a website then putting the thread to sleep for a little bit, then repeating. The other will be sending information to a website then putting the thread to sleep for a little bit, then repeating. Is it possible to do this in my main class? I already have one thread using run() for downloading the info and sleeping can i make another?
View Replies
View Related