w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Does an unused import declaration eat memory, in Java?
No they don't take any memory. Imports are just used by compiler to resolve class names at compile time. Compiler changes each class name to fully qualified name. And removes the import statement. So, the import statement doesn't make it to byte code. The only issue that can come up with wildcard import is namespace conflict, i.e., when two types with the same name is defined in two different packages, then importing those packages with wildcards will cause name conflict for that type used. To see how compiler replaces the import statement, you can generate the byte code of your class using javap command. Consider the below code: import java.util.*; import java.util.regex.*; public class Test { public static void main(String[] args) { } } Just compile the above code, and

Categories : Java

Java : Exception declaration while method overidding
If the overridden method doesn't throw a checked exception, overriding method cannot throw, too. Throwing checked exceptions means nothing for compile time. You can throw any subclass of Runtime Exception without saying that this methods throws blah blah. Runtime exceptions are generally bugs and development mistakes, such as nullpointerexception and arithmeticexception. You need to check those kind of pointers/values before sending them to a method. Otherwise, the program crashes. Hovewer, you have nothing to do with checked exceptions except try/catch. They can have many causes such as connection error, file system error, operating system permissions, etc..

Categories : Java

java invalid method declaration; return type requied in init, run
error:invalid method declaration;return type requied public init() throws Exception { ^ // You are missing the return type You forgot to add the return type to the method declaration. Every Java method should specify a return type . If it doesn't return anything to the caller , make it void. In your case it returns a primitive int , so declare int as return type. Need to re factor your code a little : // return type is int as you are returning primitive int `0`. public int init() throws MalformedURLException { //... try{ this.zx(); }catch(MalformedURLException me){ // log the Exception here // me.printStackTrace(); // logger.error(... exception message ....); throw me; // in case you return 0 , in spite of the Exception // you will never

Categories : Java

What is meant by proper declaration of read resolve method in the Effective Java book?
From the javadoc of Serializable Classes that need to designate a replacement when an instance of it is read from the stream should implement this special method with the exact signature. ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException; So proper declaration means the method must have the same declaration as above. This behavior exists because Serializable serves as a marker to the JRE/JVM, which may take action(s) based on its presence. But doesn't have any abstract methods declared of its own.

Categories : Java

Import-on-demand declaration with subpackages only
I think what you are looking for is section7.4.3 A package is observable if and only if either: A compilation unit containing a declaration of the package is observable (§7.3). A subpackage of the package is observable. The packages java, java.lang, and java.io are always observable. And in 7.5.2 It is a compile-time error if the named package or type is not accessible (§6.6). So if nothing is in a package it does not exists and the bug is actually on the side of the Eclipse compiler; it's described in a very old bug report that was left in "LATER" state until eventually that state was deprecated and it was moved to WONT_FIX instead. Feel free to re-open it if you think it's worth fixing (now that the JLS is clarified in this area)

Categories : Java

best method to build table headings and data separately using same json in underscore.js?
If you preprocess your JSON data before using it for printing you can lower your number of nested _.each. You will still have to use two _.each statements to display your data. The real benefit of doing this, is that you can centralize your data processing and you decouple your data from your display by adding a level of abstraction. If your data structure change overtime, you would only have to modify the data processing part and your "view" would remain the same var headers = []; var content = []; var rows = 0; _.each(slides, function(slide){ if (rows % 2 == 0) { content.push([]) } _.each(slide.months, function(month) { if (_.isObject(month)) { _.each(month, function(value, key) { headers.push(key); content[conten

Categories : Javascript

get value separately from json object in java servlet
In your servlet, do the following in the do[Get,Post]() method JSONObject jsonObject = JSONObject.fromObject( request.getQueryString() ); String username= jsonObject.get( "username" ); String password= jsonObject.get( "password" ); String type= jsonObject.get( "type" ); You also need the remove the following line from your JS. request = JSON.parse(data);

Categories : Java

How Get Spooled File list separately from it's format - Java ( JT400 )
The existing class doesn't have a filter on printer device type, although you could add one using getUserFilter as an example. Once you have the full list of spooled files, you could split them yourself into two groups. Try String prtdevtype = splf.getStringAttribute(ATTR_PRTDEVTYPE); From this you can tell if you have a text spooled file (*SCS) or one with graphics in it (*IPDS, *AFPDS).

Categories : Java

Method and parameter declaration?
How would the button know how to send your question and comment id? What you can do is this: [continueButton addTarget:self action:@selector(continueButtonComment:) forControlEvents:UIControlEventTouchUpInside]; The parameter you then get passed to your method is the sender, i.e. the button object. To access the questionId and comment in your method, you could create properties for them and access those in your method.

Categories : IOS

Rewriting method declaration
Try this: static MethodDeclarationSyntax RewriteMethodDeclaration(MethodDeclarationSyntax method, string name) { var type = Syntax.ParseTypeName("dynamic"); var identifier = Syntax.Identifier(String.Format(" {0}", name)); var p = Syntax.Parameter( new SyntaxList<AttributeListSyntax>(), new SyntaxTokenList(), type, identifier, null); var parameters = method.ParameterList.AddParameters(p); return method.WithParameterList(parameters); }

Categories : C#

Is there a way to declare supresswarnings to the declaration of the method?
To answer your actual question, no, because the warning is being fired on the makeText invocation where the code analyzer isn't properly identifying that Preferences.getToastDuration() does in fact return one of the approved int values. Whichever tool is giving you the warning (IDEA?) is failing to look deep enough into the code. I don't think that the MagicConstant warning is standard, and I'd open a bug report for this.

Categories : Java

Objective-C Strange Method Declaration
If omitted, the type defaults to id. You can do this with the return type as well. It looks horrible in my opinion, and it's not the clearest notation - you should typically avoid using it. It's an ancient, obsolescent heritage.

Categories : Objective C

Check if a string is an objective c method declaration
To do this correctly/precisely is hard. While a method declaration doesn't look too complicated as it potentially contains any type declaration possible in C - and a common quiz question is "What does this C declaration mean?" - the syntax is actually quite involved. Compound that with, to my knowledge, there being no published BNF for Objective-C (though you might find one in the Clang source), and you've got a challenge on your hands. So you do need to write your own parser, but you can probably tackle it in a fuzzy/imprecise way - assume the input is valid and "tokenise" it fuzzily based, say, not on what you expect but on what you don't expect - so an argument type is not a C type declaration but just an parenthesised string which might contain other balanced parentheses, and you can

Categories : Objective C

Is it possible in Spring.Net to replace a C# property (using the replaced-method declaration?
....and it turns out after looking at the code via reflector that I could use something like: <object id="entityToInject" type="InstantiatedByIOC"> <replaced-method name="get_Header" replacer="replacer"/> </object>

Categories : C#

Visual Studio Snippet to Complete a Method Declaration
You can create a new snippet as an XML file, and then import it into Visual Studio using Tools->Code Snippets Manager. Here's an example of what you're looking for: <?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>method</Title> <Shortcut>method</Shortcut> <Description>Code snippet for a method</Description> <Author>Microsoft Corporation</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal>

Categories : C#

Need to understand this warning "Attributes on method implementation and its declaration must match"
Remove the NS_REQUIRES_NIL_TERMINATION from the implementation file : @implementation THAlertView - (id) initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitles:(NSString*)otherButtonTitles, ... { // Create and return an instance of THAlertView }

Categories : IOS

enum declaration in java
The enum in java is this: public enum SHAPE { LINE("LINE", 3), CIRCLE("CIRCLE", 4), TEXT("TEXT", 5); private String type; private Integer id; SHAPE(String type,Integer id){ this.type= type; this.id = id; } // Getters for type and id }

Categories : Java

Messed up with Java Declaration
You cannot put literals ('a') in the middle of identifiers. The line char 'a' = 'a'; Does not compile because there is no identifier, and you cannot assign one literal to another. Unicode is permitted, however. It is just hard to read :-)

Categories : Java

how to define a C++ method outside the declaration for a variadic templated class specialized to no parameters?
The constructor isn't a template, since it's a non-template member of a full specialisation, so it doesn't need template in its declaration: // does work foobar<>::foobar() {}

Categories : C++

Property not found on object of type error with method declaration in Objective C
Maybe because you're using the dot notation in a case where it doesn't make much sense : in useFlattenHTML method, self.flattenHTML is the same as [self flattenHTML], which doesn't exist, as you only have [self flattenHTML:someString]. On top of that, dot notation is possible, but you should keep it for fields declared as @property only

Categories : Objective C

Strange array declaration in Java
According to javac from JDK7, it's invalid syntax (error: illegal start of expression pointing at the first [[). I assume it must be an error generating that page or some such.

Categories : Java

how to convert this declaration of byte from java to c#?
In java, bytes are signed. So in C#: sbyte[] remaining = new sbyte[total- entred]; remaining[0] = unchecked((sbyte)0x80); or simpler: remaining[0] = -128; Frankly, though, it usually makes more sense to talk about byte (unsigned) than sbyte. In the java code, it is probably using signed bytes because that is what it has available to it, not because it actually wants to work with signed bytes.

Categories : C#

Hiding base class method with "using" declaration doesn't work for assignment operator
Compiler will generate a default operator= for Derived class, and this implicit Derived::operator= in turn invokes Base::operator= internally. To get rid of this, we need to disable the operator= explicitly: struct Derived : Base { private: Derived& operator = (const Derived&); // C++03 way }; struct Derived : Base { Derived& operator = (const Derived&) = delete; // C++11 way };

Categories : C++

Why does empty variable declaration of type show compile error but not for null declaration?
Because s2 is not initialized and s1 is initialized with null For Que 1: You are performing trim() Operation on null actually, so it will throw NPE (NullPointerException) as it should be. For Que 2: See §4.12.5 of the JLS for a very detailed explanation: A local variable must be explicitly given a value before it is used, by either initialization or assignment, in a way that can be verified by the compiler using the rules for definite assignment.

Categories : Java

Simple java issue: object declaration
JFrame frame1; Tells that the reference frame1 is of type JFrame . So while instantiating/assigning it checks the type.

Categories : Java

Java Coding standard: variable declaration
There should always be reasoning behind a decision. The second example is better because it is good to initialize values in the declaration. Google has a good set of standards that is applicable to many C-type languages. The example you are referring to is shown in the 'local variables' section.

Categories : Java

Using l letter in long variables declaration in java
3244444444 is interpreted as a literal integer but can't fit in a 32-bit int variable. It needs to be a literal long value, so it needs an l or L at the end: long l2 = 3244444444l; // or 3244444444L More info: Primitive Data Types, specifically Default Values and Literals sections.

Categories : Java

From Python to Java: Proper while loop declaration
public static int gcd(int a, int b) { int temp; while(b != 0) { temp = a; a = b; b = temp % b; } return a; } Java expects the condition of the while to be a boolean, not an int. The a, b = b, a%b syntax will not work in Java. You need to do the assignments individually. So you can set a = b, and then set b = a % b. I used a temp variable to hold the old value of a so that I can compute a % b (before I overwrote a with a = b).

Categories : Java

Java-Clojure interop in REPL: 'require versus 'import a Java class
Require and import have non overlaping uses: Require is only for Clojure namespaces. import is only for java classes I don't think there is a way to alias a java package at the moment, the best you can do is import it as you are doing with Solve to avoid typing the package name. You can't using import, give it a different package name.

Categories : Java

Pydev tags import as "unresolved import" but code using this import works fine.
So, what you're seeing here is their distribution model. Usually a module will have one root import that everything stems from, but that's not necessarily the case. They're providing a package with (what I assume) is many modules that don't interact with each other; or they can all stand alone. instead of importing each package individually, you could use the 'from' keyword: from ROOTFOL.PACKAGE import * which will grab everything inside that sub-module. You could e-mail the developer and ask why they deployed it this way...or you could add your own __init__.py to the root folder and, from ROOTFOL import * which will walk the tree. Good luck!

Categories : Python

System.Xml.XmlException: Unexpected XML declaration. The XML declaration must be the first
Make sure your <?xml tag is the first thing in the document (and that it doesn't have anything before that, this includes whitespace). You can have <?xml only once per document, so if you have a large chunk of XML and you have this tag repeated somewhere down the lines your document won't be valid.

Categories : C#

Python strange import behavior: import x.y works, from x import y doesn't
Works for me: danielallan@MacBook:~$mkdir myproject danielallan@MacBook:~$cd myproject/ danielallan@MacBook:myproject$mkdir lib danielallan@MacBook:myproject$cd lib danielallan@MacBook:lib$touch __init__.py danielallan@MacBook:lib$touch view.py danielallan@MacBook:lib$touch common_lib.py danielallan@MacBook:lib$cd .. In [1]: from lib import view In [2]: view Out[2]: <module 'lib.view' from 'lib/view.pyc'> What happens when you try that on your machine? Are you sitting in the wrong directory, or is your path not configured to find these files?

Categories : Python

In java, if I call, from a subclass, a superclass method that calls an overriden method, which class' method will be called?
Because the method MyPrMethod() is overridden in the subclass, the subclass implementation will be called. The actual method that gets called depends on the object on which it gets called.

Categories : Java

Copying java source file from different maven project and modifying its package declaration
maven-resources-plugin enable you to copy java source anywhere before compiling (you can initialize phases) but the problem lies in package declaration in the java file. you need to modify it also and that is not simple in maven But why you need to do so ? why you need to use the same code in two different packages ???

Categories : Maven

How to use a variable defined inside a method use outside the method in another method on the same Class in java
If you want to send a hi message after the connection is established, you should put the line in the chatConnected() callback method instead. The reason is, that you might otherwise try to send a message even if you are not connected. I don't know the Omegle API, but I assume that's the reason why you have callback methods in OmegleEventAdaptor. Furthermore, if you want to send messages outside this callback class, you should assign the session to an instance field of MainActivity: @Override public void chatConnected(OmegleSession session) { System.out.println("You are now talking to a random stranger!"); session.send("hi", true); MainActivity.this.session = session; } Then you can simply access the session object from your MainActivity, e.g. if a button is clicked.

Categories : Java

Rails Import Class Method from lib
Look at your error. undefined local variable or method 'params' for #<SortMethods:0x2224008> That means that SortMethods is trying to call params[]. Only controllers can have access to the params object. In your SortMethods class, make sure that you are not calling the params object. If you need a parameter from the web, pass it in as an argument to one of your methods. Something like this will work. class SortMethods def initialize(param) @param = param end def sort_column(table, field) puts @param end def sort_direction #some action end end Then in your controller, def index msm = SortMethods.new(params[:something]) ... end Conceptually you could pass the entire params object, but you wouldn't want that because you should only take what yo

Categories : Ruby On Rails

JSP import external Class Method
You'll have a stack trace in the logs somewhere, have a look at that one. My conjecture is that the com.myapp.Utils isn't on the classpath of your servlet container. The class should be in WEB-INF/classes or in a jar in WEB-INF/lib (usually, if you've deployed a WAR/exploded WAR). Cheers,

Categories : Java

How to run an import method on a separate thread in Android?
Here's how to create and start a thread which will not block the GUI. Thread thread; ImportRunnable importRun; public void startImport(){ importRun = new ImportRunnable(); thread = new Thread(importRun); thread.start(); } public void stopThread(){ importRun.setActive(false); thread.join(); } public class ImportRunnable implements Runnable{ boolean active; public ImportRunnable(){this.active=true;} public void run(){ doImport(); } public void setActive(boolean active){this.active=active;} void doImport(){ while(active){ //do import stuff } } } This allows you to start and stop a runnable process safely and easily.

Categories : Java

Php class declaration inside class method with same names and PSR-0 namespaces, error
I found the error! :-D The issue lied in my autoloading functions for controllers, models etc. since i didn't take care of namespaces. So when I tried to load a controller or model named the same, the spl_autoload_register function would start off by checking for controllers, and since my functions ignored the classes namespaces it would i both cases of: TapMVCApplicationUser and TapMVCDbUser find the User-controller class, stop the autoload list, and try to declare it. This all resolved when i took care of the namespaces and made sure that controllers/models only get loaded as long as they are in the correct namespace. If not the function dose nothing and the spl_autoload_register function continues down the list of autoload functions. The question was more framework specific than imag

Categories : PHP

Method parameters (void) vs no void declaration (error from compiler)
You cannot do this for Objective-C. In Objective-C, every parameter must be after : e.g. - (void)someMethod:(int)i; - (void)someMethod:(int)i withString:(NSString *)string; - (void)someMethod:(int)i :(int)i2 :(int)i3; // you can do this but is bad style and it does not make sense to make something like - (void)someMethod:(void)what_goes_here; so if you want a method without parameter: - (void)someMethod; However you can do it in C/C++ void someMethod(void); And I didn't see any benefit of declare void parameters (explicitly declare things is not always good).

Categories : Objective C



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.