Tampilkan postingan dengan label and. Tampilkan semua postingan
Tampilkan postingan dengan label and. Tampilkan semua postingan

Cadalyst Magazine’s All In One CAD Tip 5 and I Helped


Cadalyst Magazine has had a series of All-in-One CAD tips put together by one of my favorite CAD Guru’s Curt Moreno, the Kung Fu Drafter.

The series is sponsored by HP’s new “All-In-One” Workstation the Z1.

On Tip Five, Mr. KFD asked me to lend a hand.  I contributed the tip about using Autodesk Design Review.  I’m so proud!  Check it out and check out the other All-In-One tips from Cadalyst, KDF, and HP.




Read More..

10 Famous Laws of Computer Programming and Software Enginnering World

Like any other field, Software and Programming world too has some interesting and famous rules, principles and laws, which programmers, developers, managers and architects use often in conversations, meetings and chats. These laws are either rules, principles, or famous words from great personalities of computer programming world. At the same time these laws are interesting, funny, worth knowing, and few of them are just amazing to read. I have sharing things which is worth knowing and useful for not only Java programmer but also developers from other programming language e.g. we have seen 10 Object oriented design principles, which is not only useful for Java guys but also with any OOPS programmer. In this article, I am going to share my collection of 10 famous software and computer programming laws, I am sure you would have few more to add into this list. Please share a computer programming rules, or a thought of wisdom, which is worth knowing among software professional.
Read more »
Read More..

AutoCAD Sheet Sets for Project Management Free Webinar and Training Discount

Novedge and I will be presenting a free webinar on AutoCAD SheetsSets for Project Management tomorrow, March 20th, 2013 at 11:00 am PDT/2:00 pm EDT.  Sign up now so you don’t miss it.

The webinar is free (did I mention it is free?) and will last about one hour.  The time frame includes a question and answer session at the end of the webinar. 

Not only is the webinar free, but anyone who attends gets a coupon to get 30% off the list price of my Infinite Skills Sheet Sets training Video!  This video has over three hours of in depth training on using Sheet Sets.  The normal list price is $49.99 (U.S.D) and comes with all of the files you will need to learn how to master AutoCAD Sheet Sets.

Come on by to the webinar and get a good look at what’s on the videos.  Sheet Sets do more than help you print your drawings, find out how in this FREE webinar!
Read More..

Difference between List and Set in Java Collection

What is difference between List and Set in Java is a very popular Java collection interview questions and an important fundamental concept to remember while using Collections class in Java. Both List and Set are two of most important Collection classes Java Program use along with various Map implementation. Basic feature of List and Set are abstracted in List and Set interface in Java and then various implementation of List and Set adds specific feature on top of that e.g. ArrayList in Java is a List implementation backed by Array while LinkedList is another List implementation which works like linked list data-structure. In this Java tutorial we will see some fundamental difference between List and Set collections. Since List and Set are generified with introduction of Generics in Java5 these difference also application to List and Set.

This article is in continuation of my earlier post on Collection e.g. Difference between HashMap vs HashSet, Difference between HashMap and Hashtable and Difference between Concurrent Collection and Synchronized Collection. If you haven't read them already you may find them useful.
Read more »
Read More..

Debian 6 sluggish and slow due to Mono

I have been playing around with Debian 6 for the past two weeks and overall quite happy with Debian but have noticed a slight sluggish feel when working with Gnome. (eg compared to Fedora 14)

My Debian 6 install is a default desktop install which had a working internet connection during the installation process. As a result OpenOffice, Java, Mono, extra Gnome themes and icons were all pulled in.

It would be nice if the Debian installer allowed for a more customized Desktop setup.

To cut a long story short, I have no need for Mono and decided to erase it.

apt-get purge cli-common libmono-*

If you are a Ubuntu user reading this, please do not run this command.

Now the interesting thing after performing this action was I noticed my desktop was more snappy and responsive, and more inline with Fedora 14.

Furthermore, I have also experienced the same feel when removing mono from Ubuntu 10.04 LTS.

Mono makes Linux sluggish!
Read More..

Core Java Interview Questions and Answers String concatenation



It is a very common beginner level question on String concatenation. Its imperative to understand that NOT all String concatenations are  bad. It depends on how you are using it. You need to have the basic understanding that in Java, String is an immutable object and StringBuilder (not thread-safe) and StringBuffer (thread-safe) are mutable. In, Java you can concatenate strings a number of ways with the "+" operator, using the append( ) in StringBuilder and StringBuffer classes, and the other methods like concat( ) in String class.

Q1. Is anything wrong with the following code?

public class StringConcat {
public static String withStringBuilder(int count) {
String s = "Hello" + " " + " peter " + count;
return s;
}

}
 
A1. No, the compiler internally uses a StringBuilder to use two append( ) calls to append the string and converts it to a String object using the toString( ) method.

Note: you can try the javap command  described below to see why.


Q2. Is anything wrong with the following code?
public class StringConcat {
public static String withStringBuilder() {
String s = "Hello" + " " + " peter " + " how are you";
return s;
}

}
 
A2. No, the compiler is smart enough to work out that it is a static concatenation and it uses its optimization to concatenate the string during compile-time. If you verify this by using a Java decompiler like jd-gui.exe to decompile the compiled class back, you will get the source code as below.
 
public class StringConcat
 {
public static String withStringBuilder(int count)
{
String s = "Hello peter how are you";
return s;
}
}

You can also use the javap command to dissemble the compiled class file using the following command
 
C:workspacesprojTestsrc>javap -c StringConcat

Gives the following output
 
Compiled from "StringConcat.java"
public class StringConcat extends java.lang.Object{
public StringConcat();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return

public static java.lang.String withStringBuilder(int);
Code:
0: ldc #2; //String Hello peter how are you
2: astore_1
3: aload_1
4: areturn

}

The line 0 shows that it has been optimized


Q3. Is anything wrong with the following code snippet

public class StringConcat {

public static String withoutStringBuilder(int count) {
String str = "";
for (int i = 0; i < count; i++) {
str += i;
}

return str;
}

}
 
A3. Yes. it consumes more memory and can have performance implications. This is because, a String object in Java is immutable. This means, you cant modify a String. If the value of count is 100, then the above code will create 100 new StringBuilder objects, of which 99 of them will be discarded for garbage collection. Creating new objects unnecessarily is not efficient, and the garbage collector needs to clean up those unreferenced 99 objects. StringBuffer and StringBuilder: are mutable and use them when you want to modify the contents. StringBuilder was added in Java 5 and it is identical in all respects to StringBuffer except that it is not synchronized, which makes it slightly faster at the cost of not being thread-safe. The code below creates only two new objects, the StringBuilder and the final String that is returned.
public class StringConcat {

public static String withStringBuilder(int count) {
StringBuilder sb = new StringBuilder(100);
for (int i = 0; i < count; i++) {
sb.append(i);
}

return sb.toString();
}

}
 
Now, if you want to be more pedantic as to how we know that the 100 StringBuilder objects are created, we can use the javap option to our rescue. The javap is a class file dissembler. If you compile the codebase in the question and then run the javap command with the StringConcat.class file as shown below
C:workspacesproj_blueTestsrc>javap -c StringConcat

You will get an output as shown below
 
Compiled from "StringConcat.java"
public class StringConcat extends java.lang.Object{
public StringConcat();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return

public static java.lang.String withoutStringBuilder(int);
Code:
0: ldc #2; //String
2: astore_1
3: iconst_0
4: istore_2
5: iload_2
6: iload_0
7: if_icmpge 35
10: new #3; //class java/lang/StringBuilder
13: dup
14: invokespecial #4; //Method java/lang/StringBuilder."<init>":()V
17: aload_1
18: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
21: iload_2
22: invokevirtual #6; //Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
25: invokevirtual #7; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
28: astore_1
29: iinc 2, 1
32: goto 5
35: aload_1
36: areturn

}

The dissembled looks cryptic, but if you inspect it carefully the code within the public static java.lang.String withoutStringBuilder(int);

Line 5 to 32: is the code within the for loop. The "goto 5" indicates looping back.
Line 10: creates a new StringBuilder object every time
Line 18: uses the StringBuilders append method to concatenate the String.
Line 25: uses the toString( ) method to convert the StringBuilder back to the existing String reference via toString( ) method.

If you run the improved code snippet in the answer through javap, you get the following output
Compiled from "StringConcat.java"
public class StringConcat extends java.lang.Object{
public StringConcat();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return

public static java.lang.String withStringBuilder(int);
Code:
0: new #2; //class java/lang/StringBuilder
3: dup
4: bipush 100
6: invokespecial #3; //Method java/lang/StringBuilder."<init>":(I)V
9: astore_1
10: iconst_0
11: istore_2
12: iload_2
13: iload_0
14: if_icmpge 29
17: aload_1
18: iload_2
19: invokevirtual #4; //Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
22: pop
23: iinc 2, 1
26: goto 12
29: aload_1
30: invokevirtual #5; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
33: areturn

}

As you could see

Line 0 to 6: initializes one StringBuilder object outside the for loop.
Line 12 to 26: is the for loop.
Line 19: indicates that since the StringBuilder is mutable, the string is appended via the append method.


Important: The creation of extra strings is not limited to the overloaded mathematical operator "+", but there are several other methods like concat( ), trim( ), substring( ), and replace( ) in the String class that generate new string instances. So use StringBuffer or StringBuilder for computation intensive operations to get better performance. Experiment with javap for the String methods like concat( ), trim( ), substring( ), and replace( ) .

Note: So, javap and jd-gui.exe are handy tools for debugging your application for certain issues. For example, the java decompiler is handy for debugging generics to see how the java source code with generics is converted after compilation by decompiling the .class file back to source code.
Read More..

Core Java multi thread coding printing odd and even numbers with two threads



Q. Can you write code to print odd and even numbers by two threads in sequence?
A. Even though this is not a practical question, a handy beginner level question test your ability to write multi-threaded code.

Here are the considerations.

  • It needs to be atomic so that the numbers can be printed in sequence. You can use either the AtomicInteger class or maintain two boolean flags like oddPrinted and evenPrinted  to coordinate between the two threads.
  • Both threads need to have a lock to coordinate odd and even printing. In Java, every object has a lock. So, we can create a Object lock = new Object( ) as the lock for both threads to use.
  • The Java Object class has wait and notify/notifyAll methods to facilitate inter thread communication via the Object lock. The notify/notifyAll methods notify the waiting threads to get hold of the lock. Only one thread can execute the code snippet that is synchronized on the lock.
  • You need a main method that creates a main thread and then spawn two new threads to print odd and even numbers respectively. 
 Here is the sample code.

Step 1: The main thread class PrintOddEvenNumbersWithTwoThreads that spawns the two new threads via the thread pool.

  
package com.mycompany.app6;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
* main thread
*/
public class PrintOddEvenNumbersWithTwoThreads
{
public static void main(String[] args)
{
final int max = 10;
final AtomicInteger i = new AtomicInteger(1); //start with 0
Executor dd = Executors.newFixedThreadPool(2);

final Object lock = new Object();

//the main thread spawns two threads to print odd and even numbers respectively
dd.execute(new OddNumber(max, i, lock));
dd.execute(new EvenNumber(max, i, lock));

do
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}

while (i.get() != max + 1);

System.out.println("
Done");
System.exit(0);
}
}


Step 2: The OddNumber thread that prints odd numbers.

  
package com.mycompany.app6;

import java.util.concurrent.atomic.AtomicInteger;

public class OddNumber implements Runnable
{
private int maxNumber;
private AtomicInteger number;
private Object lock;

public OddNumber(int maxNumber, AtomicInteger number, Object lock)
{
this.maxNumber = maxNumber;
this.number = number;
this.lock = lock;
}

public void run()
{
print();
}

public void print()
{
while (number.get() < maxNumber + 1)
{
if (number.get() % 2 == 0)
{
System.out.println(Thread.currentThread().getName() + " --> " + number.getAndAdd(1));

synchronized (lock)
{
lock.notifyAll();//notify all waiting threads on this lock to resume
}
}
else
{
synchronized (lock)
{
try
{
lock.wait(); //wait for the lock
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}

}



Step 3: The EvenNumber thread that prints even numbers. The implementation is very similar except for the boundary condition that checks for odd or even number.

  
package com.mycompany.app6;

import java.util.concurrent.atomic.AtomicInteger;

public class EvenNumber implements Runnable
{
private int maxNumber;
private AtomicInteger number;
private Object lock;

public EvenNumber(int maxNumber, AtomicInteger number, Object lock)
{
this.maxNumber = maxNumber;
this.number = number;
this.lock = lock;
}

public void run()
{
print();
}

public void print()
{
while (number.get() < maxNumber + 1)
{
if (number.get() % 2 != 0)
{
System.out.println(Thread.currentThread().getName() + " --> " + number.getAndAdd(1));

synchronized (lock)
{
lock.notify(); //notify all waiting threads on this lock to resume
}
}
else
{
synchronized (lock)
{
try
{
lock.wait(); //wait for the lock
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}

}





Step 4: Run the main thread class PrintOddEvenNumbersWithTwoThreads to execute the code.

The output:

  
pool-1-thread-2 --> 1
pool-1-thread-1 --> 2
pool-1-thread-2 --> 3
pool-1-thread-1 --> 4
pool-1-thread-2 --> 5
pool-1-thread-1 --> 6
pool-1-thread-2 --> 7
pool-1-thread-1 --> 8
pool-1-thread-2 --> 9
pool-1-thread-1 --> 10

Done



There are other alternative approaches as described in the NumberGenerator class.
Read More..

Source control system and subversion aka SVN questions and answers

Q. Why do you need a source control system?
A. Source Control systems like subversion is a must if you are writing Java code by yourself or as a team. It allows multiple streams of coding, tracks the changes in your code and allows you to roll back to previous versions.  Here are the benefits of a source control system.

  • Have you ever realized that you have made a mistake and wanted to revert back to your previous revision? You also dont lose your code. You can experiment with things., and if things dont work as expected, you can revert your code.
  • Multiple streams or projects can work simultaneously on the same code base by branching the code from trunk, and then merging the code back to trunk and then tagging it prior to releasing and deploying the code.
  • Versioning helps you look at previous versions of the code to find out when and where bugs were introduced. You can compare two different versions of code side by side.
  • You can also create patches and apply patches.

Q. What are the differences between trunk, branch, and a tag in relation to a source control system like SVN?
A. There are many source control systems like Git, Clearcase, Subversion (aka SVN), etc, and SVN is a very popular open source source control system. You can use it via its command line commands or via GUI based client tools like TortosieSVN.

  • A trunk in SVN is main development area, where major development happens. Like a tree, trunk is a tree’s central superstructure. All branches come out of the trunk.
  • A branch in SVN is sub development area where parallel development on different features happens. Branches are created for adding new features/enhancements, bug fixes, and maintenance. After completion of a functionality, a branch is usually merged back into trunk. Tools like TortoiseSVN and IDE plugins for SVN simplifies the code merging task.
  • A tag in SVN is a read only copy of source code from branch or trunk at any point of time. A tag is mostly used to create a copy of released source code so that it can be rolled back.
  • A head is the latest version in the repository. That is either in the trunk or branch.

Q. What are the basic steps involved in merging? for example from a branch to trunk.
A

  • Step 1: Check out the destination stream from SVN. In this case it is the trunk.
  • Step 2: The SVN client tools like tortoiseSVN or Eclipse IDE plugin provides you with a GUI interface to select the source code to merge. In this case it is the branch. Click on the merge button to merge automatically, and where there are conflicts, you need to merge those conflicts manually. You can also use the SVN command-line option.
  • Step 3: Test the merged code locally to ensure that they compile and work as expected.
  • Step 4: Check in the merged code into the destination. In this case the trunk.

Q. What do you understand by the term rebase?
A. When developers work in parallel and commit changes to different streams of the same code base, eventually some or all of these commits have to be brought together into a shared graph, and merging and rebasing are two primary ways that let us do that.

  • Merging brings two lines of development together while preserving the ancestry of each commit history. It is like melting two different pipes  together. The pipe itself doesn’t break, it’s just combined with another pipe. So, the commit itself knows that it is a merge commit.
  • In contrast, rebasing  is like cutting off a pipe and weld it on another pipe. Rebasing unifies the lines of development by re-writing changes from the source branch so that they appear as children of the destination branch – effectively pretending that those commits were written on top of the destination branch all along.

Q. What is a sync merge and when do you perform it?
A. Say you create a new branch from a head to work some enhancements, and simultaneously some bug fixes were made on the trunk. Suppose that a month has passed since you started working on your new branch and your new feature are not finished yet, but at the same time you know that other people on your team continue to make important bug fixes on the trunk. Its in your best interest to replicate those changes to your own branch, just to make sure that they integrate well with your changes. This is done by performing a sync merge, which is a merge operation designed to bring your branch up to date with any changes made to its ancestral parent, which is the trunk in this case. The sync merge is also known as rebasing.

Q. What do you understand by the term patch or pull request?
A.A patch means change sets you want to communicate and apply to another repository. Nowadays, the GitHub pull request makes it really easy to apply patches on GitHub repos, which is useful when you arent a direct contributor. A patch is a small file that indicates what was changed in a repository. Its generally used when someone from outside your team has read-only access but had a good code change available. He then creates a patch and sends it to you. You apply it and push it to the git repository. Here is a simple example.

Create an input file named "input.txt" as shown below and check in to the repository like SVN.

  
This is line A.
This is line B.


Now modify the above code as shown below by replacing A in first line to C.

  
This is line C.
This is line B.


Now create a patch file, for example from eclipse IDE using the SVN plugin by right clicking on the file and then select Team --> Create patch. The patch file created will be

  

Index: src/test/resources/input.txt
===================================================================
--- src/test/resources/input.txt (revision 19063)
+++ src/test/resources/input.txt (working copy)
@@ -1,2 +1,2 @@
-This is line A.
+This is line C.
This is line B.
No newline at end of file


The above patch tells that

@@ -1,2 +1,2 @@ tells that in line 1 was removed and another line 1 was added and line 2 remains the same. The "-" next to "-This is line A." indicates that this line was removed. The "+" sign next to "+This is line C." indicates that this line was added. You will also get similar patch output with a Unix diff tool.

 
$ diff -u input.txt output.txt


Note: For beginners, it can be a bit overwhelming to understand version control system, and the following blog explains things visually.
Read More..

How to get current URL parameters and Hash tag using JQuery and JavaScript

While dealing with current URL, many time you want to know what is the current URL path, What are the parameters, and what is the hash tag on URL. Hash tag is pretty important, if you are implementing tab structure using HTML and JQuery. To avoid confusion, let's take an example of URL: http://javarevisited.blogspot.com/2013/01/top-5-java-programming-books-best-good.html#ixzz2PGmDFlPd, in this example ixzz2PGmDFlPd is hash tag. Now, both JavaScript and JQuery provides convenient way to retrieve current URL in form of window.location object. You can use various properties of window.location JavaScript object e.g. window.location.href to get complete URL, window.location.pathname to get current path, and window.location.hash to get hash tag from current URL. If you like to use JQuery then you can get window.location as JQuery object and retrieve relevant properties using attr() function. If you are absolutely new in JQuery, and unaware of power of one of the most popular JavaScript framework, Head First JQuery is a good starting point. Being a fan of head first book, I always approach a new technology by an Head first title, it helped to learn a lot in short time, without spending time in trivial examples. By the way, In this web tutorial, we are going to retrieve current URL and hash tag using JavaScript and JQuery.
Read more »
Read More..

JSP Interview Questions and Answers

Q. How does JSP differ from a desk top application?
A. Desktop applications (e.g. Swing) are presentation-centric, which means when you click a menu item you know which window would be displayed and how it would look. Web applications are resource-centric as opposed to being presentation-centric. Web applications should be thought of as follows: A browser should request from a server a resource (not a page) and depending on the availability of that resource and the model state, server would generate different presentation like a regular “read-only” web page or a form with input controls, or a “page-not-found” message for the requested resource. So think in terms of resources, not pages.

Servlets and JSPs are server-side presentation-tier components managed by the web container within an application server. Web applications make use of HTTP protocol, which is a stateless request-response based paradigm. JSP technology extends the Servlet technology, which means anything you can do with a Servlet you can do with a JSP as well.



Q. Did JSPs make servlets obsolete? 
A. No. JSPs did not make Servlets obsolete. Both Servlets and JSPs are complementary technologies. You can look at the JSP technology from an HTML designer’s perspective as an extension to HTML with embedded dynamic content and from a Java developer’s as an extension of the Java Servlet technology. JSP is commonly used as the presentation layer for combining HTML and Java code. While Java Servlet technology is capable of generating HTML with out.println(“….. ”) statements, where “out” is a PrintWriter. This process of embedding HTML code with escape characters in Servlets is cumbersome and hard to maintain. The JSP technology solves this by providing a level of abstraction so that the developer can use custom tags and action elements, which can speed up Web development and are easier to maintain.




Q. What is a model 0 pattern (i.e. model-less pattern) and why is it not recommended? What is a model-2  or MVC architecture?
A.

Problem: The example shown above is based on a “model 0” (i.e. embedding business logic within JSP) pattern.  The model 0 pattern is fine for a very basic JSP page as shown above.  But real web applications would have business logic, data access logic etc, which would make the above code hard to read, difficult to maintain, difficult to refactor, and untestable. It is also not recommended to embed business logic and data access logic in a JSP page since it is protocol dependent (i.e. HTTP protocol) and makes it unable to be reused elsewhere like a wireless application using a WAP protocol,  a standalone XML based messaging application etc.       

Solution:  You can refactor the processing code containing business logic and data access logic into Java classes, which adhered to certain standards. This approach provides better testability, reuse and reduced the size of the JSP pages.  This is known as the “model 1” pattern where JSPs retain the responsibility of a controller, and view renderer with display logic but delegates the business processing to java classes known as Java Beans. The Java Beans are Java classes, which adhere to following items:

  • Implement java.io.Serializable or java.io.Externalizable interface.
  • Provide a no-arguments constructor.
  • Private properties must have corresponding getXXX/setXXX methods.


The above model provides a great improvement from the model 0 or model-less pattern, but there are still some problems and limitations.

Problem:  In the model 1 architecture the JSP page is alone responsible for processing the incoming request and replying back to the user. This architecture may be suitable for simple applications, but complex applications will end up with significant amount of Java code embedded within your JSP page, especially when there is significant amount of data processing to be performed.  This is a problem not only for java developers due to design ugliness but also a problem for web designers when you have large amount of Java code in your JSP pages. In many cases, the page receiving the request is not the page, which renders the response as an HTML output because decisions need to be made based on the submitted data to determine the most appropriate page to be displayed.   This would require your pages to be redirected (i.e. sendRedirect (…)) or forwarded to each other resulting in a messy flow of control and design ugliness for the application. So, why should you use a JSP page as a controller, which is mainly designed to be used as a template?       

Solution: You can use the Model 2 architecture (MVC – Model, View, Controller architecture), which is a hybrid approach for serving dynamic content, since it combines the use of both Servlets and JSPs. It takes advantage of the predominant strengths of both technologies where a Servlet is the target for submitting a request and performing flow-control tasks and using JSPs to generate the presentation layer. As shown in the diagram below, the servlet acts as the controller and is responsible for request processing and the creation of any beans or objects used by the JSP as well as deciding, which JSP page to forward or redirect the request to  (i.e. flow control) depending on the data submitted by the user. The JSP page is responsible for retrieving any objects or beans that may have been previously created by the servlet, and as a template for rendering the view as a response to be sent to the user as an HTML.




Q. If you set a request attribute in your JSP, would you be able to access it in your subsequent request within your servlet code?
    [This question can be asked to determine if you understand the request/response paradigm]
A. The answer is no because your request goes out of scope, but if you set a request attribute in your servlet then you would be able to access it in your JSP.



Important: Servlets and JSPs are server side technologies and it is essential to understand the HTTP request/response paradigm. A common misconception is that the Java code embedded in the HTML page is transmitted to the browser with the HTML and executed in the browser. As shown in the diagram above, this is not true. A JSP is a server side component where the page is translated into a Java servlet and executed on the server. The generated servlet (from the JSP) outputs only HTML  code to the browser.  

As shown above in the diagram, if you set a request attribute in your servlet code, it can be retrieved in your JSP code, since it is still in scope. Once the response has been sent back to the user (i.e. the browser) the current request goes out of scope. When the user makes another request, a new request is created and the request attribute set by the JSP code in your previous request is not available to the new request object.  If you set a session attribute in your JSP, then it will be available in your subsequent request because it is still in scope.  You can access it by calling session.getAttribute(“JSPText”).

Note: The above questions and answers are extracted from my book entitled Java/J2EE Job Interview Companion. Only a few JSP questions and answers are shown.
Read More..

Spring Framework Tutorial How to call Stored Procedures from Java using IN and OUT parameter example

Spring Framework provides excellent support to call stored procedures from Java application. In fact there are multiple ways to call stored procedure in Spring Framework, e.g. you can use one of the query() method from JdbcTemplate to call stored procedures, or you can extend abstract class StoredProcedure to call stored procedures from Java. In this Java Spring tutorial, we will see second approach to call stored procedure. It's more object oriented, but same time requires more coding. StoredProcedure class allows you to declare IN and OUT parameters and call stored procedure using its various execute() method, which has protected access and can only be called from sub class. I personally prefer to implement StoredProcedure class as Inner class, if its tied up with one of DAO Object, e.g. in this case it nicely fit inside EmployeeDAO. Then you can provide convenient method to wrap stored procedure calls. In order to demonstrate, how to call stored procedures from spring based application, we will first create a simple stored proc using MySQL database, as shown below.
Read more »
Read More..

How to convert decimal to binary octal and hex String in Java Program

This article is about a simple java program which converts decimal number to binary, octal and hexadecimal format. When it was first came into my mind I though I would probably need to write whole code to convert decimal to various other radix or base numbers but when I looked Integer class and saw these two way of converting decimal to binary etc I was simple amazed. It’s indeed extremely easy to do this in java and you can also write this program or use at it is.

Converting decimal to binary in Java Example

convert decimal number to binary in java exampleJava  has many ways to change number system of particular number, you can convert any decimal number into either binary system, hexadecimal system or octal system by following same procedure. here is code example of converting any decimal number into binary number in Java.
      
//first way      
        //decimal to binary
        String binaryString = Integer.toBinaryString(number);
        System.out.println("decimal to binary: " + binaryString);
      
        //decimal to octal
        String octalString = Integer.toOctalString(number);
        System.out.println("decimal to octal: " + octalString);
      
        //decimal to hexadecimal
        String hexString = Integer.toHexString(number);
        System.out.println("decimal to hexadecimal: " + hexString);

      
//second way
        binaryString = Integer.toString(number,2);
        System.out.println("decimal to binary using Integer.toString: " + binaryString);
      
        //decimal to octal
        octalString = Integer.toString(number,8);
        System.out.println("decimal to octal using Integer.toString: " + octalString);
      
        //decimal to hexadecimal
        hexString = Integer.toString(number,16);
        System.out.println("decimal to hexadecimal using Integer.toString: " + hexString);


Nice and little tip to convert decimal to binary or decimal to Octal, hex. This comes very handy many times when we want to do a quick conversion.

Related Java Tutorials

Read More..

What is wscript exe and how to remove it

wscript.exe - Windows-based script host by Microsoft


What is wscript.exe?


wscript.exe is a Windows service that allows you to execute VBScript files. Normally, it is not dangerous, but if a malicious script is downloaded and executed it will appear as if wscript.exe is the culprit, when it is really a separate .vbs file. Antivirus programs usually detect C:WindowsSystem32wscript.exe as the culprit, however, its not necessarily infected. It may be that your computer is infected with Worms and Trojans that attempt to execute malicious .vbs scripts. Most users, get these malware infections from SD cards, pen drives and of course infected websites. Malicious files may change Windows registry, establish connection to remove servers controlled by cyber crooks and download additional malware modules. Other issues: cant open Regedit, certain Windows options are missing, cant acces Contol Panel. Malware may also block anti-malware and Windows system utilities. You should not delete wscript.exe manually, many Windows services require it and our computer may not function properly if it cannot be found. But you should use recommend anti-malware software to remove wscript.exe related malware from your computer.







File name: wscript.exe
Publisher: Microsoft
File Location Windows XP: C:WindowsSystem32wscript.exe
File Location Windows 7: C:WindowsSystem32wscript.exe
Startup file: SYSTEMCurrentControlSetServices Windows-based script host

Read More..

Remove PC Fix Speed and 24x7 Help Uninstall Guide

PC Fix Speed is a system optimizer, mainly Windows registry fixer/cleaner. The only reason Im writing about it is because I recently got lots of questions from my readers asking if PC Fix Speed is a virus or not? The short answer is: No. But is it truly legit and useful? Security experts and technology experts in general have differing opinions on the value of registry cleaners and system optimization applications. Honestly, Im not a fan of registry cleaners. The only one I use is CCleaner because its free and does the job pretty well. Of course, there are other great applications to choose from, for instance Registry Mechanic by PC Tools and PC TuneUp by AVG. Both are well known companies in computer and internet security market. I would call these white hats because they do not report false positives and normally give you fairly honest and technically correct scan results. There are, however, grey or blacks hats, just like rogue applications. Such registry cleaners basically claim that your computer could run a lot faster if you removed hundreds or sometimes even thousands of supposedly identified registry and system errors, unwanted files, etc. For the truth to be told, such applications display highly exaggerated scan results identifying insignificant problems or errors as quite important or even critical ones.



Its not very uncommon for Windows registry to pick up lots of unnecessary registry entries that are created when you install or remove software. They may indeed slow down your computer, this is way using a legit registry cleaner from time to time is obviously not a bad idea at all. In fact, I recommend you to use a registry cleaner every once in a while.

To see how PC Fix Speed actually works, I installed it on my test machine. A clean install of Windows XP, fully updated and without any noticeable errors. I ran a quick scan with this PC optimization software and after a few minutes I saw the results: 65 issues were found on my computer. Not bad, from what Ive read about this software on the internet I was expecting a lo more issues and errors. Since these were only minor issues I decided to continue with errors.

After a few minutes I got a pop-up notification claiming that PC Fix Speed has found 54 registry errors. Not sure what happened with 11 previously reported errors they just vanished. I guess thats a good thing :) Needles to say, such misunderstanding do not add value and trust for PC Fix Speed.



Oh and by the way, I forgot to mention that the registry cleaner came with this rather interesting application called 24x7 Help. Its icon (a woman with a headphone) appears at the top of any open window, for example Google Chrome:



Apparently, its some sort of tech support available by phone. Some people reported that the application says "Microsoft trained technicians are standing by ready to help you solve all your PC issues and more" which was quickly identified as a scam by Microsoft engineers. The current 24x7 Help application doesnt provide such information, so its remain unclear whether or not they are really Microsoft trained technicians. I have to admit its unusual and for me quite annoying. Besides, it suprising how such a small apps functionally rely on three actively running processes:
  • App24x7Help.exe
  • App24x7Hook.exe
  • App24x7Svc.exe
Clearly unnecessary stuff. Its up to you if you want to keep it or not. I would remove it.

Last, but not least, both applications PC Fix Speed (virus) and 24x7 Help are promoted via freeware and kinda misleading ads. Probably this is the reason why some people say they didnt install neither of these intentionally or knowingly. Heres one of many ads that are used to promote this registry cleaner:



It pretends to scan my computer. This immediately reminded me all those fake online malware scanners used by scammers to promote rogue antivirus software. Finally, some people just couldnt remove this software from their computers. Maybe there were some technical problems or something, but they simply couldnt. So, to remove PC Fix Speed and 24x7 Help from your computer, please follow the removal instructions below.

Have you had experience with PC Fix Speed on your computer? Post your comments and questions below.

Written by Michael Kaur, http://deletemalware.blogspot.com



PC Fix Speed and 24x7 Help removal instructions:

1. First of all, download recommended anti-malware software and run a full system scan. It will detect and remove this infection from your computer. You may then follow the manual removal instructions below to remove the leftover traces of this browser hijacker. Hopefully you wont have to do that.





2. Remove PC Fix Speed and 24x7 Help from your computer using the Add/Remove Programs control panel (Windows XP) or Uninstall a program control panel (Windows 7 and Windows 8).

Go to the Start Menu. Select Control PanelAdd/Remove Programs.
If you are using Windows Vista or Windows 7, select Control PanelUninstall a Program.



If you are using Windows 8, simply drag your mouse pointer to the right edge of the screen, select Search from the list and search for "control panel".



Or you can right-click on a bottom left hot corner (formerly known as the Start button) and select Control panel from there.



3. When the Add/Remove Programs or the Uninstall a Program screen is displayed, scroll through the list of currently installed programs and remove PC Fix Speed (current version 1.2.0.24) and 24x7 Help.



Simply select each application and click Remove. If you are using Windows Vista, Windows 7 or Windows 8, click Uninstall up near the top of that window. When youre done, please close the Control Panel screen.

If you cant remove it through Control Panel, then you will have to remove both applications manually.

  • C:Program filesPC Fix Speed
  • C:Documents and SettingsAll UsersStart menuProgramsPC Fix Speed
  • C:Program files24x7Help

Read More..

Remove Recommended for You Pop ups and Malware Uninstall Guide

Over the last few weeks, some of our readers have alerted us to the fact that they got some kind of malicious software that redirected web browsers to different 3rd party websites and displayed intrusive advertisements in the lower right hand corner of their computer screens. No joke. However, its a very common issue and sometimes its rather difficult to tell whether its caused by malware, browser helper object or just a useless web browser extension. Usually, web browser redirects are indeed caused by malware, mostly rootkits and Trojan horses, but thats not always the case. So, we decided to dig into the issue and trace the root of the problem.

Shortly after we ran a certain set of Trojans on our test machine, we found a sample (Trojan.Small.dac or Troj/RuinDl-Gen) that was responsible for the combination of the Recommended for You pop-ups and web browser redirects. The web browser redirects seem to happen at random or at least they didnt happen all the time. The Trojan horse displayed two different pop-up windows: an iPhone looking box with various advertisements and a smaller one with just random ads. It happened in Internet Explorer, Mozilla Firefox and Google Chrome. Cant blame the browser this time. Its probably a cross platform malware too. Besides, it happened on both 32-bit and 64-bit systems. Ads were not very intrusive, they didnt show up like every two or five minutes. Once you minimize the ad box, it doesnt appear until you restart your computer. Thats right, you cant close the ad box, when you click the "X" it just minimizes into a smaller box that says "Recommended for You".

An-iPhone looking ad box:



A smaller one, but still very annoying:



Recommended for You box:



Now, that we know the root of this problem (malware) we can take the appropriate actions. Running a full virus scan with anti-malware software is essential step towards solving the Recommended for You malware problem. Once the Trojan horse is gone, you need to replace Windows Host file since its partly responsible for web browser redirects and annoying pop-ups as well. Yes, the Trojan modifies Windows Hosts file making web browser inquiries a subject to redirect. To remove this malware from your computer, please follow the steps in the removal guide below. Should you need any further assistance, dont hesitate to contact us or just leave a comment below. Good luck and be safe online!

http://deletemalware.blogspot.com


Recommended for You malware removal instructions:

1. Download recommended anti-malware software (direct download) and run a full system scan to remove this malware from your computer.

3. To reset the Hosts file back to the default automatically, download and run Fix it and follow the steps in the Fix it wizard.

4. Remove files from Windows %Temp% folder.

Tell your friends:
Read More..

What is eGdpSvc exe and how to remove it

eGdpSvc.exe - System eSafe update service by eSafe Security Co., Ltd.


What is eGdpSvc.exe?


eGdpSvc.exe is a part of eSafe Security Control software. The file has a valid certificate issued to Banyan Tree Technology Limited by GlobalSign. eGdpSvc.exe runs as Windows service with extensive privileges which means that it may connect to remote servers and download additional files onto your computer in the background without your permission and knowledge. Its not essential for Windows and may cause problems. Besides, most of the time, this application is bundled with adware and potentially unwanted software. It may install adware and browser hijackers on your computer, for example Qvo6. Since egdpsvc.exe runs as a background Windows service it may slow down your computer a bit. Even though, software name looks reliable, this application is potentially unwanted. I recommend you to remove eGdpSvc.exe from your computer. You should scan your computer with recommended anti-malware software as well.







File name: eGdpSvc.exe
Publisher: eSafe Security Co., Ltd
File Location Windows XP: C:Documents and SettingsAll UsersApplication DataeSafeeGdpSvc.exe
File Location Windows 7: C:ProgramDataeSafeeGdpSvc.exe
Startup file: SYSTEMCurrentControlSetServices eSafeSvc

Read More..

Motion Blur Radial Blur and Polar Coordinates

This is a simple tutorial on using the Motion Blur, Radial Blur and Polar Coordinates together in Photoshop.
This is a free stock image.
The same image with the filters applied. It can be done in any version of Photoshop and is easy to do.
The tutorial is here
Other tutorials are here






Read More..

Remove CryptoLocker virus and restore encrypted files

CryptoLocker is a ransomware trojan that encrypts your data and then asks you to pay a ransom in order to decrypt the files. The current ransom is $300 (300EUR in Europe) by MoneyPak or Bitcoins. It does not target Macs, at least for now. At first glance, its just like any other file encrypting ransomware except that this variant is well coded and actually encrypts the files. It may encrypt files in other users account and even in mapped drives. Other ransomware trojans not always managed to do the encryption right, some even displayed fake warnings but not this one. It really encrypts, the timer is real and you have only two options: to pay the ransom hoping that cyber crooks will start the decryption or restore your files from a backup (if you are lucky enough).

This threat gets in mostly via infected email attachments and drive-by downloads from infected web sites. It is also being pushed directly to infected computers that belong to certain botnets. As usual, cyber crooks will try all possible methods to infect as many computers as possible. Only because someone said that this malware is being spread via infected email attachments doesnt mean you wont get if after visiting an infected website, etc.

An email containing the Crypto Locker virus attachment with a subject "Annual Form - Authorization to Sue Privately Owned Vehicle on State Business" that supposedly came from Xerox. [Click to enlarge image]


Heres what the CryptoLocker notifications looks like. If you got it then its already too late. Your files are encrypted. It might be slightly different in same cases but the message is the same - "Your personal files are encrypted". Theres even an option to list all the encrypted files. CryptoLocker encrypts photos, videos, word/excel documents, Zip files, PDFs and more than 60 other file types. As I said, the timer is real, usually you have 3 days to pay the ransom.


Most antivirus programs have updated their AV engines and are now detecting this ransomware trojan but they cannot recover the encrypted files. For example, Avast detects it as Win32:Ransom-AQH [Trj]. AVG - Ransomer.CEL. Avira - TR/Fraud.Gen2. Detection ration is 38/48. See CryptoLocker analysis on VirusTotal for more details.


If your antivirus program found and removed CryptoLocker from your computer, you will see the following message. Its not a pop pup but a new desktop background.


Since the decryption is impossible without CryptoLocker, cyber crooks urge you to restore it from quarantine or download a new copy of this malware.

Normally, I dont recommend paying a ransom but this piece of malware is particularly nasty. The encryption is strong, theres no way you can brute force or guess the decryption key. Usually, public RSA 2048-bit keys are stored on infected computers but not private keys, they are stored on remotes servers controlled by cyber crooks. And you cant decrypt files without your private key. So, you have to make a decision. If the encrypted files are very important to you, worth more than $300 you could take the risk and pay the ransom. Paying the ransom does not guarantee the safe recovery of encrypted files. However, multiple users have reported that paying cyber crooks to decrypt the files actually does work. It may take a long time to decryp, up to 48 hours or even more. If you plan on paying the ransom, please be careful as you type the code because entering an incorrect payment code will decrease the amount of time you have available to decrypt your files. If everything goes smoothly, decryption will start:


If the payment information is incorrect or the Command and Control servers are down, you may get an error, similar to this one:


Personally, I think that paying the ransom is not a good idea at all because cyber crooks will almost certainly fund the creation of a new variant, probably even more sophisticated than the current one. On the other hand, I understand companies and users that have very important files and they cant afford to lose them. They simply do not have other options.

If the encrypted files are not very important or you dont have money to pay the ransom, you can remove this malware and restore your files (at least some of them) using Shadow Explorer. You could restore encrypted files one by one using System restore built-in features but with Shadow Explorer you can restore entire folders at once which is really great. Besides, this tool is free. To remove CryptoLocker and restore encrypted files, please follow the removal guide below. If theres anything you think I should add or correct, please let me know.

Written by Michael Kaur, http://deletemalware.blogspot.com


Step 1: Removing CryptoLocker and related malware:

Before restoring your files from shadow copies, make sure CryptoLocker is not running. You have to remove this malware permanently. Thankfully, there are a couple of anti-malware programs that will effectively detect and remove this malware from your computer.

1. First of all, download and install recommended anti-malware scanner. Run a full system scan and remove detected malware.





2. Then, download ESET Online Scanner and run a second scan to make sure there are no other malware running on your computer.

 Thats it! Your computer should be clean now and you can safely restore your files. Proceed to Step 2.

--------------

If you cant use anti-malware programs, you will have to remove CryptoLocker manually.

1. Download Process Explorer. CryptoLocker spawns two processes of itself. Its very difficult to end those processes using Task Manager, so you will have to use Process Explorer instead.

2. Open Process Explorer. Find CryptoLockers processes. This malware uses a randomly-generated name, yours will be different.



IMPORTANT! Please copy the location of the executable file it points to into Notepad or otherwise note it. Crypto Locker saves itself to the root of the %AppData% path.

Windows XP: C:Documents and Settings[Current User]Application Data

Windows Vista/7/8: C:Users[Current User]AppDataRoaming

3. Right click on the first process and select Kill Process Tree. This will terminate both at the same time.



4. Remove the malicous file. Use the file location you saved into Notepad or otherwise noted in step in previous step. The file is hidden, so make sure that you can see hidden and operating system protected files in Windows. For more in formation, please read Show Hidden Files and Folders in Windows.

In my case, it was C:Documents and Settings[Current User]Application DataKlonpmmpdidlznt.exe



5. Go to start, and type regedit into Start search; this will open the registry editing tool (Registry Editor).

6. From the top, click on Edit, and scroll to Find (Ctrl+F). Type in the file name you noted earlier, and click Find next.



7. This should bring a result Cryptolocker; right click on the entry, and delete it.

HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun 

In the righthand pane select the registry key named CryptoLocher. Right click on this registry key and choose Delete.



HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRunOnce

In the righthand pane select the registry key named *CryptoLocher. Right click on this registry key and choose Delete.



8. Press F3 to carry on the search, deleting each time. Do this until it has finished searching the registry, and then close down the editor. Thats it!


Step 2: Restoring files encrypted by CryptoLocker using Shadow Volume Copies:

1. Download and install Shadow Explorer. Note, this tool is available with Windows XP Service Pack 2, Windows Vista, Windows 7, and Windows 8.

2. Open Shadow Explorer. From the drop down list you can select from one of the available point-in-time Shadow Copies. Select drive and the latest date that you wish to restore from.



3. Righ-click any encrypted file or entire folder and Export it. You will then be prompted as to where you would like to restore the contents of the folder to.



Hopefully, this will help you to restore all encrypted files or at least some of them.

The list of files to decrypt is maintained in the registry in:

HKEY_CURRENT_USERSoftwareCryptoLockerFiles

Read More..