New to Java some questions
Hi, im new to java and am currently studying it at university, i was wondering if anyone could answer and explain these questions for me please? :)
a) There are three different types of loop. Explain the difference between them
b) Write an appropriate loop to
i. Read in 10 names from a file
ii. Read a number of names from a file until the word STOP is read in.
a) Explain what an array is and describe how it can be created and used.
b) Show the pseudo code and the code to read 10 numbers into an array and find the highest. Explain, using examples of Java, how the following could be carried out:
a) Ask a user to input their name and address details and display the input on the screen.
b) Read a list of names from a file, and display them on the screen.
c) Write a list of books to a file.
A) Using examples of code explain the uses of following
i. A JTextField
ii. A JPanel
iii. A JFrame
iv. A JLabel
B) Show how JButtons can be used to:
i. Close a form
ii. To open a new form
A) Using examples describe classes and objects and explain the relationship between them.
B) Explain how information hiding is implemented in Object Oriented programming and why it is used.
Thanks in advance.
Re: New to Java some questions
Quote:
Originally Posted by
unorthadox
Hi, im new to java and am currently studying it at university, i was wondering if anyone could answer and explain these questions for me please? :)
new too,but have some answers :)
Quote:
Originally Posted by
unorthadox
a) There are three different types of loop. Explain the difference between them
the for loop is used when we know the exact number of itterations that are going to be done.It is written as this
part1 is executed only one time,when your code reaches this line of for loop
then the part2 which is normally someCondition is going to be resolved in true or false.If true the loop is going to be executed,if false the for loop is going to be skipped and the body of it will never be executed.In case the part2 is true,then the body of the for loop is going to be executed.Right at the bottom of the loop the part3(which is normally is an increment or decrement) is going to be executed.Then the flow goes back to part 2 and checks it part2 is true or not an so on.
e.g.
Code :
for(int i=0; i<n ; i++)
//the code here is going to be
//executed n times
check out the enhanced for that is used about arrays and Collections after you get some more experience.
The while loop is going to be executed as long as the someCondition is true
Code :
while(value<5)//someCondition is the expression value<5
{
//the code here is going to be executed as long as the value is smaller than 5
}
Code :
do
{
//body
}while(someCondition);
The do-while loop is similar to while,but it is going to be at least one time(regardless if someCondition is true or not).The body will be executed at least one time,then the someCondition is going to be resolved into true or not.If true the loop goes on,if not the flow goes after the loop.So the do while is a while that the someCondition is checked at the bottom of the loop,not the top(as the while loop).
Quote:
Originally Posted by
unorthadox
a) Explain what an array is and describe how it can be created and used.
An array is a group of variables of some type,that are allocated to adjacent cells in memory.You can see some tutorial about this though
Quote:
Originally Posted by
unorthadox
b) Show the pseudo code and the code to read 10 numbers into an array and find the highest. Explain, using examples of Java, how the following could be carried out:
a) Ask a user to input their name and address details and display the input on the screen.
b) Read a list of names from a file, and display them on the screen.
c) Write a list of books to a file.
A) Using examples of code explain the uses of following
i. A JTextField
ii. A JPanel
iii. A JFrame
iv. A JLabel
B) Show how JButtons can be used to:
i. Close a form
ii. To open a new form
A) Using examples describe classes and objects and explain the relationship between them.
B) Explain how information hiding is implemented in Object Oriented programming and why it is used.
Thanks in advance.
Many questions sound like homework and i think that we are not permitted to do someone's else hw :/
Re: New to Java some questions
Its not actually homework, there revision questions which i needed help for.
Thanks alot for your help, appreciate it.
Re: New to Java some questions