SlideShare a Scribd company logo
https://www.facebook. com/Oxus20

PART I – Scenario to program and code :
1. Write a method that accept a String named "strInput" as a parameter and returns
every other character of that String parameter starting with the first character.

M e t ho d I: - Us in g L o op
public static String everyOther(String strInput) {
String output = "";
for (int index = 0; index < strInput.length(); index += 2) {
output += strInput.charAt(index);
}
return output;
}

Tips:
 Each and every characters of the given String parameter needs to be scanned and

processed. Therefore, we need to know the number of characters in the String.
strInput.length();
st

1

character is needed that is why int index = 0; we don't need the 2

nd

character that

is why we incremented index by 2 as follow: index += 2
 strInput.charAt(index); reading the actual character and concatenated to the output

variable.
 Finally

System.out.println( everyOther("SshHeErRzZaAdD") ); // will print Sherzad

M e t ho d I I :- Us in g R e g u la r E xp r es s ion
public static String everyOther(String strInput) {
return strInput.replaceAll("(.)(.)", "$1");
}

Tips:
 In Regular Expression

. matches any character

 In Regular Expression

() use for grouping

 strInput.replaceAll("(.)(.)",

"$1"); // in the expression (.)(.), there are

two groups and each group matches any character; then, in the replacement string,
we can refer to the text of group 1 with the expression $1. Therefore, every other
character will be returned as follow:
System.out.println( everyOther("SshHeErRzZaAdD") ); // will print Sherzad

Abdul Rahman Sherzad

Page 1 of 5
https://www.facebook. com/Oxus20

2. Write a method named reverseString that accepts a String parameter and returns the
reverse of the given String parameter.

M e t ho d I: - Us in g Lo op
public static String reverseString(String strInput) {
String output = "";
for (int index = (strInput.length() - 1); index >= 0; index--) {
output += strInput.charAt(index);
}
return output;
}

Tips:
 Each and every characters of the given String parameter needs to be scanned and

processed. Therefore, we need to know the number of characters in the String.
strInput.length();
 Since index ranges from 0 to strInput.length() - 1; that is why we read each and every

character from the end int index = (strInput.length() - 1);
 Finally System.out.println( reverseString("02SUXO") ); // will print OXUS20

M e t ho d I I :- Us in g r e ve rs e ( ) m e t ho d o f S t ri n g B u i ld e r / S t r in g Bu f f e r c la s s
public static String reverseString(String strInput) {
if ((strInput == null) || (strInput.length() <= 1)) {
return strInput;
}
return new StringBuffer(strInput).reverse().toString();
}

Tips:
 Both StringBuilder and StringBuffer class have a reverse method. They work pretty much

the same, except that methods in StringBuilder are not synchronized.

M e t ho d I I I:- Us in g s ubs t r in g ( ) a n d Re c u rs i o n
public static String reverseString(String strInput) {
if ( strInput.equals("") )
return "";
return reverseString(strInput.substring(1)) + strInput.substring(0, 1);
}
public String substring(int beginIndex)
public String substring(int beginIndex, int endIndex)

Abdul Rahman Sherzad

Page 2 of 5
https://www.facebook. com/Oxus20

3. Write a method to generate a random number in a specific range. For instance, if
the given range is 15 - 25, meaning that 15 is the smallest possible value the
random number can take, and 25 is the biggest. Any other number in between these
numbers is possible to be a value, too.

M e t ho d I: - Us in g R a nd om c la s s o f ja va .u t il p a c ka g e
public static int rangeInt(int min, int max) {
java.util.Random rand = new java.util.Random();
int randomOutput = rand.nextInt((max - min) + 1) + min;
return randomOutput;
}

Tips:
 The nextInt(int n) method is used to get an int value between 0 (inclusive) and the

specified value (exclusive).
 Consider min = 15, max = 25, then

o rand.nextInt(max - min) // return a random int between 0 (inclusive) and 10
(exclusive). Interval demonstration [0, 10)
o rand.nextInt((max - min) + 1) // return a random int 0 and 10 both inclusive
o rand.nextInt((max

- min) + 1) + min // return a random int 0 and 10

both inclusive + 15;


if the return random int is 0 then 0 + 15 will be 15;



if the return random int is 10 then 10 + 15 will be 25;



if the return random int is 5 then 5 + 15 will be 20;



Hence the return random int will be between min and max value both
inclusive.

M e t ho d I I :- Us in g M a t h .r a nd om ( ) m e th o d
public static int rangeInt(int min, int max) {
return (int) ( Math.random() * ( (max – min) + 1 ) ) + min;
}

Note:
 In practice, the Random class is often preferable

to Math.random().

Abdul Rahman Sherzad

Page 3 of 5
https://www.facebook. com/Oxus20

PART II – Single Choice and Multiple Choices:
1. Which of the following declarations is correct?

 [A ] boolean b = TRUE;
 [B] byte b = 255;

[A] boolean b = TRUE; // JAVA is Case Sensitive!

 [C] String s = "null";

[B] byte b = 255; // Out of range MIN_VALUE = -128 and
MAX_VALUE = 127

 [D] int i = new Integer("56");

[C] String s = "null"; // Everything between double quotes ""
considered as String
[D] int i = new Integer("56"); // The string "56" is converted
to an int value.

2. Consider the following program:
import oxus20Library.*;
public class OXUS20 {
public static void main(String[] args) {
// The code goes here ...
}
}

What is the name of the java file containing this program?
 A. oxus20Library.java
 B. OXUS20.java

 Each JAVA source file can contain only one
public class.

 C. OXUS20

 The source file's name has to be the name of
that public class. By convention, the

 D. OXUS20.class

source file uses a .java filename extension

 E. Any file name w ith the java suffix is accepted

3. Consider the following code snippet
public class OXUS20 {
public static void main(String[] args) {
String river = new String("OXUS means Amu Darya");
System.out.println(river.length());
}
}

What is printed?
 A. 17

 B. OXUS means Amu Darya

Abdul Rahman Sherzad

 C. 20

 E. river

Page 4 of 5
https://www.facebook. com/Oxus20

4. A constructor

 A. mus t have the same name as the class it is declared w ithin.
 B. is used to create objects.
 C. may be declared private
 D. A ll the above

 A.

A c o n s t r u c t o r m u s t h a ve t h e s a m e n a m e a s t h e c l a s s i t i s d e c l a r e d w i t h i n .
public class OXUS20 {
public OXUS20() {
}
}

 B.

C o n s t ru c t o r i s u s e d t o c re a te o b j e c ts
OXUS20 amu_darya = new OXUS20();

 C.

C o n s t ru c t o r m a y b e d e c l a r e d p r i va t e // private constructor is off
course to restrict instantiation of the class. Actually a good
use of private constructor is in Singleton Pattern.

5. Which of the following may be part of a class definition?

 A. instance variables
 B. instance methods
Following is a sample of class declaration:

 C. constructors
 D. All of the above

class MyClass {
 Field // class variables or instance variables

 E. None of the above
 constructor, and // class constructor or overloaded constructors

 method declarations // class methods or instance methods

}

Abdul Rahman Sherzad

Page 5 of 5
‫‪OXUS20 is a non-profit society with the aim of changing education for the better‬‬
‫.‪by providing education and assistance to IT and computer science professionals‬‬

‫آکسیوس20 یک انجمن غیر انتفاعی با هدف تغییرو تقویت آموزش و پرورش از طریق ارائه آموزش و کمک به متخصصان علوم‬
‫کامپیوتر است.‬
‫نام این انجمن برگرفته از دریای آمو پر آب ترین رود آسیای میانه که دست موج آن بیانگر استعداد های نهفته این انجمن بوده، و این دریا از دامنه های کهن پامیر‬
‫سرچشمه گرفته و ماورای شمالی سرزمین باستانی افغانستان را آبیاری میکند که این حالت دریا هدف ارایه خدمات انجمن را انعکاس میدهد.‬
‫آکسیوس20 در نظر دارد تا خدماتی مانند ایجاد فضای مناسب برای تجلی استعدادها و برانگیختن خالقیت و شکوفایی علمی محصالن و دانش پژوهان، نهادمند‬
‫ساختن فعالیت های فوق برنامه علمی و کاربردی، شناسایی افراد خالق، نخبه و عالقمند و بهره گیری از مشارکت آنها در ارتقای فضای علمی پوهنتون ها و دیگر‬
‫مراکز آموزشی و جامعه همچون تولید و انتشار نشریات علمی تخصصی علوم عصری و تکنالوژی معلوماتی را به شکل موثر آن در جامعه در راستای هرچه بهتر‬
‫شدن زمینه تدریس، تحقیق و پژوهش و راه های رسیدن به آمال افراد جامعه را فراهم میسازد.‬

‫,‪Follow us on Facebook‬‬
‫02‪https://www.facebook.com/Oxus‬‬

More Related Content

What's hot

OpenGL ES 3 Reference Card
OpenGL ES 3 Reference CardOpenGL ES 3 Reference Card
OpenGL ES 3 Reference Card
The Khronos Group Inc.
 
Lecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional ArrayLecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional Array
Md. Imran Hossain Showrov
 
2 data and c
2 data and c2 data and c
2 data and c
MomenMostafa
 
03 structures
03 structures03 structures
03 structures
Rajan Gautam
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
Cse115 lecture14strings part01
Cse115 lecture14strings part01Cse115 lecture14strings part01
Cse115 lecture14strings part01
Md. Ashikur Rahman
 
Class 2: Welcome part 2
Class 2: Welcome part 2Class 2: Welcome part 2
Class 2: Welcome part 2
Marc Gouw
 
C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
sagaroceanic11
 
Nn
NnNn
Keygenning using the Z3 SMT Solver
Keygenning using the Z3 SMT SolverKeygenning using the Z3 SMT Solver
Keygenning using the Z3 SMT Solver
extremecoders
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypes
Monika Sanghani
 
OO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual FunctionOO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual Function
Yu-Sheng (Yosen) Chen
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Rakesh Roshan
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
Abhishek Sinha
 
Class 5: If, while & lists
Class 5: If, while & listsClass 5: If, while & lists
Class 5: If, while & lists
Marc Gouw
 
Module 5-Structure and Union
Module 5-Structure and UnionModule 5-Structure and Union
Module 5-Structure and Union
nikshaikh786
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 

What's hot (17)

OpenGL ES 3 Reference Card
OpenGL ES 3 Reference CardOpenGL ES 3 Reference Card
OpenGL ES 3 Reference Card
 
Lecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional ArrayLecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional Array
 
2 data and c
2 data and c2 data and c
2 data and c
 
03 structures
03 structures03 structures
03 structures
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
Cse115 lecture14strings part01
Cse115 lecture14strings part01Cse115 lecture14strings part01
Cse115 lecture14strings part01
 
Class 2: Welcome part 2
Class 2: Welcome part 2Class 2: Welcome part 2
Class 2: Welcome part 2
 
C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
 
Nn
NnNn
Nn
 
Keygenning using the Z3 SMT Solver
Keygenning using the Z3 SMT SolverKeygenning using the Z3 SMT Solver
Keygenning using the Z3 SMT Solver
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypes
 
OO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual FunctionOO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual Function
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
Class 5: If, while & lists
Class 5: If, while & listsClass 5: If, while & lists
Class 5: If, while & lists
 
Module 5-Structure and Union
Module 5-Structure and UnionModule 5-Structure and Union
Module 5-Structure and Union
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 

Viewers also liked

java question paper 5th sem
java question paper 5th semjava question paper 5th sem
java question paper 5th semshaikfarhan8
 
Java (Information Technology) Question paper for T.Y Bca
Java (Information Technology) Question paper for T.Y BcaJava (Information Technology) Question paper for T.Y Bca
Java (Information Technology) Question paper for T.Y Bca
JIGAR MAKHIJA
 
Java Programming Question paper Aurangabad MMS
Java Programming Question paper Aurangabad  MMSJava Programming Question paper Aurangabad  MMS
Java Programming Question paper Aurangabad MMSAshwin Mane
 
5th Semester (December; January-2014 and 2015) Computer Science and Informati...
5th Semester (December; January-2014 and 2015) Computer Science and Informati...5th Semester (December; January-2014 and 2015) Computer Science and Informati...
5th Semester (December; January-2014 and 2015) Computer Science and Informati...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Java mcq
Java mcqJava mcq
Java mcq
avinash9821
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
Mumbai Academisc
 
Java Tuning White Paper
Java Tuning White PaperJava Tuning White Paper
Java Tuning White Paper
white paper
 
5th semester VTU BE CS & IS question papers from 2010 to July 2016
5th semester VTU BE CS & IS question papers from 2010 to July 20165th semester VTU BE CS & IS question papers from 2010 to July 2016
5th semester VTU BE CS & IS question papers from 2010 to July 2016
Coorg Institute of Technology, Department Of Library & Information Center , Ponnampet
 
5th semester Computer Science and Information Science Engg (2013 December) Qu...
5th semester Computer Science and Information Science Engg (2013 December) Qu...5th semester Computer Science and Information Science Engg (2013 December) Qu...
5th semester Computer Science and Information Science Engg (2013 December) Qu...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Java apptitude-questions-part-2
Java apptitude-questions-part-2Java apptitude-questions-part-2
Java apptitude-questions-part-2
vishvavidya
 
Java Multiple Choice Questions and Answers
Java Multiple Choice Questions and AnswersJava Multiple Choice Questions and Answers
Java Multiple Choice Questions and Answers
Java Projects
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
vivek shah
 
Java apptitude-questions-part-1
Java apptitude-questions-part-1Java apptitude-questions-part-1
Java apptitude-questions-part-1
vishvavidya
 
TKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids ProgrammingTKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids Programming
Lynn Langit
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
OXUS 20
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented Programming
Abdul Rahman Sherzad
 
Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement
OXUS 20
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
OXUS 20
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
OXUS 20
 
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationPHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail Explanation
OXUS 20
 

Viewers also liked (20)

java question paper 5th sem
java question paper 5th semjava question paper 5th sem
java question paper 5th sem
 
Java (Information Technology) Question paper for T.Y Bca
Java (Information Technology) Question paper for T.Y BcaJava (Information Technology) Question paper for T.Y Bca
Java (Information Technology) Question paper for T.Y Bca
 
Java Programming Question paper Aurangabad MMS
Java Programming Question paper Aurangabad  MMSJava Programming Question paper Aurangabad  MMS
Java Programming Question paper Aurangabad MMS
 
5th Semester (December; January-2014 and 2015) Computer Science and Informati...
5th Semester (December; January-2014 and 2015) Computer Science and Informati...5th Semester (December; January-2014 and 2015) Computer Science and Informati...
5th Semester (December; January-2014 and 2015) Computer Science and Informati...
 
Java mcq
Java mcqJava mcq
Java mcq
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 
Java Tuning White Paper
Java Tuning White PaperJava Tuning White Paper
Java Tuning White Paper
 
5th semester VTU BE CS & IS question papers from 2010 to July 2016
5th semester VTU BE CS & IS question papers from 2010 to July 20165th semester VTU BE CS & IS question papers from 2010 to July 2016
5th semester VTU BE CS & IS question papers from 2010 to July 2016
 
5th semester Computer Science and Information Science Engg (2013 December) Qu...
5th semester Computer Science and Information Science Engg (2013 December) Qu...5th semester Computer Science and Information Science Engg (2013 December) Qu...
5th semester Computer Science and Information Science Engg (2013 December) Qu...
 
Java apptitude-questions-part-2
Java apptitude-questions-part-2Java apptitude-questions-part-2
Java apptitude-questions-part-2
 
Java Multiple Choice Questions and Answers
Java Multiple Choice Questions and AnswersJava Multiple Choice Questions and Answers
Java Multiple Choice Questions and Answers
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 
Java apptitude-questions-part-1
Java apptitude-questions-part-1Java apptitude-questions-part-1
Java apptitude-questions-part-1
 
TKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids ProgrammingTKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids Programming
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented Programming
 
Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
 
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationPHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail Explanation
 

Similar to JAVA Programming Questions and Answers PART III

Structure in c sharp
Structure in c sharpStructure in c sharp
Structure in c sharp
rrajeshvhadlure
 
Big Brother helps you
Big Brother helps youBig Brother helps you
Big Brother helps you
PVS-Studio
 
Bc0037
Bc0037Bc0037
Bc0037
hayerpa
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
Synapseindiappsdevelopment
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
MLG College of Learning, Inc
 
Functions
FunctionsFunctions
Functions
Swarup Boro
 
Ch 4
Ch 4Ch 4
Ch 4
AMIT JAIN
 
02.adt
02.adt02.adt
Useful c programs
Useful c programsUseful c programs
Useful c programs
MD SHAH FAHAD
 
Unitii string
Unitii stringUnitii string
Unitii string
Sowri Rajan
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
C++ Homework Help
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
vikram mahendra
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013
ericupnorth
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
gkgaur1987
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptx
samdamfa
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
yndaravind
 
CS215 Lec 1 introduction
CS215 Lec 1   introductionCS215 Lec 1   introduction
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
Abdulrahman890100
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
Yaser Zhian
 

Similar to JAVA Programming Questions and Answers PART III (20)

Structure in c sharp
Structure in c sharpStructure in c sharp
Structure in c sharp
 
Big Brother helps you
Big Brother helps youBig Brother helps you
Big Brother helps you
 
Bc0037
Bc0037Bc0037
Bc0037
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
 
Functions
FunctionsFunctions
Functions
 
Ch 4
Ch 4Ch 4
Ch 4
 
02.adt
02.adt02.adt
02.adt
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 
Unitii string
Unitii stringUnitii string
Unitii string
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptx
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
CS215 Lec 1 introduction
CS215 Lec 1   introductionCS215 Lec 1   introduction
CS215 Lec 1 introduction
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
 

More from OXUS 20

Java Arrays
Java ArraysJava Arrays
Java Arrays
OXUS 20
 
Java Methods
Java MethodsJava Methods
Java Methods
OXUS 20
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
OXUS 20
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
OXUS 20
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
OXUS 20
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
OXUS 20
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
OXUS 20
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
OXUS 20
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and Technologies
OXUS 20
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
OXUS 20
 
Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART II
OXUS 20
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
OXUS 20
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
OXUS 20
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
OXUS 20
 
Object Oriented Programming with Real World Examples
Object Oriented Programming with Real World ExamplesObject Oriented Programming with Real World Examples
Object Oriented Programming with Real World Examples
OXUS 20
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non Static
OXUS 20
 

More from OXUS 20 (16)

Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Java Methods
Java MethodsJava Methods
Java Methods
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and Technologies
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 
Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART II
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
 
Object Oriented Programming with Real World Examples
Object Oriented Programming with Real World ExamplesObject Oriented Programming with Real World Examples
Object Oriented Programming with Real World Examples
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non Static
 

Recently uploaded

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 

JAVA Programming Questions and Answers PART III

  • 1. https://www.facebook. com/Oxus20 PART I – Scenario to program and code : 1. Write a method that accept a String named "strInput" as a parameter and returns every other character of that String parameter starting with the first character. M e t ho d I: - Us in g L o op public static String everyOther(String strInput) { String output = ""; for (int index = 0; index < strInput.length(); index += 2) { output += strInput.charAt(index); } return output; } Tips:  Each and every characters of the given String parameter needs to be scanned and processed. Therefore, we need to know the number of characters in the String. strInput.length(); st 1 character is needed that is why int index = 0; we don't need the 2 nd character that is why we incremented index by 2 as follow: index += 2  strInput.charAt(index); reading the actual character and concatenated to the output variable.  Finally System.out.println( everyOther("SshHeErRzZaAdD") ); // will print Sherzad M e t ho d I I :- Us in g R e g u la r E xp r es s ion public static String everyOther(String strInput) { return strInput.replaceAll("(.)(.)", "$1"); } Tips:  In Regular Expression . matches any character  In Regular Expression () use for grouping  strInput.replaceAll("(.)(.)", "$1"); // in the expression (.)(.), there are two groups and each group matches any character; then, in the replacement string, we can refer to the text of group 1 with the expression $1. Therefore, every other character will be returned as follow: System.out.println( everyOther("SshHeErRzZaAdD") ); // will print Sherzad Abdul Rahman Sherzad Page 1 of 5
  • 2. https://www.facebook. com/Oxus20 2. Write a method named reverseString that accepts a String parameter and returns the reverse of the given String parameter. M e t ho d I: - Us in g Lo op public static String reverseString(String strInput) { String output = ""; for (int index = (strInput.length() - 1); index >= 0; index--) { output += strInput.charAt(index); } return output; } Tips:  Each and every characters of the given String parameter needs to be scanned and processed. Therefore, we need to know the number of characters in the String. strInput.length();  Since index ranges from 0 to strInput.length() - 1; that is why we read each and every character from the end int index = (strInput.length() - 1);  Finally System.out.println( reverseString("02SUXO") ); // will print OXUS20 M e t ho d I I :- Us in g r e ve rs e ( ) m e t ho d o f S t ri n g B u i ld e r / S t r in g Bu f f e r c la s s public static String reverseString(String strInput) { if ((strInput == null) || (strInput.length() <= 1)) { return strInput; } return new StringBuffer(strInput).reverse().toString(); } Tips:  Both StringBuilder and StringBuffer class have a reverse method. They work pretty much the same, except that methods in StringBuilder are not synchronized. M e t ho d I I I:- Us in g s ubs t r in g ( ) a n d Re c u rs i o n public static String reverseString(String strInput) { if ( strInput.equals("") ) return ""; return reverseString(strInput.substring(1)) + strInput.substring(0, 1); } public String substring(int beginIndex) public String substring(int beginIndex, int endIndex) Abdul Rahman Sherzad Page 2 of 5
  • 3. https://www.facebook. com/Oxus20 3. Write a method to generate a random number in a specific range. For instance, if the given range is 15 - 25, meaning that 15 is the smallest possible value the random number can take, and 25 is the biggest. Any other number in between these numbers is possible to be a value, too. M e t ho d I: - Us in g R a nd om c la s s o f ja va .u t il p a c ka g e public static int rangeInt(int min, int max) { java.util.Random rand = new java.util.Random(); int randomOutput = rand.nextInt((max - min) + 1) + min; return randomOutput; } Tips:  The nextInt(int n) method is used to get an int value between 0 (inclusive) and the specified value (exclusive).  Consider min = 15, max = 25, then o rand.nextInt(max - min) // return a random int between 0 (inclusive) and 10 (exclusive). Interval demonstration [0, 10) o rand.nextInt((max - min) + 1) // return a random int 0 and 10 both inclusive o rand.nextInt((max - min) + 1) + min // return a random int 0 and 10 both inclusive + 15;  if the return random int is 0 then 0 + 15 will be 15;  if the return random int is 10 then 10 + 15 will be 25;  if the return random int is 5 then 5 + 15 will be 20;  Hence the return random int will be between min and max value both inclusive. M e t ho d I I :- Us in g M a t h .r a nd om ( ) m e th o d public static int rangeInt(int min, int max) { return (int) ( Math.random() * ( (max – min) + 1 ) ) + min; } Note:  In practice, the Random class is often preferable to Math.random(). Abdul Rahman Sherzad Page 3 of 5
  • 4. https://www.facebook. com/Oxus20 PART II – Single Choice and Multiple Choices: 1. Which of the following declarations is correct?  [A ] boolean b = TRUE;  [B] byte b = 255; [A] boolean b = TRUE; // JAVA is Case Sensitive!  [C] String s = "null"; [B] byte b = 255; // Out of range MIN_VALUE = -128 and MAX_VALUE = 127  [D] int i = new Integer("56"); [C] String s = "null"; // Everything between double quotes "" considered as String [D] int i = new Integer("56"); // The string "56" is converted to an int value. 2. Consider the following program: import oxus20Library.*; public class OXUS20 { public static void main(String[] args) { // The code goes here ... } } What is the name of the java file containing this program?  A. oxus20Library.java  B. OXUS20.java  Each JAVA source file can contain only one public class.  C. OXUS20  The source file's name has to be the name of that public class. By convention, the  D. OXUS20.class source file uses a .java filename extension  E. Any file name w ith the java suffix is accepted 3. Consider the following code snippet public class OXUS20 { public static void main(String[] args) { String river = new String("OXUS means Amu Darya"); System.out.println(river.length()); } } What is printed?  A. 17  B. OXUS means Amu Darya Abdul Rahman Sherzad  C. 20  E. river Page 4 of 5
  • 5. https://www.facebook. com/Oxus20 4. A constructor  A. mus t have the same name as the class it is declared w ithin.  B. is used to create objects.  C. may be declared private  D. A ll the above  A. A c o n s t r u c t o r m u s t h a ve t h e s a m e n a m e a s t h e c l a s s i t i s d e c l a r e d w i t h i n . public class OXUS20 { public OXUS20() { } }  B. C o n s t ru c t o r i s u s e d t o c re a te o b j e c ts OXUS20 amu_darya = new OXUS20();  C. C o n s t ru c t o r m a y b e d e c l a r e d p r i va t e // private constructor is off course to restrict instantiation of the class. Actually a good use of private constructor is in Singleton Pattern. 5. Which of the following may be part of a class definition?  A. instance variables  B. instance methods Following is a sample of class declaration:  C. constructors  D. All of the above class MyClass {  Field // class variables or instance variables  E. None of the above  constructor, and // class constructor or overloaded constructors  method declarations // class methods or instance methods } Abdul Rahman Sherzad Page 5 of 5
  • 6. ‫‪OXUS20 is a non-profit society with the aim of changing education for the better‬‬ ‫.‪by providing education and assistance to IT and computer science professionals‬‬ ‫آکسیوس20 یک انجمن غیر انتفاعی با هدف تغییرو تقویت آموزش و پرورش از طریق ارائه آموزش و کمک به متخصصان علوم‬ ‫کامپیوتر است.‬ ‫نام این انجمن برگرفته از دریای آمو پر آب ترین رود آسیای میانه که دست موج آن بیانگر استعداد های نهفته این انجمن بوده، و این دریا از دامنه های کهن پامیر‬ ‫سرچشمه گرفته و ماورای شمالی سرزمین باستانی افغانستان را آبیاری میکند که این حالت دریا هدف ارایه خدمات انجمن را انعکاس میدهد.‬ ‫آکسیوس20 در نظر دارد تا خدماتی مانند ایجاد فضای مناسب برای تجلی استعدادها و برانگیختن خالقیت و شکوفایی علمی محصالن و دانش پژوهان، نهادمند‬ ‫ساختن فعالیت های فوق برنامه علمی و کاربردی، شناسایی افراد خالق، نخبه و عالقمند و بهره گیری از مشارکت آنها در ارتقای فضای علمی پوهنتون ها و دیگر‬ ‫مراکز آموزشی و جامعه همچون تولید و انتشار نشریات علمی تخصصی علوم عصری و تکنالوژی معلوماتی را به شکل موثر آن در جامعه در راستای هرچه بهتر‬ ‫شدن زمینه تدریس، تحقیق و پژوهش و راه های رسیدن به آمال افراد جامعه را فراهم میسازد.‬ ‫,‪Follow us on Facebook‬‬ ‫02‪https://www.facebook.com/Oxus‬‬