Thursday, June 22, 2017

Basic Java Interview questions.



What is the difference between a constructor and a method?

A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself. It has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.


What is the purpose of garbage collection in  Java, and when is it used?

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused.
A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.


What is an abstract class?

Abstract class must be extended/subclassed (to be useful). It served as a template. A class that is abstract may not be instantiated(you may not call its constructor), abstract class may contain static data.
Any class with abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.


What is the difference between an Interface and an abstract class?

An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract.
An Interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected etc.), but has some abstract methods.


What are Checked and UnChecked Exception?

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown.
Example: IOException thrown by java.io.FileInputStream’s read() method.
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn’t force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown.
Example: StringIndexOutOfBoundsException thrown by String’s charAt() method. Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.



Sunday, June 18, 2017

How to enable debugging in JSP in eclipse ? Or Can't setup debugging in Eclipse !





How to enable debugging in JSP in eclipse ? Or Can't setup debugging in Eclipse !

Go to Eclipse marketplace in eclipse and install JavaEE Developers tools.




After this, go to project properties and add the project which you want to debug and which is having the JSP's.




 Click Add and select the Project as shown below.



That's it, you can debug your application and start debugging you JSP file.






Thursday, June 15, 2017

How to download file by using shell script (sh) ? How to use wget in shell sctipt to download a file ?



How to download file by using shell script (sh) ? How to use wget in shell sctipt to download a file ?


-----------------------------------------download_file.sh---------------------------------
#!/bin/sh

# directory path where you want to download the file
DIR=/data/test

# wget output file with this name
FILE="test_$(date +'%Y%m%d').xml"

# wget  file download url
URL="http"//www.xyz.com...... "

cd $DIR

#wgt syntax to download file

wget  $URL -O  $FILE



Saturday, June 3, 2017

Warning: mysql_connect(): No such file or directory in /Library/WebServer/Documents/





Warning: mysql_connect(): No such file or directory in /Library/WebServer/Documents/<YOUR_FILE_NAME.php>


You might need to change below files in you Mac OS.

If this file exist in your machine /tmp/mysql.sock but not /var/mysql/mysql.sock then do the perform below steps:

cd /var 
sudo mkdir mysql
sudo chmod 755 mysql
cd mysql
sudo ln -s /tmp/mysql.sock mysql.sock


But if  /var/mysql/mysql.sock exist in your machine but not  /tmp/mysql.sock this file, then do the below steps :...

cd /tmp
ln -s /var/mysql/mysql.sock mysql.sock



Good Luck !!!
Like, comment and share the knowledge....!!!

Fixing yum command on linux

You may find yourself having to fix more packages. So you can just remove everything you had installed via  pip and reinstall everythin...