Problem: During Selenium Automation testing, I tried to run my code script on the Mozilla Firefox browser and my code was not able to find the path of installed software/browser.
Solution:
I used the below code snippet to set the path.
System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");
Problem : I compiled below code and got possible loss of precision error.
int a = Math.pow(3, 5);
System.out.println(a);
Solution : According to the java documentation, Math.pow() expects two doubles, and returns a double. When you pass two int values to this method, it converts an int to double. But when we assign the value to an int, it gives, possible loss of precision error while compiling the code. So you can cast method to an int or assign the returning value to double to resolve the error.
int a = (int)Math.pow (3,5);
or
double a = Math.pow (3,5);
This is a procedure which has one out parameter of SYS_REFCURSOR type.
PROCEDURE p_get_data(query_result OUT SYS_REFCURSOR);
In java for working out with this procedure you need to import ojdbc14.jar and need to set registerOutParameter type as OracleTypes.CURSOR
import oracle.jdbc.driver.OracleTypes;
CallableStatement callStmt = connection.prepareCall("{call p_get_data(?)}");
callStmt.registerOutParameter(1, OracleTypes.CURSOR);
callStmt.execute();
ResultSet resultSet = (ResultSet) callStmt.getObject(1);
if(resultSet.next()) {
//Your Code here
}
java.util.Date : The class Date represents a specific instant in time, with millisecond precision.
Code :
java.util.Date dtUtil = new java.util.Date();
System.out.println(dtUtil);
Output :
Mon Mar 28 21:35:05 IST 2016
java.sql.Date : A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.
To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
long java.util.Date.getTime() :
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by Date object.
Code : Convert java.util.Date to java.sql.Date
java.sql.Date dtSql = new java.sql.Date(dtUtil.getTime());
System.out.println(dtSql);
Output :
2016-03-28
java.sql.Timestamp : A thin wrapper around java.util.Date that allows the JDBC API to identify this as an SQL TIMESTAMP value. It adds the ability to hold the SQL TIMESTAMP fractional seconds value, by allowing the specification of fractional seconds to a precision of nanoseconds.
Code :
java.sql.Timestamp dtTime = new java.sql.Timestamp(dtUtil.getTime());
System.out.println(dtTime);
Output :
2016-03-28 21:35:05.181
java.text.SimpleDateFormat : SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date ? text), parsing (text ? date), and normalization.
Code :
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String dt = sdf.format(dtTime);
System.out.println(dt);
Output :
28-03-2016 21:35:05
Follow the below given image to edit java directory path in Eclipse IDE
Eclipse IDE > Windows > Preferences > Installed JREs > Edit JRE > Direcctory > Browse For Folder > OK > FINISH > OK
Problem : The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path.
Faced this error while using maven integration with eclipse.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
First found this error on the start of JSP page with one red mark over above piece of code.
Solution : Below, I have written three solution for this problem. I guess, one will work for you.
Method 1: Add Maven dependency(pom.xml)
Include servlet-api-3.1.jar in your dependencies.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Method 2: Add a Runtimes
Properties > Project Facets > Runtimes > Check Server name > Apply > OK (As shown in Image)
Method 3: Select a Runtime to add to the classpath
Java Build Path > Libraries > Add Library > Server Runtime > Next (As shown in Image)
then select a Runtime(Apache Tomcat Server) > Finish > OK (As shown in Image)
Problem : JAVA_HOME is set to an invalid directory. please set the java_home variable in your environment variable to match the location of your java installation.
Solution :
Computer > Properties > Advanced System Settings > System Properties > Advanced > Environment Variables
In System Variables :
Variable Name : JAVA_HOME
Variable Value : C:\Program Files\Java\jdk1.8.0_45 (Set your JDK)
In System Variable:
Variable Name : path or PATH
Variable Value : [already there+];%JAVA_HOME%\bin
If You are getting still this error then:
To Set JAVA_HOME : go to Command Prompt and Execute following command
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_45
Restart your IDE and Command Prompt then install mvn again.
Please Comment Thanks to us if this topic is helpful :)
It can be that java 1.7 is not installed in your system then you can use java version that is already installed in your system.Following Steps could resolve this error by setting up current version in project facet
1: Right Click over your Project on Project Explorer and click on Properties.
2: Goto java build path->Libraries
Check JRE System Library Jars and also check it is JDK 1.6 or 1.7
3: Goto Project Facet and select your current java version available.
click apply then ok
Please Comment Thanks to us if this topic is helpful :)
Disclaimer
We shall not be liable for the improper or incomplete transmission of the information contained in this communication nor for any delay in its response or damage to your system. We do not guarantee that the integrity or security of this communication has been maintained or that this communication is free of viruses, interceptions or interferences. Anyone communicating with us by email accepts the risks involved and their consequences. We accept no liability for any damage caused by any virus transmitted by this site.