Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, June 25, 2015

Shortcut of RAD

Here's my list of shortcut when using RAD / Eclipse..
You can change it in the preferences.


#ShortcutsDescription
Searching / Auto-completion
1Ctrl+fSimple a find function
2Ctrl+kFind next
3Ctrl+Shift+kFind previous
4Ctrl+lGo to line x in the java file
5Ctrl+oList all methods in the java file
6F3Show source for a method or a class
7Ctrl+shift+rList of resource with your initial
8Ctrl+spaceContent assist
9Ctrl + /Single line comment by //
10Ctrl + Shift + /Multiple line comments by //
Debugging (in debug mode)
11Ctrl+bBuild All
12F6Step into
13F8Step over
Formatting / Save
14Ctrl+Shift+fCode formatting
15Ctrl+Shift+oOrganize Imports
16Ctrl+shift+sSave All

Friday, March 21, 2014

Resolved: java.lang.OutOfMemoryError: Java Heap space

When opening a large heap file, the following error occurs.
java.lang.OutOfMemoryError: Java Heap space
at com.ibm.jinwoo.heap.HeapInfo.readHAX(HeapInfo.java: 8319)
...



Solution
It would be resolved by increasing the memory for the Heap Analyzer by the following command.

java -Xmx1024m - jar ha454.jar

if it is not enough, you can try to adjust to -Xmx2048m or -Xmx4096m

Saturday, June 29, 2013

Java compiler level does not match the version of the installed Java project facet.

Created a dynamic web project and set GlassFish 4.0 as the testing server.  The following error occured:

Java compiler level does not match the version of the installed Java project facet.


Solution:
1. Right click and choose Quick Fix
2. Change Java compiler level to 1.7

3. Done!

Sunday, January 13, 2013

How to disable Java in Chrome Browser (Security)



U.S. warns on Java software as security concerns escalate
Extracted from Reuters
(Reuters) - The U.S. Department of Homeland Security urged computer users to disable Oracle Corp's Java software, amplifying security experts' prior warnings to hundreds of millions of consumers and businesses that use it to surf the Web.
http://www.reuters.com/article/2013/01/11/us-java-security-idUSBRE90A0S320130111


How to disable Java Plugin in Chrome


1. Open the chrome browser, and type chrome://plugins/ in the URL


2. Search Java in the list


3. Click Disable

Wednesday, July 4, 2012

Eclipse Development Platform Setup



The following tutorial shows how to setup the development environment for Java Application
You have to install the following software in your machine.
- JAVA SDK
- Eclipse
Steps by steps1. Download and Install the latest version of the Java SDK. 


2. Download Eclipse, either IDE for Java Developer or Java EE Developer is okay.

3. Unzip the eclipse, Open it with selecting a workspace

4. Done


java.lang.UnsupportedClassVersionError: Bad version number in .class file


This is due to the incorrect Java Version for the complication & execution.

Resolution:
Download the correct Java Version for the complication.

HTTP Status 500 -


type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Bad version number in .class file
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:272)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.UnsupportedClassVersionError: Bad version number in .class file
 java.lang.ClassLoader.defineClass1(Native Method)
 java.lang.ClassLoader.defineClass(ClassLoader.java:620)
 java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
 org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1812)
 org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:866)
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1319)
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
 org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1325)
 org.apache.jasper.compiler.Parser.parseElements(Parser.java:1573)
 org.apache.jasper.compiler.Parser.parse(Parser.java:126)
 org.apache.jasper.compiler.ParserController.doParse(ParserController.java:211)
 org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
 org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:155)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
 org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.

Wednesday, June 27, 2012

Useful API converting PDF to image

1. Download the tool PDFBox (e.g. pdfbox-app-1.7.0.jar) via the following URL:


2. Include the library in your java program. The following source code is attached for your reference.



package com.test;

import java.awt.Toolkit;
import java.awt.image.BufferedImage;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFImageWriter;

public class PDFBoxPreviewTest {

       /**
        * @param args
        */
       public static void main(String[] args) {
              try {
                     String path = "D:\\temp\\a.pdf";
                     PDFBoxPreviewTest t = new PDFBoxPreviewTest();
                     t.getDocument(path);
              } catch (Exception e) {

                     System.out.println(e.getMessage());
              }
       }

       private PDDocument getDocument(String path) throws Exception {
              PDDocument document = null;

              document = PDDocument.load(path);

              PDFImageWriter writer = new PDFImageWriter();
              boolean success = writer.writeImage(document, "jpg", "", 1, 1,
                           "myFileName", BufferedImage.TYPE_INT_RGB, Toolkit
                                         .getDefaultToolkit().getScreenResolution());
              System.out.println(success);

              return document;
       }
}

3. myFileName.jpg will be generated!


Source Code can be found here:
http://test-pdfbox.googlecode.com/svn/trunk/

Thursday, April 12, 2012

[Resolved] Download CSV with UTF-8 handling

System generates garbage characters or question marks ??? when exporting a CSV file with Chinese character, Japanese Character..



It is okay to view the Chinese / Japanese character in notepad, but cannot be shown correctly in Excel.
It is because Excel does not handle the unicode well.


Solution
It can be solved by adding addition header (BOM, Byte order Mask) to the downloaded CSV file.

response.setContentType("application/vnd.ms-excel:UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=myOutputFile.csv");

// Excel does not recongize the UTF-8, add additional header (BOM) for excel
OutputStream outputStream = response.getOutputStream();
outputStream.write(0xEF);  
outputStream.write(0xBB);
outputStream.write(0xBF);  


BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));

// Your method that generate the CSV content
writeSth(writer);

writer.flush();
writer.close();

Tuesday, March 13, 2012

Code Snippnet: Converting java.util.Date to java.sql.Date


 java.util.Date today = new java.util.Date();
long t = today.getTime();
java.sql.Date dt = new java.sql.Date(t);

Monday, February 20, 2012

Install Decompiler in Eclipse Indgio

This article will show you how to install a Java Decompiler to Eclipse.. We will use JadClipse in this example. 

  JadClipse
Maintainer:Vladimir Grishchenko, Johann Gyger
Platform:Platform independent
Genre:Java, Decompiler, Eclipse plug-in
License:CPL
Languages:English, Russian
Website:JadClipse.sf.net
 
1. Download JAD

http://www.softpedia.com/progDownload/JAD-Download-85911.html

2. Download JADEclipse in sourceforge


http://sourceforge.net/projects/jadclipse/

3. Put the JAR to Eclipse Plugin Folder
For example: D:\eclipse_indigo\plugins\net.sf.jadclipse_3.3.0.jar


4. Start and Configure Eclipse for the JAD Plugin
In Eclipse, Click Window –> Preference –> Java –> Jadclipse
For example: 
Path to decompiler: D:\warez\JAD\jadnt158\jad.exe
Directory for temporary files: D:\tmp\Decompiler


5. Done and test
Open a file, mouse over the javax.ejb.SessionBean, click F3 to go to the class definition.

 The Decompiled Java file will be shown.

Thursday, February 16, 2012

How to avoid calling huge number of Java program

Background
When the mail server receive email, it would trigger a java program by calling a shell script.
However, as the volumne of email is large, the java program will be triggered serveral times...

Better Design

Wednesday, February 15, 2012

[Resolved] Do not use APIs from sun.* packages (WAS Upgrade)

This is a short note for my WAS upgrade project V6.0 to V7.0

Recommendation by the WebSphere Application Migration Tool:
Do not use APIs from sun.* packages

Package: sun.misc.BASE64Encoder

*** Code changes as below:

Before
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

Monday, February 13, 2012

[Resolved] Use the BigDecimal toPlainString() method explicitly when deriving a string value (WAS Upgrade)

This is a short note for my WAS upgrade project V6.0 to V7.0

Recommendation by the WebSphere Application Migration Tool:
Use the BigDecimal toPlainString() method explicitly when deriving a string value


The behavior of the method toString() in BigDecimal is changed from J2SE 1.4 to 1.5

Java 1.4.2

 StringtoString()
          Returns the string representation of this BigDecimal.