Android 4.0 SDK yı kurduktan sonra virtual bir device eklemek istediğimde şöyle bir hata ile karşılaştım:
"Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder."
If you look in the "Android SDK Manager" in the "Android 4.0 (API 14)" section you'll see a few packages. One of these is named "ARM EABI v7a System Image".
This is what you need to download in order to create an Android 4.0 virtual device:
ref
13 Nisan 2012 Cuma
6 Nisan 2012 Cuma
Sending Email With Images in a HTML Table Through Java
Mailinizi html şeklinde tasarlayın ve sonra bu html i message ınıza set edin.
message.setContent(your html);
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class MailSender {
/* */
private Properties props = new Properties();
/* */
private Session session;
/* */
private InternetAddress sdriveMail;
/**
*
*/
public MailSender() {
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("info.sdrive","şifre");
}
});
try {
sdriveMail = new InternetAddress("info.sdrive@gmail.com");
} catch (AddressException e) {
}
}
/**
*
* @param mailAddress
* @param userName
* @param nickName
*/
public void sendWelcomeMail(String mailAddress, String userName, String nickName){
try {
Message message = new MimeMessage(session);
message.setFrom(sdriveMail);
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(mailAddress));
message.setSubject("Welcome to SDrive!");
message.setContent
("<html><body><table border = \"3\" width = \"800\"><tr align=\"center\"><td><img src=\"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQRh7AYO4dETB_gzAhFuqyFhFYapzZ7trft3bb9TZCThbLG0lIjrOJXhz6j5EXshqMBbK1NkYQTeY7MAj6yFpOfZWaBq7iJg9XbaxY3KdBJnRsDi3PXamWhWxqt8PqtMtfiwpwMrZYdZfd/s320/t2.png\">"
+ "</td></tr><tr><td height = \"100\" ><h3>Dear Sdrive user,</h3>" + "Welcome to SDrive!" +
" Thank you for registering with Sdrive!</td></tr><tr><td height = \"150\">" +
"<p>Your account information:</p>" +
"<p>Name: " + userName +
"</p><p>User Name: "+ nickName +
"</p><p>Email: "+ mailAddress + "</p><br /><br /><p>Copyright © 2012 SDrive. All rights reserved.</p></td></tr></table></body></html>",
"text/html");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
}
}
public static void main(String[] args) {
MailSender mail = new MailSender();
mail.sendWelcomeMail("baharcglr@gmail.com", "Bahar Çaglar", "baharcaglar");
}
}
5 Nisan 2012 Perşembe
Log4j vs java.util.logging API
You have seen logging levels in log4j they have optimized number of java logging level and each of them fully describes what it does. Another flexibility of log4j is that you can change logging level of your java application without restarting your java application, by the way this you can do in java.util.logging API by using JMX if you have implemented that.
Log4j also provides flexibility to set logging level based on per class in its configuration file log4j.xml. You can either use log4j.properties file or log4j.xml for configuring java logging in your application while using log4j for logging in java. Also log4j is thread-safe. Log4j components are designed to be used in heavily multithreaded systems. On the other hand Formatter and Appender facility of java.util.logging API quite useful especially Formatter allows you to format java logging output as you want for logging in Java.
Log4j also provides flexibility to set logging level based on per class in its configuration file log4j.xml. You can either use log4j.properties file or log4j.xml for configuring java logging in your application while using log4j for logging in java. Also log4j is thread-safe. Log4j components are designed to be used in heavily multithreaded systems. On the other hand Formatter and Appender facility of java.util.logging API quite useful especially Formatter allows you to format java logging output as you want for logging in Java.
4 Nisan 2012 Çarşamba
JUnit 4
1. @Test
Mark your test cases with @Test annotations. You don’t need to prefix your test cases with “test”. In addition, your class does not need to extend from “TestCase” class.
@Test
public void addition() {
assertEquals(12, simpleMath.add(7, 5));
}
@Test
public void subtraction() {
assertEquals(9, simpleMath.substract(12, 3));
}
2. @Before and @After
Use @Before and @After annotations for “setup” and “tearDown” methods respectively. They run before and after every test case.
@Before
public void runBeforeEveryTest() {
simpleMath = new SimpleMath();
}
@After
public void runAfterEveryTest() {
simpleMath = null;
}
3. @BeforeClass and @AfterClass
Use @BeforeClass and @AfterClass annotations for class wide “setup” and “tearDown” respectively. Think them as one time setup and tearDown. They run for one time before and after all test cases.
@BeforeClass
public static void runBeforeClass() {
// run for one time before all test cases
}
@AfterClass
public static void runAfterClass() {
// run for one time after all test cases
}
4.Exception Handling
Use “expected” paramater with @Test annotation for test cases that expect exception. Write the class name of the exception that will be thrown.
@Test(expected = ArithmeticException.class)
public void divisionWithException() {
// divide by zero
simpleMath.divide(1, 0);
}
5. @Ignore
Put @Ignore annotation for test cases you want to ignore. You can add a string parameter that defines the reason of ignorance if you want.
@Ignore(“Not Ready to Run”)
@Test
public void multiplication() {
assertEquals(15, simpleMath.multiply(3, 5));
}
6. Timeout
Define a timeout period in miliseconds with “timeout” parameter. The test fails when the timeout period exceeds.
@Test(timeout = 1000)
public void infinity() {
while (true)
;
}
7. New Assertions
Compare arrays with new assertion methods. Two arrays are equal if they have the same length and each element is equal to the corresponding element in the other array; otherwise, they’re not.
public static void assertEquals(Object[] expected, Object[] actual);
public static void assertEquals(String message, Object[] expected, Object[] actual);
@Test
public void listEquality() {
List expected = new ArrayList();
expected.add(5);
List actual = new ArrayList();
actual.add(5);
assertEquals(expected, actual);
}
8. JUnit4Adapter
Run your Junit 4 tests in Junit 3 test runners with Junit4Adapter.
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(SimpleMathTest.class);
}
ref
Mark your test cases with @Test annotations. You don’t need to prefix your test cases with “test”. In addition, your class does not need to extend from “TestCase” class.
@Test
public void addition() {
assertEquals(12, simpleMath.add(7, 5));
}
@Test
public void subtraction() {
assertEquals(9, simpleMath.substract(12, 3));
}
2. @Before and @After
Use @Before and @After annotations for “setup” and “tearDown” methods respectively. They run before and after every test case.
@Before
public void runBeforeEveryTest() {
simpleMath = new SimpleMath();
}
@After
public void runAfterEveryTest() {
simpleMath = null;
}
3. @BeforeClass and @AfterClass
Use @BeforeClass and @AfterClass annotations for class wide “setup” and “tearDown” respectively. Think them as one time setup and tearDown. They run for one time before and after all test cases.
@BeforeClass
public static void runBeforeClass() {
// run for one time before all test cases
}
@AfterClass
public static void runAfterClass() {
// run for one time after all test cases
}
4.Exception Handling
Use “expected” paramater with @Test annotation for test cases that expect exception. Write the class name of the exception that will be thrown.
@Test(expected = ArithmeticException.class)
public void divisionWithException() {
// divide by zero
simpleMath.divide(1, 0);
}
5. @Ignore
Put @Ignore annotation for test cases you want to ignore. You can add a string parameter that defines the reason of ignorance if you want.
@Ignore(“Not Ready to Run”)
@Test
public void multiplication() {
assertEquals(15, simpleMath.multiply(3, 5));
}
6. Timeout
Define a timeout period in miliseconds with “timeout” parameter. The test fails when the timeout period exceeds.
@Test(timeout = 1000)
public void infinity() {
while (true)
;
}
7. New Assertions
Compare arrays with new assertion methods. Two arrays are equal if they have the same length and each element is equal to the corresponding element in the other array; otherwise, they’re not.
public static void assertEquals(Object[] expected, Object[] actual);
public static void assertEquals(String message, Object[] expected, Object[] actual);
@Test
public void listEquality() {
List expected = new ArrayList();
expected.add(5);
List actual = new ArrayList();
actual.add(5);
assertEquals(expected, actual);
}
8. JUnit4Adapter
Run your Junit 4 tests in Junit 3 test runners with Junit4Adapter.
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(SimpleMathTest.class);
}
ref
Java - Eclipse Generate JavaDoc
1.Listed below is a Javadoc comment style used to generate a Javadoc.
Use following comment style to generate a Javadoc.
2. Click on projects link and choose ” Generate Javadoc ” option.
3.Now a window will be opened where you can select Java Projects or their underlying resources for which JavaDoc needs to be generated. Several other options are also there where user can select any of them as per the need.Here user can select whether to generate JavaDoc for public/private API’s etc.
4. Click “Finish” Javadoc will be generated. If you select option of opening index file in browser then after generation of Javadoc you will find ” index.htm ” of Javadoc in your default Web Browser. On console you can see progress of JavaDoc Generation.
Use following comment style to generate a Javadoc.
2. Click on projects link and choose ” Generate Javadoc ” option.
3.Now a window will be opened where you can select Java Projects or their underlying resources for which JavaDoc needs to be generated. Several other options are also there where user can select any of them as per the need.Here user can select whether to generate JavaDoc for public/private API’s etc.
4. Click “Finish” Javadoc will be generated. If you select option of opening index file in browser then after generation of Javadoc you will find ” index.htm ” of Javadoc in your default Web Browser. On console you can see progress of JavaDoc Generation.
2 Nisan 2012 Pazartesi
java open frame in the center of window
/** Put frame at center of screen. **/
Ben kendi frame imin boyutuna göre ayarladım width i 3'e height ı 7 ye böldüm.
Frame in left top coordinatına bu değeri attım. Frame size ınıza göre bunu değiştirebilirsiniz
void centerFrame (JFrame f) {
// Need the toolkit to get info on system.
Toolkit tk = Toolkit.getDefaultToolkit ();
// Get the screen dimensions.
Dimension screen = tk.getScreenSize ();
// And place it in center of screen.
int lx = (int) (screen.getWidth () /3);
int ly = (int) (screen.getHeight ()/7);
f.setLocation (lx,ly);
} // centerFrame
Ben kendi frame imin boyutuna göre ayarladım width i 3'e height ı 7 ye böldüm.
Frame in left top coordinatına bu değeri attım. Frame size ınıza göre bunu değiştirebilirsiniz
void centerFrame (JFrame f) {
// Need the toolkit to get info on system.
Toolkit tk = Toolkit.getDefaultToolkit ();
// Get the screen dimensions.
Dimension screen = tk.getScreenSize ();
// And place it in center of screen.
int lx = (int) (screen.getWidth () /3);
int ly = (int) (screen.getHeight ()/7);
f.setLocation (lx,ly);
} // centerFrame
How to List all files in a directory
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public List getAllFilesInDirectory(String directory) {
String files;
File folder = new File(directory);
File[] listOfFiles = folder.listFiles();
List allFiles = new ArrayList<>();
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
files = listOfFiles[i].getName();
//System.out.println(files);
allFiles.add(files);
}
}
return allFiles;
}
import java.util.ArrayList;
import java.util.List;
public List
String files;
File folder = new File(directory);
File[] listOfFiles = folder.listFiles();
List
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
files = listOfFiles[i].getName();
//System.out.println(files);
allFiles.add(files);
}
}
return allFiles;
}

