Terms Flashcards
(72 cards)
Casting
Assigning a value of one type to a variable of another type is known as Type Casting.
public class Test { public static void main(String[] args) { int i = 100; long l = i; //no explicit type casting required float f = l; //no explicit type casting required System.out.println("Int value "+i); System.out.println("Long value "+l); System.out.println("Float value "+f); }
} Output: Int value 100 Long value 100 Float value 100.0 https://www.studytonight.com/java/type-casting-in-java
Truncation
Cutting off the digits to the right of a decimal point.
i.e.
double div = 5/2;
System.out.println(div) = 2
In order to print out “2.5” you would need to make div = 5.0/2, 5/2.0, or 5.0/2.0.
A thread (multithreading)
A thread is a subset of a process. An example of a process is Google Chrome and a thread would be a tab. A thread shares the same address as its parent process.
https://www.youtube.com/watch?v=b5sj13Z7aho
What does “static” do?
\+It creates an element that's independent of any object When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object. -https://www.geeksforgeeks.org/static-keyword-java/
What does “public” do?
It creates a class element that other classes can use.
Overloaded method
Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists are different. It is similar to constructor overloading in Java, that allows a class to have more than one constructor having different argument lists. Method overloading is an example of Static Polymorphism.
https://beginnersbook.com/2013/05/constructor-overloading/
Overloaded constructor
+Like methods, we can overload constructors for creating objects in different ways. Compiler differentiates constructors on the basis of numbers of parameters, types of the parameters and order of the parameters.
-https://www.geeksforgeeks.org/constructors-in-java/
+Sometimes there is a need of initializing an object in different ways. This can be done using constructor overloading. For example, Thread class has 8 types of constructors. If we do not want to specify anything about a thread then we can simply use default constructor of Thread class, however if we need to specify thread name, then we may call the parameterized constructor of Thread class with a String args like this:
Thread t= new Thread (“ MyThread “);
https://beginnersbook.com/2013/05/constructor-overloading/
What does “IDE” stand for?
Integrated Development Environment
What does an IDE do?
An IDE is a set of tools that helps you create software programs. It provides an editor, a compiler, a debugger, and other tools.
What is “source code”?
The programs that we write in text are called source code. (This is true of any programming language, not just Java.). But whatever text editor a programmer uses, the product is the same: Java source code.
Describe a “compiler”
A compiler translates the source code you’ve written into a form that a computer can understand. In many cases, this is a string of ones and zeroes.
POJO
Pojo: Plain Old Java Object is a Java object not bound by any restriction other than those forced by the Java Language Specification. I.e., a POJO should not have to
Extend prespecified classes
Implement prespecified interface
Contain prespecified annotations
What is POJO, Bean, Normal Class in easy language?
Normal Class: A Java class
Java Beans:
All properties private (use getters/setters)
A public no-argument constructor
Implements Serializable.
Pojo: Plain Old Java Object is a Java object not bound by any restriction other than those forced by the Java Language Specification. I.e., a POJO should not have to
Extend prespecified classes
Implement prespecified interface
Contain prespecified annotations
What is Java’s API?
The Application Program Interface, a list of all Java’s classes and their public properties.
What does the Java keyword static do?
It creates a class element that’s independent of any object.
How does Java’s do-while loop work?
It executes its group of statements at least once, and it repeats them long as its condition is met.
What’s the difference between declaring instance variables and local variables in a Java program?
You declare instance variables at the start of a class, but you declare local variables inside methods.
Constructor
A constructor constructs an instance of a class.
https://wecancodeit.github.io/java-slides/objects/constructors/#/9
Constructors are used to initialize the object’s state.
https://www.geeksforgeeks.org/constructors-in-java/
The job of a constructor is to construct an object. A constructor’s name is the same as the name of the type of thing it’s constructing:
https://wecancodeit.github.io/java-slides/fundamentals/reading-console-input/#/4
Arrays vs. Array List
-The capacity of an Array is fixed.
Where as, ArrayList can increase and decrease size dynamically.
-An Array is a collection of similar items.
Where as, ArrayList can hold item of different types.
-Array is in the System namespace.
Where as, ArrayList is in the System.Collections namespace.
-An Array can have multiple dimensions.
Where as, ArrayList always has exactly one dimension.
-We can set the lower bound of an Array.
Where as, the lower bound of an ArrayList is always zero.
-Array is faster and that is because ArrayList uses a fixed amount of array.
However when you add an element to the ArrayList and it overflows. It creates a new Array and copies every element from the old one to the new one.
You will only feel this if you add to often.
-Since the add from ArrayList is O(n) and the add to the Array is O(1).
However because ArrayList uses an Array is faster to search O(1) in it than normal lists O(n
https://www.codeproject.com/Questions/394625/Which-is-better-array-ArrayList-or-List-in-terms-o
Maps
A map is a construct that allows us to pair keys and values. Map is a parameterized type.
https://wecancodeit.github.io/java-slides/objects/maps/#/1
List
characterized by being ordered. May contain duplicate elements.
elements are unordered. Elements must be unique.
Set
Elements are unordered. Elements must be unique.
https://wecancodeit.github.io/java-slides/objects/maps/#/6
APIE
[ A ] bstraction
[ P ] olymporphism
[ I ] nheritance
[ E ] ncapsulation
Encapsulation
+Encapsulation at its simplest is hiding away information that isn’t necessary to share. The more knowledge we have about an object, the more complex our problem solving becomes.
-https://wecancodeit.github.io/java-slides/objects/a-pie/#/11