w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Good practices - Use of LiquiBase packages
I know this is old, answering for anyone who comes across it in the future. No, the checksums are pretty ingrained in how Liquibase works, runOnChange is the correct way to do this. The problem is your should be more granular with your changelogs. Remember: changelogs can include other changelogs. if we add a new changeSet for each sprint, pointing to the file in packages folder, for example with runOnchange, this will execute all the changeSet that are pointing to these file because the content is diferent, and is runOnchange (is not what i want). But is the only way to know the changes in the sprint, and have track of this. Your project structure is good, you just need to take it a step farther. Make the actual changelogs to install the package/function/trigger/etc a part

Categories : Oracle

Best practices of protecting published web app packages (MVC 4)
Once you package up your files and give them to a customer, what happens to these files is out of your control. Just about anything you can do could be reverse engineered, decompiled or unencrypted. Your best bet is to protect your assets legally by producing a robust license agreement between your company and your customers. You can then make your customers aware in the terms and conditions that any reproduction or modification of your work is illegal, you can then later pursue them legally for damages. Other than that, obfuscating your code and compiling your views would help a bit.

Categories : Asp Net Mvc

Javadoc @author tag good practices
You can have more than one @author tag. In case you make some big changes to a class, just add a new @author tag with your own name in it. There's no need to mark the changes you've done or to put your name around the changes, as the revision history should be able to display that clearly.

Categories : Java

Good Coding Practices: When to Create New Functions
This is a wonderful question, and the answer is: It depends. Personally I would create a function for increased code readability, but If you are looking for efficiency maybe you would want to leave the code copied and pasted.

Categories : Function

What are the good implementation practices to minimize RAM consumption
Be careful about scope of objects. Make sure you are handling the memory deallocation after an object is no longer needed. I'm not sure I understand your use functions as much as possible(?). Functions require overhead, every call causes a little bit of extra memory to be taken up because it has to store a few pointers and a little bit of information about the method on the call stack. So, while that may help keep your source code clean - it won't lower your memory usage (it'll probably increase it). One way to get the best of both worlds in C is to use inline functions - which suggests to the compiler that it should not create an actual function, but rather just insert that block of code wherever it is used. Keep in mind that efficient code usually has a more machine level look to it (mea

Categories : C

Good programming etiquette/ good programming practices
Val is a left over Legacy function. I would recommend switching to type specific converters. This also provides protection for values that are not convertible like letters. Remember to convert types. Turn Option Strict On and you will see. Integer.TryParse Dim result As integer = 0 Dim numberA, numberB as Integer If Integer.TryParse(TextBoxNumbA.Text, numberA) Then If Integer.TryParse(TextBoxNumbB.Text, numberB) Then result = numberA + numberB End If End If TextBoxResult.Text = result.ToString("n2")

Categories : Vb.Net

Which are good practices for writing/organizing JBehave stories?
Generally, if the user can tell the difference then the automation should be able to do the same. Use your automation tool to look for something that will show you which context you're in. For instance, if you have two screens, one for "Contacts" and one for "Employee Data", look for that text and you'll know which screen you're on. Alternatively you could look at the URL, or include a specific, hidden identifier that the automation tool will find. This is similar to the "IsPurchased()" step here (I'm using a DSL rather than JBehave, and it's C#, but the principle is the same). If you actually look at the code for that step, you'll see that I look for a payment type, and if there isn't a valid one selected, then I select one. In your case, your context is a bit bigger than a radio butto

Categories : Java

Static public constant ActionScript 3 good practices
const A constant is constant. That means it does not change, because it is constant. The idea behind a constant is that you can be assured its value does not change during runtime. If you try to assign a new value to a constant, you will get an error like this: 1049: Illegal assignment to a variable specified as constant. In your example, RADIUS is not re-calculated. In fact, that behaviour doesn't occur when you access any variable - unless you are accessing it via a getter that needs to calculate the result before returning it. An example of this might be a getter that returns the distance between two points. In your final example, you are assigning a Point to a constant. This behaves a little differently than you might expect. What you cannot do is go ahead and assign a new Poin

Categories : Actionscript

Trouble creating list objects with a loop, and looking for good structure practices
I'm getting a null reference where I add the card to the list. CardHand is not declared within that method, so wherever you do it, you are apparently not initializing it. So somewhere, you should have the following: CardHand = new List<Card>(); Then before the loop within generateBattleCards you should clear that list to make sure that you don’t keep previous cards: CardHand.Clear(); In general, I would separate the random card generation from where you are creating the player’s hand. This would allow you to draw cards separately (which might be useful to your game). Furthermore, you should also separete the game logic (drawing cards etc.) from the visual logic (which icon to show where). E.g. just let the Forms controller access the player’s cards and leave it

Categories : C#

Need a way to access the public members of an anonymous Java class (or some good alternative)
i am not sure why you want to do that, but annonymous class is a differnt class that extends the Class that declares with new keyword. like Template T1 = new Template(){ public final String NAME = "My Name"; }; the new class that is created is not Template but a class that extends Template. that extended class has Name variable not in Template class and T1 can only see its variable or its parent variable but doesnt not or cannot have information about its child.

Categories : Java

Cannot resolve R.java, duplicate class
Unfortunately I run into this as well, sometimes frequently, mostly happens when I put my computer to sleep and back on while Eclipse is on. Sometimes recompiling and validating the project works. I did find this solution online somewhere, lost the link and do not claim credits for this: Disable auto build, and clean the project then Right click your project -> properties -> Java Build Path -> Source -> Add Folder -> add gen and src Then compile If that doesn't work, try to delete the gen folder and do that process Let me know.

Categories : Android

How do I avoid duplicate DLL conflicts with native NuGet packages?
The root cause of the problem appears to be that the projects that failed to load had an AppContainerApplication property setting in their project file, and did not have a WindowsAppContainer property setting. I removed the AppContainerSetting property by manually editing the project XML file. Then I Enabled the Windows Store App Support on the General properties page, Set the Consume Windows Runtime Extension option to Yes (/ZW) on the C/C++ All Options page, and Set the Enable Minimal Rebuild to No (/Gm-), also on the C/C++ All Options page. It is not clear how the project was loading prior to adding the NuGet package, but updating the settings seems to have fixed the issue.

Categories : C++

Java - Duplicate methods in classes and how to call them from another class
It depends on what each method does. By the name, getPrefs() looks like setting preferences of some sort. In that case, what I personally do, is create a class Configuration and make a singleton instance that all classes share. Android is slightly different from the usual Java. In 'usual' Java, you instantiate the objects, have a reference to them and then you call methods on them. In Android, most of your methods are defined in Activity, Fragment, DialogFragment , etc. and you are not in control of instantiating them. The methods defined whitin those can only be called within themselves unless declared static. So, go over your design, see what the methods do and check if you can make a different class out of them :) Hope it helps.

Categories : Java

java.lang.IllegalArgumentException: duplicate key: class javax.faces.convert.DoubleConverter
The webapp's runtime classpath covers more than only /WEB-INF/lib. It also covers among others server's own /lib folder and, if any, the "common" and "shared" libraries which are server-specific and configurable in server end. It also covers the JRE's /lib and /lib/ext folder. Usually, those folders are not to be touched by developers, for sure not by starters. Apparently you've somehow a copy of RichFaces JAR in one of those places. At least, the fact that you keep getting this exception while having a proper /WEB-INF/lib confirms this. To figure the exact local disk file system paths covered by the runtime classpath, run just for debug this piece of code in your webapp, e.g. in constructor of a test backing bean: System.out.println("The current runtime classpath covers the following p

Categories : JSF

Java - Collection of abstract class, children contain disparate objects - Any "good" way to handle these wrapped objects?
You discarded in your question the "good" way of doing it. Generics will not help in this case. Yes, you are going to be cursed to a nasty place for the ugly use of type checking. You can disguise the type checking using a common instance member called, say, category and its corresponding accessor getCategory defined in MyClass. And them do a switch if you can (instead of multiple ifs) on getCategory(). However, the people who will condemn you could dislike ifs and switches no matter if they are checking for types or not. And they could also be smart and understand what you are trying to do. Anything but for(MyClass e: collection ) e.doYourAction(); is "bad". Now, for software that seems to have no specification at all, you could be pardoned.

Categories : Java

Organizing class... best practices?
You should create a StatDetails object: class FootballPlayer { public FootballPlay() { CareerStats = new StatDetails(); SeasonStats = new StatDetails(); CurrentStats = new StatDetails(); } public string Name { get; set; } public string TeamName { get; set; } public StatDetails CareerStats { get; set; } public StatDetails SeasonStats { get; set; } public StatDetails CurrentStats { get; set; } } class StatDetails { public int Goals { get; set; } public int Assists { get; set; } public int Passes { get; set; } } In this way, you only have to implement INotifyPropertyChanged on two classes.

Categories : C#

Maven compilation fails when class becomes inner class (although Eclipse is good)?
Do you have an inner class inside your inner class? You may have encountered a compiler bug: http://bugs.sun.com/view_bug.do?bug_id=6707323 The fact that moving your import statement from the top of the class fixed the problem is suggestive of this bug.

Categories : Java

Best practices for making a 2D array/collection class
There are any number of options, but it will depend in part on what the actual implementation of your 2D collection is. If you just want a 2D array then there is a special syntax for that. This is a 2D string array: string[,] twoDimStringArray = new string[4,5]; Another option is to have a list of lists: List<List<string>> listOfListOfString = new List<List<string>>(); You could have a jagged array: string[][] arrayOfArraysOfString = new string[5][]; Generally speaking I would discourage you from having a class that extends another collection type. It's generally best to encapsulate another type of collection. If your class is itself exposed as a collection then use the various interfaces that are appropriate, such as IEnumerable, ICollection, IList, IS

Categories : C#

java: Preventing malicious change or modification on some public functions in java packages
You can sign your code to prevent someone from changing it and giving it to someone else pretending it is the "official" version. You cannot prevent anyone from making changes to code they are running themselves. If they break the program that way, that is their fault. If they can break your system that way (such as gain unauthorized access to other people's files), then this is a design flaw in your system. You cannot depend on client software not being modified. Code that must not be tampered with needs to run on your machines and be accessible as a service. Practical example: Instead of checking a password and then granting access to a local file or not (which can be circumvented by changing that code), encrypt the file with the password (so that there is no way to access it if you d

Categories : Java

PHP Best Practices for querying a group of class objects with summarized data
There are a number of tasks to be done and, yes, some of them are specific to each class. Especially when it comes to knowing which columns there are and how to treat them. But on the other hand there is the abstract logic of 'grouping something' and of building search patterns (and this includes of course also a range of date handling functions). These two can/should be placed in separate objects/functions which can be called from both classes, orders and invoices. A similar thing goes for putting together the result arrays. Here we need to be able to adapt to all sorts of different grouping conditions. The column names are class specific but the general logic can be put in separate classes or functions.

Categories : PHP

Java - Best practices - How to copy many files in bulk?
Use Thread Pool: You can use Thread Pool in which you will run a fixed no. of threads to copy files. Each thread will be copying a different file. As soon as one thread finished with copying; next thread will come to the pool to continue copying of next file. In this way performance will not degrade and you will be able to copy multiple files concurrently.

Categories : Java

two packages in one jar file have the same class
If this is a compile time error then you just need to fully qualify the class type, and spell out the type in full length. This way the compiler will no which one you want to use, and you won't have to guess either. You may need to adjust project dependencies too, hopefully that will yield a correct classpath and you won't have to poke around manually. Furthermore, use the one what your project depends on. I guess it's not Maven if it's a really old project.

Categories : Misc

execute class files with packages?
If the class is in a package called Pack then you'd do java Pack.ClassFile Have you copied the compiled code around at all, moving it from one directory to another? If you have, it's important to maintain the directory structure that it was originally compiled into. If I was writing some code in a package and compiling and running it, these are the steps I'd take. Assume we've cd'd to a clean directory first. mkdir Pack vi Pack/ClassFile.java javac Pack/ClassFile.java java Pack.ClassFile

Categories : Java

Java Q based on Packages
The classpath is explicitely passed to the java command, so it supersedes the CLASSPATH environment variable. Answers B, D, E and F are thus incorrect. A is incorrect since the class name is games.Chess. Since the package and the directory structures must match, the Chess.class file must be in a games folder (inside or outside a jar file). C is correct. G is incorrect because you can't pass *.jar to a classpath. And even if Games.jar was explicitely in the classpath, the manifest doesn't play any role here. See http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html for the documentation about the classpath.

Categories : Java

python packages -- overriding built-in packages and the dreaded "Module xxxx was already imported" warning
Rename myprogramxlrd to myprogramfrozen_xlrd. Then import it with try: import xlrd except ImportError: import frozen_xlrd as xlrd Alternatively, you could tell Python to silently ignore this particular UserWarning: import warnings warnings.filterwarnings("ignore", message="Module xlrd was already imported", category=UserWarning) Place this early on in the program, before scikits gets imported.

Categories : Python

What replaces Java's sun.security packages?
As of now there are no direct replacment packages from Oracle. If you don't have any plan to run your code in any non sun/oracle jvm this is not an issue. These warnings are meant for highlighting code portability issues with other JVM implementations. If you want to run the code in other JVM you should use the equivalant libraries provided by that JVM. I am not sure about what you meant regarding portability , AFAIK (haven't tested, read it somewhere )sun.security is available in jdk1.7 , not sure about availability in upcoming releases.

Categories : Security

Can a Java Factory class be structured to instantiate either Java 6 or Java 7 specific class based on JVM version?
You can do this without having to worry about the versions. You can even build the "Java 7" to run on Java 6, but won't work because it needs classes which are not there. i.e. you can have one JAR which runs in Java 6 for them all. Also you don't need to use reflection.

Categories : Java

What is the typical convention for importing Java packages?
It's not so much a memory issue, but rather that you run the risk of inadvertently importing the wrong class if you use the * notation. Generally it's not a problem, but if the * matches a class that you meant to pull in from another package it's a hard bug to find. I've seen IDE's use the rule that specific class imports are replaced by a single '*' import statement if you're importing three or more classes from that package. I prefer to call out each imported class by name.

Categories : Java

java security restrict access to jar or packages
following method on above code solves my problem.... @Override public void checkPackageAccess(String pkg) { super.checkPackageAccess(pkg); System.out.println("checkPackageAccess.." + pkg); if (!accessOK()) { if (pkg.startsWith("my.specialpackage.path")) { throw new SecurityException("No access to " + pkg); } } }

Categories : Java

Is the use of a class to "enumerate objects" in C# a good practice?
Yes it is reliable it even has a name. It is the "Singleton pattern". You just create a set of singletons and set them as read only properties of your class. It is used all over the framework.

Categories : C#

Drawbridging client, shared an server packages in Java
As Java bytecode references to classes by their fully qualified names it should be quite feasible (but not easy), using a library like BCEL or ASM. However, I think this question has a pretty distinctive X-Y ring to it, meaning that you're trying to solve a problem that is actually a symptom of the root cause you should be solving, in this case probably by properly compartmentalizing your code just as Brian Roach already suggested.

Categories : Java

Is it a good practice not to use Message field of an Exception class in C#?
If you need custom information to be part of the exception, it's generally advisable to create your own exception class where you'll create separate properties to structure the information. For your example, the relevant exception constructor could look like this: public CustomException(string message, string customInfo) : base(message) { CustomInfo = customInfo; } The customInfo parameter would populate a read-only property in the class: public string CustomInfo { get; private set; } Use it like this: throw new CustomException("My message", "My Custom Info."); Note also that the article you linked mentions that the exception message is not a good place to store structured information, because that will force clients to parse it to obtain relevant bits, since you'd have to form

Categories : C#

Is using clone() -Node class method- good for performance?
Hard to say without real data, how about benchmarking it? But it only worth the work if you have a performance problem – don't do premature optimization! But if you do a benchmark in Dart, you should read this guide. The internal of the Dart VM make real benchmarking with correct results difficult. Your code won't get optimized until it's hot (has run some times). Running the VM in checked mode makes a difference, too!

Categories : Dart

What is a good class design for node-connection situation?
Your language seems to be C++. Your solution 1. has the following problems: class Connection seems to "aggregate" the Nodes. It should rather be an association in OOspeak (a pointer to a Node to make it understandable to mere mortals) a Connection object has absolutely no reason to exist, unless it connects 2 Nodes. So the function of ConnectTwoNodes belongs in a constructor. In other words rename it to Connection. In your second solution it also seems that a Node contains the other Nodes. But in reality they exist independently. Again, you need associations, or pointers to other Nodes. I actually prefer the 1. approach. Or a non-OO solution with a matrix, with "from" Nodes on one axle and "to" Nodes on the other. It also allows you to handle cases when it's possible to get from New Y

Categories : Algorithm

Is writing into class resources a good way to save files?
Your three observations in #2 above are valid reasons not to store settings in a resource file, regardless of the APIs provided. There are a variety of ways to save settings in Java, including: The Java system property "user.home" provides the user's home directory, to which the user should have write access. You can create an application-specific subdirectory underneath it. Java provides a Preferences API. This may store settings in a directory or (on Windows) in the registry. OSGI provides a preferences API. If you're using the Eclipse RCP, you can write to the configuration directory using a ConfigurationScope. See the Eclipse FAQ "What is a preference scope").

Categories : Java

Is it a good approach to override methods in a class which you don't want to test?
I would say overriding methods is something you should avoid in general since it most likely violates the Liskov substitution principle. Test code is no special: it should follow the same strict principles as production code. The only exception I can think of is if you are testing legacy code with high coupling between components and overriding is the only option. But when writing new code I don't see any reason. I think @samlewis is on to something: if you feel you want to test parent() in isolation for some reason, then child_1() and child_2() should probably be in own classes that are injected into parent(). Avoid testing anything smaller than a class. If you need to test something smaller you probably have a responsibility that wants to be extracted (Single responsibility principle).

Categories : Java

What Java classes/packages are safe to whitelist in a security sandbox?
I suspect you'll discover that instead of starting with a general-purpose programming language and figuring out how to give people access to that and make it safe, it's safer going the other way. My approach would be to start with a domain-specific language and give it access to a sandbox - the aspects of your program's environment which you're willing and happy to have modders affect.

Categories : Java

java desktop and android application at the same time - shared packages
I would use the 3-project approach. As you have already said, make a seperate project for the core. (API) That way you can also create unit test for the core only and your setup will still look clean. What you should add to the 'core' project is an ant file or something similar to generate a jar file from the project, thus making it possible to import your core into the other projects. Another advantage is that any library used in the core, will only have to be imported there, as the import of the core will use those.

Categories : Java

Is there a way in Force.com Apex code to "import packages / namespaces" as in java/cpp ?
I think this is a hidden detail in APEX. I've extended classes and referenced system methods without ever having to worry about it. It might work to think of Salesforce managing one big import list that it adds to all of your code. When you declare a class as global it gets added to your global import list. At least this line in the documentation hints in that direction, "The global access modifier declares that this class is known by all Apex code everywhere." Regarding namespaces, I've only seen this made available as part of managed packages. So for instance, SteelBrick's managed package QuoteQuickly has the prefix SBQQ on all of it's code. More about that here. I don't believe you can namespace in any other way. There are some really sharp peeps over at salesforce.stackexchange.com

Categories : Misc

Eclipse Java: using existing source-code as different packages (due to visibility)
This is not possible in Java. I like to see packages in Java as a kind of module. So package visible members/classes offer functionality, which is only needed inside the module, but too big to be put into a single class (where it would be private). Letting B or C access package visible elements would break the encapsulation of module A (unfortunately packages in Java are more of a naming convention, not an intrinsic module mechanic). So you want to let B and C interact with the public interface of module A. What you want to achieve is in my understanding, to restrict who can use the interface of module A - this is not possible in Java. In fact all the visibility levels in Java do not offer protection from "unauthorized" use. Package visibility can be broken by defining the accessing class

Categories : Java



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