Saturday, July 29, 2017

Java - Random Helpful Tips

  • Ternary Operator
This  will to reduce line number of  code . 
condition ? ifConditionTrueWhatShouldHappen : ifConditionFalseWhatShouldHappen
 This can  be use instead of ,Normal if  and  else .


  •  Substring
    •     public String substring(int startIndex) : 
   This method returns new String object containing the substring of the given string from specified     startIndex (inclusive). 

    •     public String substring(int startIndex, int endIndex):  
  This method returns new String object containing the substring of the given string from specified     startIndex   to    endIndex (exclusive).
  Index starts  from 0  .Returns index where found, or -1 if not found 
ex :-  
String text = "Here there everywhere";
int a =text.indexOf("there");   // a is 5
int b =text.indexOf("er"); // b is 1 
int c =text.indexOf("eR"); // c is -1, "eR" is not found
  •  For Checking Null
    if(foo != null && foo.bar()) {
       someStuff();
    }
    will use short-circuit evaluation, meaning it ends if the first condition of a logical AND is false.            
  •  The && and || operators "short-circuit", meaning they don't evaluate the right hand side if it isn't        necessary. The & and | operators, when used as logical operators, always evaluate both sides.


  • Variable Arguments (Varargs) in Java
     
  • There can be only one variable argument in a method.
  • Variable argument (varargs) must be the last argument.
  • ex:-
    // Java program to demonstrate varargs
    class Test1
    {
        // A method that takes variable number of intger
        // arguments.
        static void fun(int ...a)
        {
            System.out.println("Number of arguments: " + a.length);
            // using for each loop to display contents of a
            for (int i: a)
                System.out.print(i + " ");
            System.out.println();
        }
        // Driver code
        public static void main(String args[])
        {
            // Calling the varargs method with different number
            // of parameters
            fun(100);         // one parameter
            fun(1, 2, 3, 4);  // four parameters
            fun();            // no parameter
        }
    }

Friday, July 7, 2017

How to Read Out Loud ,Pdf File etc and Listen to Them Later

If  we  able  to  convert    pdf  files   that  we  have  to read  ,to  audio  files ,It  will  be  great   help  to our   studies .


You  can   use   Adobe  Reader    to  read  out  loud , pdf   files  .But  I    there  is  no direct   way  to convert  those   files  to  MP3  files to  listen  later  .










You  can   use these   steps  in  this  web  page  to use    this  useful  method   Link - Simple Ways on How to Convert PDF to MP3 without any Fuss  .



There  is  other  softwares also ,  But   most  of  them  have  to  pay  to  pay  if  we  convert  them  to  MP3 file  , Watch  this video  .  So  i  think   earlier  way  will  be help most .






Hope   this will  help  to  your   studies . Try  it .

Tuesday, May 30, 2017

How to use CMD to recover files from virus infected storage media

If    your data lost or inaccessible due to virus attacks,  you   can  use CMD (command  prompt)   to  recover  those   files . 

#  First  open  cmd .
#  Then  type        ATTRIB  -H  -R  -S   /S    /D  J:\*.*        in  cmd .   Letter  "J"  in that  should  replace  from  your  drive  name  letter .
#  Then , you  will  able  to  view  your   files  that  inaccessible  due  to  virus  attack .
#  Some  times   you  may  get   error  saying , "ATTRIB  is not  recognized as an internal or external command ........"  etc  , Then edit 
  1. Right click My Computer> Properties> Advanced System Settings  or  search   for "Environment variables"  in  find  option .
  2. In the Advanced System Settings Tab, click on Environment variables and look for Path in System variables
  3. Click Edit and add C:\Windows\System32  at the end of the already  have path  variable . MAKE SURE YOU DON'T DELETE THE REST OF THE STRING


Wednesday, May 10, 2017

Components to be created in Spring MVC application.

1.Add maven dependencies  in  porm.xml

2.Add DispatcherServlet in web.xml

3.Configure view-resolver in spring-servlet.xml

4.Create the controller with handler  mappings

5.Finally write the JSP

Monday, April 24, 2017

Data Access Object (DAO)

# The Data Access Object (DAO) support in Spring is aimed at making it easy to
  work with data access technologies like JDBC,   Hibernate, JPA (our one JPA) or JDO in a consistent way

# The best way to guarantee that your Data Access Objects (DAOs) or
  repositories provide exception translation is to use the @Repository annotation

# Any DAO or repository implementation will need to access to a persistence resource,
 depending on the persistence technology used; for example, a JDBC-based repository will
 need access to a JDBC DataSource; a JPA - based repository will need access to an EntityManager.
 The easiest way to accomplish this is to have this resource dependency injected using one of
 the @Autowired,, @Inject,@Resource or @PersistenceContext annotations.

 @Autowired
 EntityManager em;

# return em.createNativeQuery(sql).getResultList();

# Query query = em.createNativeQuery(sql);
  BigDecimal exChangeRate = (BigDecimal)query.getSingleResult();

Views - SQL

Benifits  of   Views   

A view provides several benefits.

1. Views can hide complexity

If you have a query that requires joining several tables, or has complex logic or calculations,
you can code all that logic into a view, then select from the view just like you would a table.

2. Views can be used as a security mechanism

A view can select certain columns and/or rows from a table, and permissions set on the view
instead of the underlying tables. This allows surfacing only the data that a user needs to see.

3. Views can simplify supporting legacy code

If you need to refactor a table that would break a lot of code, you can replace the table
with a view of the same name. The view provides the exact same schema as the original table,
while the actual schema has changed. This keeps the legacy code that references the table
from breaking, allowing you to change the legacy code at your leisure.


4.Among other things, it can be used for security. If you have a "customer" table, you might
want to give all of your sales people access to the name, address, zipcode, etc. fields, but
not credit_card_number. You can create a view that only includes the columns they need access
 to and then grant them access on the view.

5.A view is an encapsulation of a query. Queries that are turned into views tend to be complicated
 and as such saving them as a view for reuse can be advantageous.  Though a view doesn't store data, some refer to a views as “virtual tables,” you can query a view like you can a table .

6.Once a view is created you can used then as you would any table in a SELECT statement.

7.Views take up very little space, as the data is stored once in the source table.

Sample  view  is  shown  below .

 

CREATE OR REPLACE VIEW    SAMPLE_VIEW     AS
SELECT  cast('A' as varchar2(2)) col1,'Overdue period > 0  month and < 3 months' col2
FROM dual
UNION
SELECT cast('B' as varchar2(2)) col1,'Overdue period > 3  month and < 6 months' col2
FROM dual
UNION
SELECT cast('C' as varchar2(2))  col1,'Overdue period >= 24 months' col2
FROM dual
UNION
SELECT cast('D' as varchar2(2))  col1, 'Overdue RV > 0'  col2
FROM dual

Some interesting things to explore more

 Here  some  some  things  to  study  more ,     How Google Search works               https://developers.google.com/search/docs/fundamental...