Describe OOPs concepts in Java
The four main concepts are involved in OOP:
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
Abstraction
Abstraction is hiding of information from others. In case of Java, its hiding implementation of a method/ object. For example if an interface is available to outer world, so end user won’t know about implementing class details. This is just a kind of abstraction. Abstraction could be anywhere in java, wherever we hide some information, we call it abstraction.
Encapsulation
Encapsulation is combining data and method along with implementation hiding within the class. Implementation hiding is done with the help of access modifiers (public, protected, package, private).
Inheritance
Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality. Although inheritance may sometimes imply (especially in Java, where the keyword for inheritance is extends) that you are going to add new methods to the interface, that’s not necessarily true. The second and more important way to differentiate your new class is to change the behavior of an existing base-class method. This is referred to as overriding that method.
Polymorphism
Polymorphism is something like one name many forms. Polymorphism is also known as dynamic binding or late binding or run-time binding.
What is watchdog timer?
Watchdog timer is hardware circuitary tightly integrated into embedded systems’ CPU to have a watch on embedded system’s working. It has ability to detect if embedded system is entered into a hanged state. It then resets the embedded system so that it doesn’t remain in hanged state indefinately. Watchdog timer is generally used in embedded systems where their is no human intervention present to reset it when system hangs. As its name suggests watchdog timer is a timer circuitary which keeps on counting and expires until reset. Embedded system software is expected to restart the timer regularly to prevent it from expiring under normal conditions. When systems hangs the timer is not restarted and it expires to give an indication to the system to restart.
jQuery – A lightweight JavaScript Library
jQuery is JavaScript library that simplifies lots of work done in JavaScript. jQuery makes HTML document traverse easy. It can provide ajax support to your website. There are lots of site which provides jQuery plugins (plugin for validation, animation, cookies, events). The most important point to remember is that by using jQuery you can easily get multiple browser compatibility.
There are three downloads available
1. Minified and Gzipped (Used in production)
2. Packed version (This version is not gzipped)
3. Uncompressed (Used in testing and learning)
Reference
http://jquery.com
The Constructor Date(String) is Deprecated since of JDK 1.1 you should not use it
You should use java.text.SimpleDateFormat to convert String value to Date. E.g.
private static final SimpleDateFormat sdf = new SimpleDateFormat(”yyyy-MM-dd”); String birthDate = “1981-12-30?; Date birth = sdf.format(birthDate);
Simulating slow internet connection
One important measure of a web application is its performance. It is important to check the application performance in slow internet speed. It might be possible that an application is doing fine in high internet speed but doesn’t do well in slow connection. You need to make sure that user experience is not bad in slow internet speed. In Web 2.0, we use AJAX extensively, some time because of high internet speed, we are not able to catch some tricky bugs. For such applications slow internet connection can be good test environment.
To simulate slow internet speed, we can use Fiddler. To setup slow internet speed go to
Rules -> Performance -> Simulate Modem Speed and now capture http traffic. Your Fiddler will act like proxy for your web application and will simulate slow connection speed.

There are few points to remember
1. If you are running your application locally then use your machine name in place of localhost to access web application
2. If you shutdown Fiddler once, and start again then you again need to enable Simulate Modem Speed.
Backup of mysql database
Use the following command to get backup of complete mysql database.
shell> mysqldump -u [username] -p[password] –all-databases > [backupfile.sql] –if you want to take backup of selective database then u need to specify database name like shell> mysqldump -u [username] -p[password] –databases [databasename] > [backupfile.sql]
Syntax in above commands are explained below
username – User name of mysql database
password – Password of mysql database
databasename – Name of the database you want to take backup
backupfile – Name of the backup file
http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html
Converting Array to List
Array can be converted to List by using asList static function of Arrays class.
Integer[] integerArray = {1,2,3,4};
List<Integer> integerList = Arrays.asList(integerArray);
Arrays.asList Returns a fixed-size list backed by the specified array.
public static List asList(T... a)
recall that argument list of variable length is implemented by packing the arguments into an array and passing that. It can be understood by the following example
List<Long> a = Arrays.asList(1L,2L,3L);
// is equivalent to
List<Long> b = Arrays.asList(new Long[]{1L,2L,3L});
Creating report in java using jasper
Here is the example code for creating standalone java application to generate jasper report.
List dataList = new ArrayList();
HashMap dataMap = new HashMap();
dataMap.put("name", "ProductX");
dataMap.put("cost", 100.01);
dataList.add(dataMap);
dataMap = new HashMap();
dataMap.put("name", "ProductY");
dataMap.put("cost", 23.00);
dataList.add(dataMap);
dataMap = new HashMap();
dataMap.put("name", "ProductZ");
dataMap.put("cost", 99.89);
dataList.add(dataMap);
JasperDesign jasperDesign = getProductJasperDesign();
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JRBeanCollectionDataSource jrBeanCollectionDataSource = new JRBeanCollectionDataSource(dataList);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), jrBeanCollectionDataSource);
JasperViewer.viewReport(jasperPrint);
Click here to download example file.
Implicit conversion from data type varchar to money is not allowed
Error Message:
Implicit conversion from data type varchar to money is not allowed. Use the CONVERT function to run this query.
Solution: Convert is not going to work, use cast
CAST(“Column Name” AS VARCHAR)
Changing root user password in mysql
Changing root user password in mysql
Resetting root password on window
1. Log in to the window using admin credentials
2. Check if ur mysql server is running, if so stop it. To stop mysql server go to
Start Menu -> Control Panel -> Administrative Tools -> Services
Go to MYSQL and stop it.
3. Save the following commands in a file. lets call it mysql-password-reset.txt and save this file to c drive.
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
4.Start MYSQL using mysqld-nt with file option.
The mysqld-nt.exe process is used within the mySQL Database server application to handle SQL requests and provide general access to the database.
5. C:\Program Files\MySQL\MySQL Server 5.0\bin>mysqld-nt –init-file=C:\mysql-password-reset.txt
6. MYSQL server will start successfully.
7. Stop the server and delete the file and start the MYSQL server in normal mode.
8. To start server in normal mode go to services and start the MYSQL service.
Resetting root password on unix system
1. Stop mysql server if running.
$ /etc/init.d/mysql stop
2. Now start MYSQL using following command.
$ mysqld_safe --skip-grant-tables &
3. Now log into mysql server using
$ mysql -u root
4. You will see mysql command line. Now you can reset your new root password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
5. Stop mysql server
$ /etc/init.d/mysql stop
6. Your new password is set. You can use new passowrd to log in to mysql.
References
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html