Java Test Review PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document contains a Java test review covering various programming concepts. This includes questions about variable types, loops (for, while, and do-while), arrays, input/output from files, and Java Virtual Machines (JVM).
Full Transcript
Java Test Review Explain all the following concepts in your own words. Include chunks of java code when applicable. 1.) What is Java? Who created it? Why is it so popular? What was it originally called? - Java is a popular programming language, created in 1995 by Sun Microsystems...
Java Test Review Explain all the following concepts in your own words. Include chunks of java code when applicable. 1.) What is Java? Who created it? Why is it so popular? What was it originally called? - Java is a popular programming language, created in 1995 by Sun Microsystems - Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) - It is one of the most popular programming language in the world - It has a large demand in the current job market - It is easy to learn and simple to use - It is open-source and free - It is secure, fast and powerful - It has a huge community support (tens of millions of developers) - Java is an object oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs - As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or vice versa - The operating system in Java is responsible for executing the bytecode (.class file) thus any program in Java will run on any operating system that supports java 2.) What is JVM? What is Java IDE? What do these stand for? -JVM is a virtual machine that enables the execution of Java bytecode. (Java virtual machine) -integrated development environment (IDE) is a software application that helps programmers develop software code efficiently 3.) What are some everyday applications that were created/use Java? - Android os - Google - Spotify - Netflix 4.) What are all the variable types in Java? What type of values can be stored in these? - String - stores text, such as "Hello". String values are surrounded by double quotes - int - stores integers (whole numbers), without decimals, such as 123 or -123 - float - stores floating point numbers, with decimals, such as 19.99 or -19.99 - double - stores BIGGER floating point numbers, with decimals than float - char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes - boolean - stores values with two states: true or false 5.) How do you comment in Java? - Using // for a single line - Start with to make a multiple line comment 6.) How do you correctly output strings, numbers and variable? Give some coding examples. - You would have to add the name to your string/variable/number - Then println(string/number/variable); 7.) How would you output a line of text and variables within the same line of code? - System.out.println(“______” + x ) 8.) What are if statements? Else if’s? How are they used in Java? - If statements are blocks that execute a command only when a specified condition is true. - Else if statements are blocks that are used if the if statement is false and is only executed if the else statement condition is true. 9.) What was the purpose of using args in our pizza programs? How does this work? - To store data in a string like manner - This works by adding the data into the run with args menu. 10.) What are the three types of loops that we have used in Java? Show what the code would look like for each. - for (initialization; condition; update) { // code to be executed For loop for (int i = 0; i < 5; i++) { System.out.println("i is: " + i); - while (condition) { // code to be executed int i = 0; while (i < 5) { System.out.println("i is: " + i); i++; - do { // code to be executed } while (condition); int i = 0; do { System.out.println("i is: " + i); i++; } while (i < 5); } } 11.) What is an array? When would you want to use one in a program? - An array is a data structure that allows you to store a collection of elements of the same type, like numbers or strings, under a single variable name. It allows you to organize and manage data efficiently. 12.) Explain how we read from text files and how we write to text files. What specific lines of code must be included to perform these tasks? - - In java we can import text files to either have the computer read the file or we can make it print on that file using the input file code and output file code