|
There is execution flow. And code references.
Neither guarantees finding all code usage.
Code is loaded dynamically in java. A class is not loaded until it is referenced. The byte codes contain that information though so it can be dynamically determined. But that doesn't mean it actually runs.
Then a developer can write code that dynamically loads classes. Or they can use libraries that do that.
So normally execution flow needs to be done to determine what runs.
But, for example, what happen if there is a report that only runs on the first of the month and you use execution profiling on the 15th to find all the classes that are used. You will not find the classes used in that report.
So it is manual process...
You use profiling and attempt to execute your application. The profiled classes are the ones that are executed. Anything else isn't. Then build your jar(s) using only those and then completely test the application. If your tests are complete then it should work.
|
|
|
|
|
Instructions:
• This formative assessment consists of THREE Questions. (Answer ONLY TWO)
• The assessment is based on units 4 – 5 (Chapter 12 – 14 of the Java Programming Textbook).
• You can use either a console or Java Swing components (GUI) to answer your programming questions.
• Answer the questions outlined in the answer sheet and submit the completed sheet as a pdf.
• The code (programs) as described in the questions must be submitted as well.
• NOTE: SECTION A QUESTION 1 IS COMPULSORY.
SECTION B SELECT ONE QUESTION (QUESTION 2 OR QUESTION 3).
The assessment covers the following learning outcomes:
• Use recursion to solve mathematical problems
• Use the List interface
• Use the ArrayList class
• Use Swing components to capture and output information.
SECTION A (QUESTION 1 IS COMPULSORY)
Question 1 [25 marks]
Fun Times is a tourism company that provides adventurous itineraries around South Africa that are unique and engrossing. Fun Times co. specializes in group trips, with groups typically including 50 or more people. The company needs you to develop an application to capture trips and calculate their costs.
Use NetBeans IDE for all your programming questions. Create a class (Trip) to hold trip data for Fun Times. Your class header statement must be as follows:
}
Inside the class make sure you complete the following tasks:
1.1 Create four private variables that hold a trip number, number of guests for the trip, the price per guest, and the price for the trip. The trip number is stored as a String because the company plans to assign trip numbers such as T123. (4 marks)
1.2 Create two public setter methods that set/modify the trip number (setTripNumber()) and the number of guests (setGuests()). The setGuests() method will calculate the trip price by taking the number of guests multiplied by the price per guest every time the number of guests is set. The trip number MUST always be set as four digits (First a character followed by three numbers). If the input is otherwise the program must use a default trip number T000.
(6 marks)
1.3 Create three public getter methods that return the values in the three non-static fields. getTripNumber(), getGuests(), and getPriceForTrip(). (5 marks)
1.4 Create a constructor that accepts a trip number and number of guests as parameters. Pass these values to the setTripNumber() and setGuests() methods, respectively. (5 marks)
The constructor calculates the price charged for the trip by multiplying the number of guests by the price per guest. The price per guest is R500 for small trips (50 guests or fewer) and R550 for large trips (more than 50 guests).
Use a default constructor provided for you below that passes T000 and 0 to the two-parameter constructor.
1.5 Create a toString() method that returns the trip number, number of guests, and total price in a readable format. (5 marks)
Use a compareTo() method provided for you below that overrides the Object class compareTo() method to compare trips based on their total price.
|
|
|
|
|
OK. Did you have a question or did you expect someone to do your homework for you?
|
|
|
|
|
And you have to use NetBeans (IDE) if you do help. Can't bring your own.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Is there a way to make the difference between the server being offline, or it being busy with accepting another connection at the exact same time and not being able to accept another one, so that the client knows it wasn't a problem that the server wasn't online to try again to reach it?
|
|
|
|
|
|
Aren't those C++ errors? I was asking for Java socket.
|
|
|
|
|
Yes, but they are based on actual sockets which are the same for all languages. I could not find a definitive list for Java, you should check the Java documentation.
|
|
|
|
|
|
I tried to use that, but that exception is thrown if the server is offline but also when it didn't responded to .connect(...) in time.
|
|
|
|
|
Did the exceptions include any message text to explain what was the underlying cause? When I run my Java client against an offline server I get:
Exception in thread "main" java.net.ConnectException: Connection refused: connect
There may be some more useful information at Java Network Programming FAQ[^].
|
|
|
|
|
|
Check inetaddress.isReachable.
It is similar to ping
|
|
|
|
|
In my app I'm using JNI, and because of that I have to add into User/System Path the location to jvm.dll from JRE\bin\server . To add a variable in User Path it doesn't require administrator rights, so I'm taking this approach. To add it I'm using REG ADD from CMD with the following functions. The problem that I have is that after I'm adding the variable into Path, the software still doesn't see it and returns the error "jvm.dll not found", but if I restart the computer, then it runs fine and sees the variable. Also after I'm adding it, if I manually go into User Path and double click to edit the variable, and simply press enter without changing anything, then it doesn't require the restart. Does it have something to do with the code/way I'm adding the variable? What should I do to get past this and to get it working without the user/client having to restart the computer before it is working?
Function to run CMD:
std::string executeCMD(const char* cmd) {
std::string result;
std::array<char, 128> buffer;
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
if (!pipe) {
return "ErrorCMD";
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
Use of the function:
resultCMD.insert(0, "reg add \"HKEY_CURRENT_USER\\Environment\" /v PATH /t REG_EXPAND_SZ /d \"");
resultCMD.append("\" /f");
executeCMD(resultCMD.c_str());
resultCMD is a std::string which contains the values that were in Path and also the value that I'm adding under the following format with "C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server" being added after I use the function from above:
C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server;D:\Program Files (x86)\VMware\VMware Player\bin\;D:\Program Files\Python\Python310\Scripts\;D:\Program Files\Python\Python310\;C:\Windows\system32;C:\Windows; ...and the rest of the variables, this was as an example, after each variable they have a ;
|
|
|
|
|
I ended up switching to use RegOpenKeyExA, RegQueryValueExA, RegCreateKeyEx, RegSetValueExA to get and add the values into Path, that way I can use SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)TEXT("Environment")); to get past the need for a system restart/logout.
|
|
|
|
|
There is also the “setx” command that can help with that.
I ran into similar problems setting info into the registry directly.
|
|
|
|
|
If I'm planning to distribute some software that uses Java, can I simply add in it's folder structure jre-8u333-windows-x64.exe (or other versions, this was the latest) for those that don't have it and prompt them to install it? Or beside that I need to add a file with Oracle license and have the user tick a box that they agree? Or do I have to buy something from Oracle?
The software will be free but it contains microtransactions for profit.
|
|
|
|
|
If you're bundling Oracle software, then you go with what the Oracle license says.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
|
I'm using jdk1.8.0_333 / jre1.8.0_333. Do you know if this is a problem or not? Or I need to try to switch to a new version to be free? I'm not really going to make money from my first release, so I would like to try to keep it free.
Also I've seen that there is another source for Java: OpenJDK[^] / OpenJDK JDK 18.0.1.1 GA Release[^]. Is this one free, while the one from Oracle you need a subscription but contains some more advanced features/libraries?
|
|
|
|
|
For the definitive answer that's going to deal with money, the ONLY people you should be asking this question of is Oracle Support.
|
|
|
|
|
Because this is a issue that can lead to financial/law problems I took a look at JDK's and I found Adoptium[^]. Do you know if this is free for commercial use? I see that they have JDK and JRE. I will try to contact them as well, but for sure it will take quite a long time before they respond.
|
|
|
|
|
I don't do Java.
The only reason I know about the licensing is because of the licensing requirements at work.
|
|
|
|
|
public class student{
private int ID;
private String Name;
Student class constructor
student(int id, String name){
this.ID = id;
this.Name = name;}
public int getid(){
return this.ID;}
public String Getname(){
return this.Name;}
public void SETid(int i){
this.ID = i;}
public void sETNAme(String n){
this.Name=n;}
method to display data
public void display() {
System.out.println("Student id is: " + id + " "
+ "and Student name is: "
+ Name;);
System.out.println();
}}
|
|
|
|
|
No.
Even if you'd asked nicely, you haven't bothered to tell us what "the error" is.
Dumping your code without explanation and demanding that someone "solve the error" is a great way to alienate people, and ensure nobody wants to help you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|