Lesson 1: Introduction To The Java Language Flashcards

1
Q

Who invented java، what company، year، and what was it originally called?

A

Java was conceived by James Gosling (lead)، Patrick Naughton، Chris Warth، Ed Frank، and Mike Sheridan at Sun Microsystems in 1991. This language was initially called “Oak” but was renamed “Java” in 1995.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What was the original purpose of Java? Why?

A

The primary motivation was the need for a platform-independent language that could be used to create software to be embedded in various consumer electronic devices، such as toasters، microwave ovens، and remote controls. The trouble was that (at the time) most computer languages were designed to be compiled into machine code that was targeted for a specific type of CPU.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What cause was secondary but more important in the development of popularity in Java programming?

A

About the time that the details of Java were being worked out، a second، and ultimately more important، factor emerged that would play a crucial role in the future of Java. This second force was، of course، the World Wide Web.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In laymans terms، what are portable programs?

A

portable (platform-independent) programs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What two coding languages does java descend from?

A

The two languages that form Java’s closest ancestors are C and C++

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does Java inherit from C and what in C++? Why is it’s close tie with these two languages so important in it’s popularity development?

A

From C، Java inherits its syntax. Java’s object model is adapted from C++. Java’s relationship to C and C++ is important for a number of reasons. First، at the time of Java’s creation، many programmers were familiar with the C/C++ syntax. Because Java uses a similar syntax، it was relatively easy for a C/C++ programmer to learn Java. This made it possible for Java to be readily utilized by the pool of existing programmers، thus facilitating Java’s acceptance by the programming community

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why is Java not the internet version of C++?

A

Java is not simply the “Internet version of C++.” Java has significant practical and philosophical differences from C++. Furthermore، Java is not an enhanced version of C++. For example، it is neither upwardly nor downwardly compatible with C++. Moreover، Java was not designed to replace C++. Java was designed to solve a certain set of problems. C++ was designed to solve a different set of problems. They will coexist for many years to come.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How did Java simplify web-based programming?

A

Java simplified web-based programming in a number of ways. Arguably the most important is found in its ability to create portable، cross-platform programs. Of nearly equal importance is Java’s support for networking. Its library of ready-to-use functionality enabled programmers to easily write programs that accessed or made use of the Internet. It also provided mechanisms that enabled programs to be readily delivered over the Internet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are applets and what is their key feature?

A

An applet is a special kind of Java program that is designed to be transmitted over the Internet and automatically executed inside a Java-compatible web browser. If the user clicks a link that contains an applet، the applet will download and run in the browser automatically. Applets were intended to be small programs، typically used to display data provided by the server، handle user input، or provide simple functions، such as a loan calculator. The key feature of applets is that they execute locally، rather than on the server. In essence، the applet allowed some functionality to be moved from the server to the client.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What two broad object categories can transmitted between server and client? Where do applets fit in?

A

In general، there are two very broad categories of objects that are transmitted between the server and the client: passive information and dynamic active programs. For example، when you read your e-mail، you are viewing passive data. Even when you download a program، the program’s code is still only passive data until you execute it. By contrast، the applet is a dynamic، self-executing program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does C# relate to java?

A

A few years after the creation of Java، Microsoft developed the C# language. This is important because C# is closely related to Java. In fact، many of C#’s features directly parallel Java. Both Java and C# share the same general C++-style syntax، support distributed programming، and utilize a similar object model. There are، of course، differences between Java and C#، but the overall “look and feel” of these languages is very similar.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In layman’s terms، how is Java safe if its programs self-execute?

A

Java achieved protection by enabling you to confine an application to the Java execution environment and prevent it from accessing other parts of the computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are bytecode، JVM، and JRE and how do they work together?

A

Bytecode is a highly optimized set of instructions designed to be executed by what is called the Java Virtual Machine (JVM)، which is part of the Java Runtime Environment (JRE). In essence، the original JVM was designed as an interpreter for bytecode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the sandbox?

A

Because the JVM is in control، it manages program execution. Thus، it is possible for the JVM to create a restricted execution environment، called the sandbox، that contains the program، preventing unrestricted access to the machine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why is Java not slower than other compilers running executable code?

A

When a program is interpreted، it generally runs slower than the same program would run if compiled to executable code. However، with Java، the differential between the two is not so great. Because bytecode has been highly optimized، the use of bytecode enables the JVM to execute programs much faster than you might expect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the HotSpot JVM and what is a JIT compiler?

A

there is nothing about Java that prevents on-the-fly compilation of bytecode into native code in order to boost performance. For this reason، the HotSpot JVM was introduced not long after Java’s initial release. HotSpot includes a just-in-time (JIT) compiler for bytecode. When a JIT compiler is part of the JVM، selected portions of bytecode are compiled into executable code in real time on a piece-by-piece demand basis. That is، a JIT compiler compiles code as it is needed during execution. Furthermore، not all sequences of bytecode are compiled—only those that will benefit from compilation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are Java servlets?

A

A Java servlet is a small program that executes on a server. Servlets dynamically extend the functionality of a web server. It is helpful to understand that as useful as client-side applications can be، they are just one half of the client/server equation. Not long after the initial release of Java، it became obvious that Java would also be useful on the server side.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Why are applets not viable? What JDK started it’s replacement and which one fully replaced it?

A

Applets rely on a Java browser plug-in. Thus، for an applet to work، it must be supported by the browser. Simply put، without browser support، applets are not viable. Because of this، beginning with JDK 9، the phase-out of applets was begun، with support for applets being deprecated. In the language of Java، deprecated means that a feature is still available but flagged as obsolete. Thus، a deprecated feature should not be used for new code. The phase-out became complete with the release of JDK 11 because support for applets was removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is Java Web Start and how is it different than an applet?

A

Called Java Web Start، it enabled an application to be dynamically downloaded from a web page. It was a deployment mechanism that was especially useful for larger Java applications that were not appropriate for applets. The difference between an applet and a Web Start application is that a Web Start application runs on its own، not inside the browser. Beginning with JDK 11، support for Java Web Start has been removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What tool was deployed in JDK 9 and replaces applets and Java Web Start?

A

Given that neither applets nor Java Web Start are viable options for modern versions of Java، you might wonder what mechanism should be used to deploy a Java application. At the time of this writing، one part of the answer is to use the jlink tool added by JDK 9. It can create a complete run-time image that includes all necessary support for your program، including the JRE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are major Java releases called and what does increased release cadence allow?

A

Each major release، now called a feature release، will include those features ready at the time of the release. This increased release cadence enables new features and enhancements to be available to Java programmers in a timely fashion. Furthermore، it allows Java to respond quickly to the demands of an ever-changing programming environment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What decade was structured programming popularized like C and Pascal? What characterizes a structured language?

A

The 1960s gave birth to structured programming. This is the method encouraged by languages such as C and Pascal. Structured languages are characterized by their support for stand-alone subroutines، local variables، rich control constructs، and their lack of reliance upon the GOTO.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

In a very general sense، how can a program be classified based on its organization? How does oop factor into this?

A

In the most general sense، a program can be organized in one of two ways: around its code (what is happening) or around its data (what is being affected). Using only structured programming techniques، programs are typically organized around code. This approach can be thought of as “code acting on data.” Object-oriented programs work the other way around. They are organized around data، with the key principle being “data controlling access to code.” In an object-oriented language، you define the data and the routines that are permitted to act on that data. Thus، a data type defines precisely what sort of operations can be applied to that data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What three traits do all OOP languages have in common?

A

All OOP languages، including Java، have three traits in common: encapsulation، polymorphism، and inheritance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is encapsulation، a black box، and how do these work to make an object?

A

Encapsulation is a programming mechanism that binds together code and the data it manipulates، and that keeps both safe from outside interference and misuse. In an object-oriented language، code and data can be bound together in such a way that a self-contained black box is created. Within the box are all necessary data and code. When code and data are Page 11linked together in this fashion، an object is created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What does it mean to have private and public data in an object? When are they used?

A

Within an object، code، data، or both may be private to that object or public. Private code or data is known to and accessible by only another part of the object. That is، private code or data cannot be accessed by a piece of the program that exists outside the object. When code or data is public، other parts of your program can access it even though it is defined within an object. Typically، the public parts of an object are used to provide a controlled interface to the private elements of the object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

How are classes used in Java in very basic terms?

A

The code and data that constitute a class are called members of the class. Specifically، the data defined by the class are referred to as member variables or instance variables. The code that operates on that data is referred to as member methods or just methods. Method is Java’s term for a subroutine.

28
Q

What are members in Java? methods?

A

The code and data that constitute a class are called members of the class. Specifically، the data defined by the class are referred to as member variables or instance variables. The code that operates on that data is referred to as member methods or just methods. Method is Java’s term for a subroutine.

29
Q

What is polymorphism in programming?

A

Polymorphism (from Greek، meaning “many forms”) is the quality that allows one interface to access a general class of actions. A simple example of polymorphism is found in the steering wheel of an automobile. The steering wheel (i.e.، the interface) is the same no matter what type of actual steering mechanism is used. Therefore، once you know how to operate the steering wheel، you can drive any type of car. More generally، the concept of polymorphism is often expressed by the phrase “one interface، multiple methods.” This means that it is possible to design a generic interface to a group of related activities.

30
Q

If polymorphism’s job is to specify a general class of action، what determines the specific actions?

A

Polymorphism helps reduce complexity by allowing the same interface to be used to specify a general class of action. It is the compiler’s job to select the specific action (i.e.، method) as it applies to each situation.

31
Q

What is inheritance in programming?

A

Inheritance is the process by which one object can acquire the properties of another object. This is important because it supports the concept of hierarchical classification. If you think about it، most knowledge is made manageable by hierarchical (i.e.، top-down) classifications. For example، a Red Delicious apple is part of the classification apple، which in turn is part of the fruit class، which is under the larger class food.

32
Q

What does IDE stand for and what is it?

A

Interactive Development Environment (IDE). Basically، a windowed program that allows you to develop code

33
Q

How would you write a very basic program that output “Java drives the web.”?

A

/* This is a simple Java program */ class Example { // A Java program begins with a call to main(). public static void main(String args[]) { System.out.println(“Java drives the web.”); } }

34
Q

What is the official title of a source file in Java? What filename extension does it use?

A

In Java، a source file is officially called a compilation unit. It is a text file that contains (among other things) one or more class definitions. (For now، we will be using source files that contain only one class.) The Java compiler requires that a source file use the .java filename extension.

35
Q

If the name of your Java code file is “ExampleForScrubs”، what will the name of the main class be?

A

In Java، all code must reside inside a class. By convention، the name of the main class should match the name of the file that holds the program. You should also make sure that the capitalization of the filename matches the class name.

36
Q

What is a comment in java and how do you make a multi-lined comment?

A

Like most other programming languages، Java lets you enter a remark into a program’s source file. The contents of a comment are ignored by the compiler. Instead، a comment describes or explains the operation of the program to anyone who is reading its source code. called a multiline comment. This type of comment must begin with /* and end with */.

37
Q

How do you make a single-line comment and when is it used as opposed to a multi-lined one?

A

A single-line comment begins with a // and ends at the end of the line. As a general rule، programmers use multiline comments for longer remarks and single-line comments for brief، line-by-line descriptions.

38
Q

In java، what is a subroutine called?

A

in Java، a subroutine is called a method.

39
Q

What are access modifiers? How are the two keywords “public” and “private” related?

A

The public keyword is an access modifier. An access modifier determines how other parts of the program can access the members of the class. When a class member is preceded by public، then that member can be accessed by code outside the class in which it is declared. (The opposite of public is private، which prevents a member from being used by code defined outside of its class.)

40
Q

How does the static keyword affect main()? What about void?

A

The keyword static allows main( ) to be called before an object of the class has been created. This is necessary because main( ) is called by the JVM before any objects are made. The keyword void simply tells the compiler that main( ) does not return a value.

41
Q

What are parameters in Java and when do you need them?

A

Any information that you need to pass to a method is received by variables specified within the set of parentheses that follow the name of the method. These variables are called parameters. If no parameters are required for a given method، you still need to include the empty parentheses.

42
Q

What does the args parameter do?

A

a parameter named args. This is an array of objects of type String. (Arrays are collections of similar objects.) Objects of type String store sequences of characters. In this case، args receives any command-line arguments present when the program is executed.

43
Q

What method is used to display general output?

A

Output is actually accomplished by the built-in println( ) method. A side note: its printLn but must be all lowercase

44
Q

How do the class “System” and the output stream “out” work together?

A

System is a predefined class that provides access to the system، and out is the output stream that is connected to the console. Thus، System.out is an object that encapsulates console output.

45
Q

What are variables in Java?

A

A variable is a named memory location that can be assigned a value. Further، the value of a variable can be changed during the execution of a program. That is، the content of a variable is changeable، not fixed.

46
Q

What type of data can a variable hold if it’s declared as an integer? How do you do that?

A

These are whole number values. In Java، to declare a variable to be of type integer، precede its name with the keyword int.

47
Q

Generally speaking، how do you declare a variable?

A

In general، to declare a variable you will use a statement like this: type var-name; Here، type specifies the type of variable being declared، and var-name is the name of the variable.

48
Q

How can you chain items together in a println statement?

A

Using the + operator، you can chain together as many items as you want within a single println( ) statement.

49
Q

What is the difference between the print() method and the println() method?

A

The print( ) method is just like println( )، except that it does not output a new line after each call.

50
Q

How can you declare multiple variables using one declaration statement?

A

It is possible to declare two or more variables using the same declaration statement. Just separate their names by commas.

51
Q

What two data types are used for fractional values? Which one is used more and how do you declare it?

A

Fortunately، int is only one of several data types defined by Java. To allow numbers with fractional components، Java defines two floating-point types: float and double، which represent single- and double-precision values، respectively. Of the two، double is the most commonly used. To declare a variable of type double، use a statement similar to that shown here: double x;

52
Q

How can you add a black line in the output in java?

A

To print a blank line، simply call println( ) without any arguments.

53
Q

How do if statements work in Java? What are boolean expressions?

A

if(condition) statement; Here، condition is a Boolean expression. (A Boolean expression is one that evaluates to either true or false.) If condition is true، then the statement is executed. If condition is false، then the statement is bypassed.

54
Q

What are the 6 operators for conditional expressions and their meaning?

A

Java defines a full complement of relational operators that may be used in a conditional expression. They are shown here: < | less than <= | less than or equal > | greater than >= | greater than or equal == | equal to. != | not equal

55
Q

How would you write a code that uses if statements that evaluates weather a variable is positive or negative?

A

/* Demonstrates the if statement */ class IfDemo { public static void main(String[] args) { int a، b، c; a = 2; b = 3; if(a < b) System.out.println(“a is less than b”); //This wont display anything if(a == b) System.out.println(“a equals b”); System.out.println(); c = a - b; //sets c to -1 System.out.println(“c equals a minus b، currently -1”); if(c >= 0) System.out.println(“C is positive”); if(c < 0) System.out.println(“C is negative”); System.out.println(); c = b - a; //c is now 1 System.out.println(“C now equals b minus a، currently 1”); if(c >= 0) System.out.println(“C is positive”); if(c < 0) System.out.println(“C is negative”); } }

56
Q

What is the general format of a for loop in Java?

A

for(initialization; condition; iteration) statement; In its most common form، the initialization portion of the loop sets a loop control variable to an initial value. The condition is a Boolean expression that tests the loop control variable. If the outcome of that test is true، statement executes and the for loop continues to iterate. If it is false، the loop terminates. The iteration expression determines how the loop control variable is changed each time the loop iterates.

57
Q

How would you make a for loop code that counts to 5?

A

package fordemo; /* Demonstration of the for loop */ class ForDemo { public static void main(String args[]) { int count; for(count = 0; count < 5; count = count+1) //Sets the count to zero then makes the loop iterate five times. Could you count++ System.out.println(“This is count: “ + count); System.out.println(“Done!”); } }

58
Q

Why is writing (count=count+1;) in Java unnecessary? What replaces the (=count+1;) part?

A

Java includes a special increment operator that performs this operation more efficiently. The increment operator is ++ (that is، two plus signs back to back). The increment operator increases its operand by one.

59
Q

What is the operator that decreases the operand by 1?

A

Java also provides a decrement operator، which is specified as – –. This operator decreases its operand by one.

60
Q

What are code blocks and how are they started in Java?

A

Another key element of Java is the code block. A code block is a grouping of two or more statements. This is done by enclosing the statements between opening and closing curly braces. Once a block of code has been created، it becomes a logical unit that can be used any place that a single statement can.

61
Q

What does a block of code in an if statement look like in an if statement?

A

package blockdemo; class BlockDemo { public static void main(String args[]) { double i، j، d; i = 5; j = 10; //the target of this if is a block if(i != 0) { System.out.println(“i does not equal zero”); d = j / i; System.out.println(“j / i is “ + d); } } }

62
Q

Do code blocks make the code run slower? How are “{“ and “}” seen in the source code?

A

No. Code blocks do not add any overhead whatsoever. In fact، because of their ability to simplify the coding of certain algorithms، their use generally increases speed and efficiency. Also، the { and } exist only in your program’s source code. Java does not، per se، execute the { or }.

63
Q

What do semicolons do in Java?

A

In Java، the semicolon is a separator. It is often used to terminate a statement. In essence، the semicolon indicates the end of one logical entity.

64
Q

What is a free-form language?

A

Java is a free-form language، meaning that it does not matter where you place statements relative to each other on a line.

65
Q

What are the general rules for naming a variable?

A

Variable names may start with any letter of the alphabet، an underscore، or a dollar sign. Next may be either a letter، a digit، a dollar sign، or an underscore.