Contains all kinds of wretched Java written/interview topics

Source: Internet
Author: User
Tags stringbuffer

This article contains a variety of wretched Java written/interview questions, some relatively easy to forget, not regularly updated. Also hope that everyone at the bottom of the message, posted on their own encounter or see a variety of wretched written, interview topics. Java EE Foundation section

1, operator priority problem, the following code results. Written[Java]View plain copy package test;           public class Test {public static void main (string[] args) {int k = 0;           int ret = ++k + k++ + ++k + k;       The value of the RET is how many System.err.println (ret); } 2, operator problem, what the following code outputs separately. Written[Java] View plain copy package test;      public class test {        public static void main (String[] args)  {            int i1 = 10, i2 = 10;            system.err.println ("i1 + i2 = "  + i1 &NBSP;+&NBSP;I2);           system.err.println ("i1 -  i2 =  " + i1 - i2);            system.err.println ("i1 * i2 = "  + i1 * i2);            system.err.println ("i1 / i2 = "  + i1 &NBSP;/&NBSP;I2);       }  }   3, what is the result of the following code. or throw an exception. Written [Java] View plain copy package test;      public class test {               public void mymethod (STRING&NBSP;STR)  {            system.err.println ("string");        }              public void  mymethod (object obj)  {            System.err.println ("Object");       }               public static void main (String[] args)  {           test t = new test ();            t.mymethod (NULL);       }  }    4, assuming today is September 8Day, what the following code outputs. Written[Java]View plain copy package test;      Import Java.util.Date;           public class Test {public static void main (string[] args) {Date date = new Date ();       System.err.println (Date.getmonth () + "" + date.getdate ()); } 5, what the output of the following code is.[Java]View plain copy package test;           public class Test {public static void main (string[] args) {double val = 11.5;           System.err.println (Math.Round (Val));           System.err.println (Math.floor (Val));       System.err.println (Math.ceil (Val)); } 6, programming outputs all directories and file names under a directory, and tab between directories. Written[Java] View plain copy package test;      import java.io.file;      Public  class Test {          public static void  Main (String[] args)  {           new test (). Read ("D:/test",  "");       }              public void read (String path, string tab)  {           file file = new file (PATH);           file[] childfiles = file.listfiles ();            for  (int i = 0; childfiles  != null && i < childfiles.length; i++)  {      &nBsp;         system.err.println (Tab + childFiles[i]. GetName ());               if  ( Childfiles[i].isdirectory ())  {                    read (Childfiles[i].getpath (), tab +  "\ T");               }            }       }  }   don't think it's easy, At the very least, remember to return all files under the current folder by Listfiles (), isdirectory don't spell the wrong one.

7, from the keyboard to read 10 integers, and then from large to small output. Written[Java] View plain copy package test;      import java.util.arrays;   import  java.util.comparator;   import java.util.scanner;      public class  test {          public static void main (String[)  args)  {           scanner in = new  scanner (system.in);           //  Note the array here, not the INT            integer[] arr = new integer[10 ];           for  (int i = 0; i  < 10; i++)  {                arr[i] = in.nextint ();           }    &NBsp;       arrays.sort (arr, new comparator<integer> ()   {                @Override                public int compare (Integer &NBSP;O1,&NBSP;INTEGER&NBSP;O2)  {                    if  (O1&NBSP;&GT;&NBSP;O2)  return -1;                    if  (o1  &LT;&NBSP;O2)  return 1;                    return 0;                }                    &nbsP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP});            System.err.println (arrays.tostring (arr));       }          }   own handwriting sorting algorithm can ignore this problem, if it is arrays.sort (), please pay attention to comparator and comparable interface difference, don't confuse.

8. What is the result of the following code?[Java] View plain copy package test;      public class test extends base  {          public static void main (string[]  args)  {           base b = new test ( );           b.method ();                       Test t =  New test ();           t.method ();        }           @Override         public void method ()  {            SYSTEM.ERR.PRINTLN ("test");       }          }      class base {       public void method ()   throws interruptedexception {            System.err.println ("base");       }  }   9, what is the result of the following code.[Java]View plain copy package test;       public class Test extends Base {public static void main (string[] args) {new test (). method ();           public void Method () {System.err.println (Super.getclass (). GetName ());       System.err.println (This.getclass (). Getsuperclass (). GetName ()); Class Base {} 10, True, or false.
[Java] View plain copy package test;      public class test {           public static void main (String[] args)  {           string str1 = new string ("abc");            string str2 = new string ("abc");            system.err.println (Str1.equals (str2));                       Stringbuffer sb1 = new stringbuffer ("abc");            stringbuffer sb2 = new stringbuffer ("abc");            system.err.println (Sb1.equals (SB2));          } &nbsp 11, the output of what is the result. [Java] View plain copy package test;      public class test {           public static void main (String[] args)  {           system.err.println (New test (). METHOD1 ());           system.err.println (New test (). METHOD2 ());       }              public  Int method1 ()  {           int x = 1;            try {                return x;            } finally {                ++x;           }       }              public int method2 ()  {           int x = 1;            try {                return x;           } finally {                return ++x;            }       }  }    so. Output what[Java]View plain copy package test;    public class Test {public static void main (string[] args) {System.err.println ()); &nbs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.