Java

99K

Solutions

33K

Contributors

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi everyone, I'm creating an android app that allows people to register via FacebookAccountKit.

Facebook account kit gives me a Token when the user has been verified (via SMS).

I can't understand how I can secure registration and user data with the token.

I'll explain :

At the moment, when I need to get user data from the database and show it on the app, I use a hidden field to send the user ID to the PHP file to filter the data.

Many have told me that it is not recommended, they told me to send a Token to the PHP file and then get the user id.

I can't understand a few things:

1) The Token must be associated with the user's ID address, could I save them in the same table or could I do it in another way?

2) When the Token expires what happens? I have to log in the user again and save the new Token on the MySql table.
   But to do this I will have to specify that it will be saved in the line where the user ID is the same as the user ID and then send the user ID from the app again.

3) To log in, I request the phone number and the user ID, I will have to send them from the app to the PHP file that checks whether the user exists or not, but so I return to the initial problem, ie send the user's id and the phone number from the app to the PHP file.

Someone could clarify my confusion about this.

Do you recommend a more valid alternative for securing my users' data?

If you …
0
Fundamentals of JavaScript
LVL 13
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

I am doing a bit of Java learning and exercises.

I've built a helper class that can retrieve Json from an URL:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;

import org.json.JSONException;
import org.json.JSONObject;

public final class JsonReader {

    private static String readAll(Reader rd) throws IOException {
        StringBuilder sb = new StringBuilder();
        int cp;
        while ((cp = rd.read()) != -1) {
            sb.append((char) cp);
        }
        return sb.toString();
    }

    public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
        InputStream is = new URL(url).openStream();
        try {
            BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
            String jsonText = readAll(rd);
            JSONObject json = new JSONObject(jsonText);
            return json;
        } finally {
            is.close();
        }
    }


    /**
     * Create a private constructor because no one should ever create a {@link JsonReader} object.
     * This class is only meant to hold static variables and methods, which can be accessed
     * directly from the class name JsonReader (and an object instance of JsonReader is not needed).
     */
    private JsonReader(){

    }

}

Open in new window


When I try to use this class from another class:
public class LinearSearch {

    public static void main(String args[]){
        System.out.println("Starting");
        JsonReader.readJsonFromUrl("https://raw.githubusercontent.com/mwgg/Airports/master/airports.json");
    }

}

Open in new window


Here I immediately get this error:
Error:(5, 35) java: unreported exception java.io.IOException; must be caught or declared to be thrown

Strange thing is that, as you see, the IOException is implemented in the JsonReader class.

What am I missing?

Thanks for your time and patience.
0
Java compile error for the statement : if ((mMonth == 4 && mDay == 18)) || ((mMonth == 12 && mDay == 31))  {

Any idea ?


Saving.java:69: error: illegal start of expression
                if ((mMonth == 4 && mDay == 18)) || ((mMonth == 12 && mDay == 31))  {
                                                 ^
Saving.java:69: error: ';' expected
                if ((mMonth == 4 && mDay == 18)) || ((mMonth == 12 && mDay == 31))  {
                                                                                  ^
2 errors
The above Java expression return error. I want to check End of Jun or End of Dec. Any idea ?

Thx
0
Hi
If I make my game server in Java, with TCP/IP HELO, START and in-game messages, game runs in browser, javascript to my server,
what can I expect as the worst from the unavoidable hackers and miscreants? Floods..
DSS attacks. Are they detectable? Stoppable? Google suggested they are stoppable. I will be using a Godaddy professional private server.
Floods will be a certainty if my game escalates. It would  suck, because there will be prizes in contention.
Do Blizzard and Microsoft weed these out? Is this how the old disconnect-hacks worked?

Thanks
0
I get compile error when compiling Bank class. However, I have no idea how to fix it. Any advice ?  Thx

C:\Temp>javac Bank.java
Bank.java:21: error: non-static method setSaving(Saving) cannot be referenced from a static context
                                Customer.setSaving(savingAC);
                                        ^
Note: Bank.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
MyWork.zip
0
Hi Experts,

sample xml of type string
 String xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"+
            "<Tutorial id=\"1\"><technology>Dot net, Java, Big data, Database</technology>\n"+
            "<address>topjavatutorial.com</address></Tutorial>";
 

Open in new window


i want to pass this  xmlStr to  rest-api webservice to conusme it.

request method -post,
acceptable -contente type is -->application/xml

i am having doubt do i need to convert this xmlStr  to XML or i can pass this xmlStr  directly
if possible please provide sample.

Thanks
0
Q1:
Does  JDK 1.6, JRE 6 & J2EE 1.6 have the same End of Support date (ie beyond
which there's no further patch/support fr Oracle)?

Q2:
I'm looking at JDK 1.8, JRE 8, J2EE 1.8 : what's their End of support date

Q3:
& do they (the 3 items above) simply have a common EoL/EoSL date as Java 8?    

Q4:
So the products that are bundled with above Java items (eg: Weblogic & JBoss)
will have their EoL/EoSL the same as  the versions of bundled Java or usually
they're different & we can update/upgrade the Java components separately?
0
Hi
i) Many of you know that I am working on getting my phone game IDE setup working. I have my first potentially very good ideas to play with/test.
I received excellent advice to make the game in Java first to know exactly what I'm trying to do, so I'm ready. It's working in a Javax JFrame. (thanks a lot - got my mind right)
I have been studying Javascript, some iOS, a look at some c# pages, Xcode pages..

ii) I am not getting it done as quickly as I hoped..I have so many questions every minute, u know how it goes..
Do you think it could be a plan to ask a Freelancer to completely help set me up, maybe over the phone? Ability to make games on any, every device, browser? I prefer back and forth banter, not sporadic articles. too much waiting. I need some first downs.
How many languages, SDK's and devices are there to accommodate me in this situation, have to learn? What did the agar.io or slither.io dudes do? Javascript!? How did they cover everything, all devices!? iPhones need special features. What else?  J2ME is a bust, so I need a new angle. The agar.io dudes made an iPhone app! Also Android App? Windows phone?

iii) I have access to one of Godaddy's private professional servers. - got major repeat customer credits for an appealing price for 10 years in. I hope it will serve the potential max players well. non VPN (can be clogged) Can I expect this to serve my players as well as agar.io and slither.io  do?

Freelancer a plan?
Thanks
0
I have been running Ubuntu 14 with custom tcp tuning parameters for a couple years.  I applied, via puppet, all of the same tuning parameters, but on Ubuntu 18, my TCP Time Wait is very high.  What is the best method of finding the source of this high TCP Time Wait?  The process that is using the tcp connections is a java application.

Please let me know any other information I should provide.

Graph on the left is Ubuntu 18.04, right is Ubuntu 14.04

Thank you,

Reade
tcp-time-wait.png
0
Hi
I'm surprised this JFrame didn't work, an I wonder why. It doesn't draw any blue. What might I have done wrong?

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.*;


public class Merrywin extends Thread{
	
	JFrame jFrame;

	public Merrywin() {
		
		
		
		start();
	}
		
		

		
		
		
	

	public void run() {

		System.out.println("Hi");
		jFrame = new JFrame();   
		jFrame.setBounds(10, 0, 1125, 2436);  
		jFrame.setVisible(true);
		
		Graphics G = jFrame.getGraphics();
		G.setColor(Color.BLUE);
		G.fillRect(0, 0, 1000, 2000);
			
				

	}
		
		
	public static void main(String[] args) {
		System.out.println("Maine");

			Merrywin m = new Merrywin();

	}

}

Open in new window

0
Exploring ASP.NET Core: Fundamentals
LVL 13
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Hi

I read that J2ME can do Java code for phone apps and other thingies, like PDA's.
This is very good news. Is it as good, speed, efficiency as desktop?
But, it also can't use Eclipse Juno. - must be Indigo - is that a step backwards?
That is annoying. Must I really uninstall Juno to get Indigo up on MacBook? Does that mean just simply deleting the .app file in my applications folder? and then installing Indigo?
I'll lose all my project settings?

Thanks
0
Hi
If I am going to focus on phone / io games, I'd like to know about security issues like hacking, which is unavoidable w online games. I created a successful Authoritative Java RTS server. It could not be hacked. Slither.io has all game data local..  Are people messing around with slither, etc?

Surely, if they start my game from an io site - or on my business hosting private server, it is my official client code. - it is not their hack. Now they can hack my game variables, but can they simply make a map hack? Must I still have an authoritative server? I read that some games are just clients - update each other on all activity, no in-game server, just clients.

Is hacking something I ned to be vigilant about, yet?

Will it ever be?
Thanks
0
Dear Experts,
I have installed Java 1.8 in a Red Hat OS Server at separate location(/data/inout/crm) from root folder. (Root folder is at an older version of Java 1.7 and is not very useful)
Now I need to import a TLS cert in the Java Keystore to this location (/data/inout/crm).
I know the command to be used is :
 keytool -importkeystore -deststorepass [password] -destkeystore [filename-new-keystore.jks] -srckeystore [filename-new-PKCS-12.p12] -srcstoretype PKCS12

Open in new window



How do I make sure that it is imported to Java 1.8 and not to Java 1.7  in the root

Thank You
Flex
0
HI,
I am getting the following error during SFTP connection -
Screenshot-2019-04-06-at-7.09.28-PM.pngwhat could be the reason for that
I am using the
 <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.54</version>
        </dependency>

dependency in my java code
Thanks
0
Hi,
I am a java developer
What are the coding practices you use to minimize the number of bugs.
I recently was working on a small project. Time was less due to deadline.
Although i logically coded many things..
And there were several functions to be written.
It was frustrating to check each and every function and test cases were also of many different categories...
So i tested some functions and skipped some. And this had me having a feeling of uncertainity when the time was near for final deployment.
As a coder should i test each and every testcase ? or at least category of testcases ?
or initially strive to make a running code that approaches the final one ?

Some coding practices that i have learn are
1) start writing the code in pseudocode format to ease the process
2) Good naming
3) Defensive coding -- Somehow also making sure they way you are thinking is the way it will turn out.
4) Started testing my code separately in small small blocks

Somethings that delayed my work are small things like -
1) I was getting some error and i figured out it was because i was using java 10. so i switched to java 8. But this happened long back. And i didnt bother to fix it permannetly..and again i got this error because what i did was just doing an export statement.
so ended up again searching for the reason for this error.
2) Any part of code that is less understood or less tested seems to be causing bugs.

Any ideas about good coding practices ways to avoid …
0
Hi,
I want to set the java version at terminal permanently to java 8.
Currently by default it is set to java 10.
I always have to do export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

How do i avoid this everytime ?

Thanks
0
Hi,
I accidentally truncated a table in postgresql on staging environment. It had lot of data.
I needed it for testing. Although a small amount of data would also suffice.
But the online portal which generates the data is also down.
So i am kind of stuck.
how do i test. what approaches do you suggest to resolve this or to avoid such things to happen or some alternative plan.
Is it possible to recover table data in postgresql ?

Thanks
0
Can I use a bookmarklet to increase the vertical size of this text box?
What would that bookmarklet be? (i.e. the code please)

nb: I believe the marked info will be unique for this control

<textarea name="nsql_text" id="d332765e57" rows="30" cols="100" aria-required="true" class="ppm_field ppm_code_field" wrap="OFF">
....
</textarea>
0
Hi,
I have an s3 url which is of the image in jpg format. I have the following code :
        BufferedImage image = ImageIO.read(new URL(url));
I need to calculate the sizeof this image.
How do i do that.
I tried the following :
 public static Integer getSize(BufferedImage bufferedImage) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "jpg", byteArrayOutputStream);
    byteArrayOutputStream.close();
    return byteArrayOutputStream.size();
  }

Open in new window

It gave 18183 bytes for an image of 14Kb which is wrong.

Mainly i need to detect if the size of the image is more than 1 MB.

Please suggest any ways to do it in java or any alternatives to achieve this ?

Thanks
0
CompTIA Security+
LVL 13
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

HI,
This question is about calling a method from inside a constructor. As i have read many places that one should not do this as the class is not created. I saw a similar code here :
@EagerSingleton
public class SftpUploaderCron {
  private final SpectraLogger logger = OlympusSpectra.getLogger(SftpUploaderCron.class);
  private final ZetaHostMessagingService zhms;
  private final TaskScheduler taskScheduler;
  private SftpDocsUploadHandler sftpDocsUploadHandler;
  private ImmutableMap<String, Long> nameIFIMapping;
  private ScheduledFuture scheduledFuture;


  @Inject
  public SftpUploaderCron(ZetaHostMessagingService zetaHostMessagingService,
                          SftpDocsUploadHandler sftpDocsUploadHandler,
                          @Named("nameIFIMapping") ImmutableMap<String, Long> nameIFIMapping) {
    logger.info("Inside SftpUploaderCron constructor").log();
    this.taskScheduler = new ThreadPoolTaskScheduler();
    ((ThreadPoolTaskScheduler)taskScheduler).initialize();
    this.zhms = zetaHostMessagingService;
    this.sftpDocsUploadHandler = sftpDocsUploadHandler;
    this.nameIFIMapping = nameIFIMapping;
    startSftpUploaderThread();
  }


  private void startSftpUpload() {
    logger.info("Inside startSftpUpload").log();
    if (scheduledFuture != null)
      scheduledFuture.cancel(true);
    long period = 30 * 60 * 1000l;
    Trigger trigger = new PeriodicTrigger(period);
    scheduledFuture = taskScheduler.schedule(this::scheduledKycUploadTask, 

Open in new window

0
Hi,
I used the @PostConstruct annotaion on a method. But my application is using Google Guice.
For constructor i am using the @Inject annotation.
The method annotated with @PostConstruct is not getting called.
Probably because the classes are handled by Google Guice and so this annotation is not of Google Guice..
Is there any alternative to it ?

Thanks
0
Hi,
How to reduce the size of a BufferedImage object in java.
I have constructed a bufferedImage merged from some images like this :
 public static BufferedImage mergeImages(List<PreSignedUrlResponse> preSignedUrlResponseList) {
    List<BufferedImage> imageList = new ArrayList<>();
    int width = 0;
    int maxHeight = 0;
    for (PreSignedUrlResponse preSignedUrlResponse : preSignedUrlResponseList) {
      try {
        BufferedImage image = ImageIO.read(new URL(preSignedUrlResponse.getPreSignedUrl()));
        imageList.add(image);
        width += image.getWidth();
        maxHeight = Math.max(image.getHeight(), maxHeight);
      } catch (Exception e) {

      }
    }
    BufferedImage merged = new BufferedImage(width, maxHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = (Graphics2D) merged.getGraphics();
    int currenWidth = 0;
    for (BufferedImage bufferedImage : imageList) {
      graphics2D.drawImage(bufferedImage, currenWidth, 0, null);
      currenWidth += bufferedImage.getWidth();
    }
    return merged;
  }

Open in new window


And i am creating an inputstream like this to upload it to an sftp server .:

private InputStream getInputStream(BufferedImage mergedImage) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
      ImageIO.write(mergedImage, "jpg", byteArrayOutputStream);
      byteArrayOutputStream.flush();
    } catch (IOException e) {
      return null;
    }
    InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    return inputStream;
  }

Open in new window


The server only accepts the image of size less than 1MB so if the image size if more than 1 MB than i need to do some image compression etc.

Please suggest what are the possibilities and things i can do ?

Thanks
0
Some web apps update status messages when a process is running.
Other web apps require me to press F5 or refresh the browser using one of the icons at the top of the screen.

Question:   Can these two types of status updates or app messages be classified (i.e. apps programmed in ______ require you to press F5 to receive an updated status message, however, apps programmed in _____  refresh messages on their own and do not require you to press F5.
0
I have a problem passing a class to another class in java.  Doesn't show an error message.  So I am not sure what's going on.  The file I am inquiring about is called TestJasoncallingMethod.txt.  This is a two part question.  after I create the JSON file I would to like to use it in Java class filling a pdf file.
testJasoncallingMethod.txt
0
Hi

I'm about to install Atom IDE for Javascript.
It seems to be the one everyone on YT is using?
Can I expect any conflicts/ issues with Eclipse and my Java projects? or anything I should know?

Thanks
0

Java

99K

Solutions

33K

Contributors

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.