Print Current Time Every Second?
Nov 13, 2014
I need to write a program that prints the current time every second. Here is what I have and I am not entirely sure why I'm not.
Java Code:
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class CurrentTime
[Code] .....
View Replies
ADVERTISEMENT
Jun 2, 2014
I am trying to get the current utc date/time, but it keeps printing out in local time:
Java Code: LocalDateTime dt = LocalDateTime.now();
ZonedDateTime zdt = dt.atZone(ZoneOffset.UTC);
System.out.println("time: " + zdt);
// output:
time: 2014-06-02T13:37:55.705Z mh_sh_highlight_all('java');
13:37 is local time. Utc time is 17:37.
View Replies
View Related
Mar 18, 2014
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;
public class Swipe_In {
public String DTStart; //Swipe in Date Time
[code]....
I have got 2 questions on the above class...
1) I get an error "Cannot make a static reference to the non-static field DTStart" wherever i use DTStart in the main method....What's causing this error? and How do i fix it for good?
2) public String DTStart; Once i get the current date & time assigned to the above DTStart String in the main method i cannot use the updated value of DTStart in any other class. In another class i wanna create an instance(object) of this Swipe_In class with DTStart assigned to the current time(as in its main method)..I tried but the object's DTStart gets assigned to null.(( How do i achieve this?
View Replies
View Related
May 29, 2014
I'm working on a project for class that asks me to record punch-in and punch-out times for employees. However, I am having difficulty figuring out where I am going wrong as none of the information will write to the text file in the ArrayList that I have created. The code is as follows:
import java.text.*;
import java.util.*;
import java.io.*;
import java.nio.file.*;
public class TimeClockApp {
// declare class variables
private static EmployeeDAO employeeDAO = null;
[Code] .....
I want to keep the coding as simple as possible as I am new to Java, and have spent hours upon hours trying to figure this all out. The console output looks like this:
Welcome to the Punch-In/Punch-Out Screen
Please choose an option below:
I. Punch In
O. Punch Out
Choice: i
PUNCH IN
--------
Enter Employee ID:
8
8Punch-In Date & Time: 2014/05/28 22:44:26
[]
Press enter to return to the main screen:
View Replies
View Related
Oct 22, 2014
I want to know if I can get the entire log4j.properties file constructed in Java code. I am not talking about configuring the logger using Java code.I have a logger that is already configured using a file. I want to get access to either Logger or LogManager (any other?) class and print the current configuration that is in memory.
View Replies
View Related
Jul 14, 2014
i want to write a class in such a way that i should get the current execution time of another class which is running. I searched in net but it shows only how to calculate the time duration of the current class which is running. But as per my way, i need the execution time of one class from another class. How to do this ?
View Replies
View Related
Mar 6, 2014
How can i assign current null value to current date, I only what to assign this if the current value coming from database is null otherwise i must use value from database
public static String getDate(Calendar cal){
return "" + cal.get(Calendar.DATE) +"/" +
(cal.get(Calendar.MONTH)+1) + "/" + cal.get(Calendar.YEAR);
}
try {
[Code] .....
View Replies
View Related
Mar 17, 2015
I want to be able to use the current date to solve a math problem, specifically as follows:If today is March 17, the math problem of the day should be:
(Month times Day of Month) + 99 = Answer of the Day
(3 x 17) + 99 = 150
How can I create a java script to find the current month and the current day of month, multiple those two together, then add 99 and display the answer as a result.
View Replies
View Related
Apr 10, 2014
I am trying to write to an output file that the user names. I have flushed and closed the printwriter, so now I am at a loss. The console output works fine with the formatting, and the file is created, but I cannot get the file to populate. I have the following:
public static void main(String[] args) {
try
{
Scanner kb = new Scanner(System.in);
System.out.print("Input file: ");
String inputFileName = kb.next();
System.out.print("Output file: ");
String outputFileName = kb.next();
// Construct the Scanner and PrintWriter objects for reading and writing
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
PrintWriter out = new PrintWriter(outputFileName);
[code]....
View Replies
View Related
Oct 6, 2014
import java.util.Scanner;
public class Arraykey {
public static void main(String[] args) {
System.out.println("Enter array size: ");
Scanner input = new Scanner(System.in);
int size = input.nextInt();
int [] a = new int[size];
for(int i=0 ; i<size ; i++){
[Code] ....
View Replies
View Related
Feb 9, 2015
I am working on an assignment that I can't seem to figure out the final part to. The program takes in course data such as the time the class starts and how long it lasts. The time is in military time (0000 - 2400)
I need the output time to be the time the class started, plus the length of the class, and displayed in military time.
for example,
Start Time = 0930
Length = 50 minutes
Endtime = 1020
I can't for the life of me figure out how to do this. I have gotten a program that works for this time and minutes, and displays the correct 1020. But when I change the information to say
Start time: 0700
Length = 90 minutes
I get:
Endtime = 90
90 is technically correct, the way the formula is setup, but I need it to display 0900 not 90.
Here is the code that I have. Be easy, I'm still learning, and this is just the file I created to get the formula to work. Also, the verbose in here is just for my own debugging to make sure values should be what I'm expecting them to be.
public class calc
{
public static void main(String[] args) {
double hours, minutes, length;
double temp;
int time = 2400;
hours = time / 100;
System.out.println("Hours are: " + hours);
[Code] ....
View Replies
View Related
Jan 29, 2014
I have two classes. time_runner is used for testing my code.
This is what I'm using to test my code:
class time_runner
{
public static void main(String str[]) throws IOException {
Time time1 = new Time(14, 56);
System.out.println("time1: " + time1);
System.out.println("convert time1 to standard time: " + time1.convert());
System.out.println("time1: " + time1);
System.out.print("increment time1 five times: ");
time1.increment();
[code]....
The two constructors are "Time()", which is the default constructor that sets the time to 1200, and "Time(int h, int m)" Which says If h is between 1 and 23 inclusive, set the hour to h. Otherwise, set the hour to 0. If m is between 0 and 59 inclusive, set the minutes to m. Otherwise, set the minutes to 0. Those are my two constructors that I pretty much have down. The three methods however I'm having trouble with. The "String toString()" Returns the time as a String of length 4. The "String convert()" Returns the time as a String converted from military time to standard time. The "void increment()" Advances the time by one minute.
public class Time {
private int hour;
private int minute;
public Time(int h, int m) {
if(h > 1 && h < 23)
hour = h;
[code]....
View Replies
View Related
Jun 24, 2014
First of all, i am using ubuntu and jdk8. My problem: displaying the current path of a file in my system Approach: I have a file called dummy.txt in a given directory which have enough permissions and i did the following:
File file=new File("dummy.txt");
System.out.println(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("/")));
I expected to see displayed the current path of the file without the name of the file but it is showing a different path. I just want to display the current path of the file without the name.
View Replies
View Related
Sep 14, 2014
Following is the code on the click of a button, id like to know how do i close the current jframe on which the jButton4 is currently placed. I know how to send it to the next Jframe i.e JobCard. But need to close the current one. I tried using this.setVisible(true); But it does not work.
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
JobCard jobCard = new JobCard();
jobCard.setVisible(true);
}
View Replies
View Related
Nov 10, 2014
Basically we have to create a calculator that it will have to keep track of the current value, and do the functions that the calculator uses.
But I have it working for the most part, but the current value does not keep...
The double " currentValue " Must stay private.
import java.util.*;
public class MemoryCaluclator {
private double currentValue;
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int answer = 0;
[Code] ......
View Replies
View Related
Jun 29, 2014
Can we set the class path for one level down the current directory? My structure is like
binlibresourceshexicon.cmdinside the folder dist.
In this case I could run the .cmd file which has java -cp .;lib;resources client.Test .
c: rycpdist>java hexicon.cmdBut if i put the .cmd file inside bin as like this and run as
c: rycpdistin>java hexicon.cmdI am getting this error Error: Could not find or load main class
Is there any possibility to set the class path in this case
View Replies
View Related
Jan 5, 2014
Is there a way to measure current download speed of a file being downloaded? I've searched all over google and the only thing i get is average download speed. This is basically how it is being done, the result is average download speed.
Java Code:
OutputStream out = null;
URLConnection conn;
InputStream in = null;
long startup = System.currentTimeMillis();
try {
URL url = new URL(adress);
out = new BufferedOutputStream(
[Code] .....
View Replies
View Related
Feb 12, 2014
My primary question is about which method is the best for having an applet of mine communication with a backend database of mine. In other words, I don't want to try learning a technology that is out of date or not a good fit for my goal. I purchased the O'Reilly title "Java Servlet Programming", but it seems to be very old and out of date (referencing Netscape 4, etc.) and I see a Java RMI O'Reilly title on Amazon, but it was written in 2001.
My basic goal is to allow my applet to have access to a back-end database for reading and writing. I understand that direct Applet to DB (via JDBC) access is a bad idea so my thought is to create a servlet (much like web service for lack of a better term) or an actual web service (RESTful would be my first guess) to broker the requests. I already have a very basic servlet running that has access to my database server so now I want to focus on the best method for making calls from the applet to the servlet but having said that I don't want to go down this road too far if a servlet is not the right tool for the job.
My reading has been leading me to RMI, but as I said, I don't want to focus on that if there is a better option. In a non-Java environment, I'd use a web service (REST, SOAP, etc.) and perhaps that's what I should do here as well and not even bother with a servlet per se and just go with a web service.I know there can be some subjectivity with regard to these choices and I don't need to know what the "best" one is.I don't want to use RMI if it's dead or has been surpassed by something else, for example.
Should I use a servlet? Should I use a web service? My needs are rather modest; query the database, send updates to the database, etc. Nothing too crazy.
View Replies
View Related
Sep 30, 2014
I have now slowly moving on the learning Database Connectivity.Found a simple example on one site and tried to execute it, Creating a database, connecting to it and displaying the output.
I am getting trouble with recordset in displaying all the records in the badabase. It displays the very first record correctly but if I try to enclose it in while(rs.next()) loop, it generates an error message saying "Invalid operation at current cursor position".
package database_console;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
[code]....
View Replies
View Related
Apr 7, 2014
In weblogic deployment, I have my MQ profile defined which creates weblogic.jms.PooledConnectionFactory. I want to Inquire to get some queue statistics like Current depth and max depth. If I have MQQueueConnectionFactory/MQQueueManager, I can do this with MQQueue INQUIRE but I am not able to find a solution for this from PooledConnectionFactory.
Is there a way to convert PooledConnectionFactory to MQQueueManager/MQQueueConnectionFactory or is there any other way to INQUIRE from PooledConnectionFactory.
View Replies
View Related
Aug 29, 2014
I would like to know how much of memory is free and used my java program.I have used Runtime.totalMemory and freeMemory() functions. However, how come used memory is so different than java.exe process show in windows task manager?
View Replies
View Related
Mar 10, 2014
I want to have JTextField automatically highlighting the current values for overwriting when the box is selected. Is there a way to do this? It seems like something that might occur in an action listener.
View Replies
View Related
Oct 8, 2014
I am supposed to write a Tester to get the current volume of a balloon that starts with a radius of 0 after it is inflated.This is the balloon:
public class Balloon
{
private double savedRadius;//instance variable
/**constructor!!
Constructs a balloon with a radius
*/
}
[code]....
View Replies
View Related
Nov 23, 2014
So basically we have this question to do : Write a method dayNumber that determines the number of days in a year up to and including the current day. The method should have three int parameters: year, month, and day. If the value of any parameter is invalid, the method should print a warning message and return the value zero. The table gives some examples of the action of the method. Accept any non-negative year as being valid. You may want to assume the existence of a method numberOfDays that returns the number of days in a given month of a given year. And you should have a method call isLeapYear, if the user enter a year that is a leap year.
This is what I did so far:
class dayMonthYear {
public static void main(String[] args) {
System.out.println("Enter a year");
int year = In.getInt();
System.out.println("Enter the month for '1' to be January - '12' to be december");
[Code] ....
It works and compiles but my problem is that: let say I enter "12" for December and December has 31 days, so what my program will do since December has 31 days, it thinks each month has 31 days and add them up which will give me 372 when it's suppose to give me 365. How do I make it that it won't do that and that it will work if the year is a leap year too.
View Replies
View Related
Apr 7, 2014
I want to get current RAM usage of my computer and display it in Console View of Eclipse? How can I achieve this?
View Replies
View Related
Apr 12, 2014
Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.
The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.
company class:
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;
[Code] ....
error message when print button is clicked:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
[Code] ......
View Replies
View Related