Programming Basics Flashcards

1
Q

How to output “ Hello World “ in CMD using Java?

A

public class Filename >1
{ >2
public static void main ( String[]args ) >3
{ >4
System.out.println(“Hello World”); >5
} >6
} >7

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

What does the world public mean in the first line of Java ?

A
  • A keyword of Java language that indicates that the element that follows should be made available to other Java elements.
  • Other class can also use it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the curly brackets ( {} ) do in 2nd line and the last line?

A
  • Everything that are included in the curly brackets belongs to the class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the word void mean ?

A
  • To indicate that no value is returned
  • To let the program just run the program and return nothing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does static mean ?

A
  • To run the method without calling on the class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does String [] args mean ?

A
  • It is a parameter list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why it was not advisable to create identifiers using the Java Keywords

A
  • May lead to confusion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Java most concerned about ?

A

Case Sensitive
- for to For , it will be printing error

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

The most important programming tips

A
  1. Remember to semicolon ( ; )
  2. Remember to check if there is any word that are being written in Uppercase Letters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Java Keywords also known as

A

Reserved words

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

Statements format ( 5 )

A

1.Declaration Statement
- int i ;
- String name ;

  1. Assignment Statement
    • i = 42 ;
    • name = “ ADI “
  2. Declaration + Assignment
    • int i = 42
    • String name = “ ADI “
  3. Expression Statement
    • System.out.println(“Hello World”)
  4. Many other more
    • for
    • if
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Statement must type semicolon ( ; ) after finishing

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

How can you create a block ?

A
  1. Using brace { }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Do we need to add semicolon after creating a block ?

A

No

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

Which is correct?
1. int Total
= 100;
2. int Total = 100;

A

Both are correct

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

What are double and float different ?

A
  1. double - to represent double-precision 64-bit floating-point numbers
  2. float - To represent single-precision 32-bit floating-point numbers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to create a comment?

A
  1. Type // ( End-of-line Comments )
  2. Type /* */ ( Traditional Comments )
  3. ( Java DOC Comment )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

All identifiers must begin with what?

A

Letter ( a , d , A)

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

What are the differences of state and behavior in Java?

A
  1. Consist data that the object might be keeping track of.
  2. Consists actions that the object can perform.
20
Q

Key Principles of OOP

A
  1. Encapsulation
    - Encapsulation is the bundling of data (attributes) and methods (functions) that operate on the data into a single unit, known as a class.
  2. Abstraction
    - Abstraction involves simplifying complex systems by modeling classes based on the essential properties and behaviors they share.
  3. Inheritance
    - Inheritance is a mechanism that allows a new class (subclass or derived class) to inherit the properties and behaviors of an existing class (superclass or base class).
  4. Polymorphism
    - Polymorphism allows objects of different classes to be treated as objects of a common superclass.

( PIEA )

21
Q

What are usually used for variable names in Java ?

A

Camel case ( myClass1Object )

22
Q

How to create another class

A
  1. Create a new class in a different file
  2. Then in the main file type :
    Greater ( Another class file name ) myGreeterObject ( Hold the objects in the Greeter file ) = new Greeter(); ( Create new objects )
23
Q

Variable must start with what first?

A
  1. Letter ( m,k,l ,small letter first [ camel case ] )
  2. Underscore ( _ )
  3. Dollar Sign ( $ )
24
Q

What are class variable also known as?

A

Static Variables

25
Q

What are the rules that the static variables follow?

A
  1. Must place within the class but not in the method ( Start of the code or the End )
  2. Must include the word static ( static int newNum = 5 )
26
Q

What is a static variables ?

A

Variable that can be shared among the class

27
Q

What is the usage of instance variables ?

A

To create us own class

28
Q

All Variable

A
  1. Static Variable ( Outside of the method )
  2. Instance Variable ( Outside of the method )
  3. Local Variable ( Inside of the method )
  4. Final Variable ( Outside / Inside of the method )
29
Q

What are the difference about Static and Local Variable?

A
  1. Static can put Above or Below the code
  2. Local must put Above the code
30
Q

What is a Final Variable ?

A

The value can’t change after being initialized

31
Q

How to add a Final Variable ?

A

Add a final word ( final int radius = 3.1415 )

32
Q

Which variables a given default values ?

A
  1. Static Variable
  2. Instance Variable
33
Q

All integer types

A
  1. byte ( -128 to 127 )
  2. short ( -32,768 to 32,767 )
  3. int ( -2,000,000,000 to 2,000,000,000 )
  4. long ( -9,000,000,000,000 to 9,000,000,000,000 )
34
Q

Why there are so many integer types?

A

To save up some memory

35
Q

How to make values easier to read ?

A

Putting underscore ( 58_473_882 )

36
Q

All Floating-point types

A
  1. float ( F at the back )
  2. double ( D at the back )
37
Q

All Character types

A
  1. char ( Uses ‘ ‘ )
  2. String ( Uses “ “)
38
Q

What does var do in Java ?

A
  1. Decide the value is what type of data by itself
39
Q

Why is string is written in Uppercase Letters ( String ) than other variable ( int , boolean )?

A

Because string isn’t primitive types, it was a reference types and it was the name provided by the Java API class

40
Q

How to combine two strings?

A

Adding a + sign

41
Q

How to convert an integer to string ?

A

Use the code Integer.toString() ( String s = Integer.toString (x); )

42
Q

How to convert a string to primitives value ?

A
  1. int x = Integer.parseInt ( “ 100 “ )
  2. short x = Short.parseShort ( “ 100 “ )
  3. double x = Double.parseDouble ( “ 19.01 “ )
  4. boolean x = Boolean.parseBoolean ( “ true “ )
43
Q

What are convert numeric data of one type to another called ? ( int to double )

A
  1. Casting
44
Q

How to input data using JOptionPane?

A

String priceDialog;
priceDialog = JOptionPane.showInputDialog(“Please enter the price of the goods : “);
double goodsPrice = Double.parseDouble(priceDialog);

45
Q

How to input data from Terminal?

A

static Scanner sc = new Scanner(System.in)
System.out.print(“Please enter the price of the goods : “);
double goodsPrice = sc.nextDouble();

46
Q
A