Browsing 7239 questions and answers with Jon Skeet

FileNotFoundException when using FileOutputStream

I need to extract tar file by this code. But it' this error when I use FileOutputStream(outputFile); " java.io.FileNotFoundException: D:\TestFile\1.png (Access is...
Jon Skeet
people
quotationmark

This is the problem: Attempting to write output directory D:\TestFile\1.png You've created the target filename as a directory. You need to separate out "the directory I need to exist" and "the file I want to write to". For... more 7/7/2014 7:57:13 AM

people

Java Timestamp conversion error

Here is my problem with time stamp: in MySql data base there is a column name creation_date with data type timestamp the value in the column is 2014-07-04 17:35:07.0 when I am...
Jon Skeet
people
quotationmark

Did you read the documentation for the (deprecated) constructor you're calling? In particular: year - the year minus 1900 month - 0 to 11 I'd strongly advise you not to call that constructor to start with. If you're using Java 8,... more 7/7/2014 7:44:56 AM

people

Deserializing of Google's Translate API result in C#

I'm trying to deserialize Google's Translate API JSON response into an C# object using JavaScriptSerializer. However, it always says Type 'TranslateAPI.Models.Translations' is not...
Jon Skeet
people
quotationmark

I suspect you don't need the Translations class at all. You've got: An object containing a data property The data property value is an object containing a translations property The translations property value is an array Each element of... more 7/7/2014 7:31:41 AM

people

Getting System.Byte [] instead of ASCII value

I'm a newer programmer with C#. I am having an issue where my character frequency reading program is not displaying the ASCII values correctly. What it is supposed to do is read...
Jon Skeet
people
quotationmark

This is the problem: Convert.ToString(Encoding.ASCII.GetBytes(s)); Encoding.GetBytes(string) returns a byte[], and calling Convert.ToString() on that will just return System.Byte[]. It's not clear why you're using Encoding.ASCII at all... more 7/6/2014 9:48:54 PM

people

Dynamic dispatch and access level of a method

Consider the following classes: public class A { public void foo() { System.out.println("A.foo()"); } public void bar() { ...
Jon Skeet
people
quotationmark

If A.foo() is private, then it can't be overridden by a subclass - any other class should basically be unaware of the existence of private members. You can't override a member you can't "see". From section 8.4.8.1 of the JLS: An... more 7/6/2014 8:59:46 AM

people

primitive datatypes are atomic in java

I read that primitive datatypes like boolean, byte, short, char, int and float are atomic. 64-bit datatypes like long and double are not. But what does this mean? When I have 2...
Jon Skeet
people
quotationmark

When I have 2 Threads that increment and decrement on a int variable than sometimes i still got race conditions. Yes, you will - because even though the "get" and "set" operations on the int variable are each atomic, that doesn't mean... more 7/5/2014 7:59:15 AM

people

Singleton injected into a class does it cause memory leak?

I have a class MyClass that has a parameter of type MyThreadPool in the constructor (DI). MyThreadPool is a singleton. The code is like the following: Public Class MyClass ...
Jon Skeet
people
quotationmark

No, because the reference is from the instance of MyClass to the instance of MyThreadPool. That means that the instance of MyClass would keep the instance of MyThreadPool alive, but not the other way round. The instance of MyThreadPool... more 7/5/2014 7:09:19 AM

people

Java Singleton doesn't work

I'm setting a class via SOOT-ECLIPSE plugin as the main class and want it to operate like a singleton. But my implementation seems to not work, as I get different instances one...
Jon Skeet
people
quotationmark

(From comments...) My point is that I want to run this class and get the same instance every time. It sounds like you have a misconception about what singletons are. If you're running your app twice, i.e. $ java MyApp [output] $... more 7/4/2014 3:14:38 PM

people

Find which class created me

I have a generic component (a simple java package). I convert it into a jar and give it to my clients. My client can use this jar for any of his applications. Will it be...
Jon Skeet
people
quotationmark

That's in my component, will I be able to identify who created an instance of me? Not in general, no. You could try obtaining a stack trace in the constructor, but that's not necessarily reliable or helpful. If you want some sort of... more 7/4/2014 3:00:18 PM

people

I use interface when I create object should I set default value for parameter only in interface method?

I use interface type when I create object some class - should I set default value for parameter (=5) only in interface method as You can see below? Or maybe also set default value...
Jon Skeet
people
quotationmark

You'd need to define "best". The default value is basically only applied to whichever type you try to call against. So for example, with your current code: MyClass c = new MyClass(); c.MyMethod(); // Invalid MyInterface i = new... more 7/4/2014 12:57:25 PM

people