0% found this document useful (0 votes)
27 views10 pages

Java Programming Basics and Concepts

The document discusses various aspects of Java programming, including the use of import directives, inheritance, and the differences between Java and C/C++. It outlines different types of applications (console-based, desktop, and web-based), the three editions of Java (Java SE, Java EE, and Java ME), and the internal workings of the Java Virtual Machine (JVM). Additionally, it covers basic Java programming elements, memory areas in JVM, and methods in the Object class.

Uploaded by

Mohit Gangwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views10 pages

Java Programming Basics and Concepts

The document discusses various aspects of Java programming, including the use of import directives, inheritance, and the differences between Java and C/C++. It outlines different types of applications (console-based, desktop, and web-based), the three editions of Java (Java SE, Java EE, and Java ME), and the internal workings of the Java Virtual Machine (JVM). Additionally, it covers basic Java programming elements, memory areas in JVM, and methods in the Object class.

Uploaded by

Mohit Gangwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

​ hen we use the import, the class which is required that should be​

W
​only imported​
​Processor Directives #include​ ​#include​
​#include​
​#define #define​
​#import​
​These two directives are being support by c These​
​two directives are being support by c++ These two are not​
​supported by java​
​if we are using #include and #define, we are importing each and every​
​class which is present in some particular package. It will increase the​
​burdern on the compiler. So it is not a good practice. so in c and c++​
​we have to use the two processor directives but in java we can select​
​a particular class that needs to be imported which reduces the stress​
​on the compiler.​

I​nheritance means, acquiring the properties of one class into another​


​class​
​Inheritance Not supported in C, it is supported in C++, in java , it is​
​supported. Java does not support multiple inheritance​
​pointers pointers are supported by c and c++. In java it is being​
​eliminated and it is being replaced by references.​
​Pointers causes the issue of memory leaks so to overcome this java​
​as eliminated the pointers​

-​ -------------Day12 21st July----------------​


​When joining the company we have three types of application​
​1) console based application​
​2) Desktop or stand alone applications​
​3) web-based application​
​ ) console based systems​
1
​the machine tha is being used by the bus conductors that type of​
​machine is known as console based systems. it doesn't have pointer​
​like a mouse. Just a small keypad to give the ticket​

t​o make such aaplications we must know the following technologies​


​Core java + SQL + Embedded systems​
​Today it is deprecated. As a fresher, No new projects are being done.​
​User just maintain the existing projects​

​ ) Desktop applications/Stand alone application​


2
​Such projects works on the local machine.​
​They take some space from your overall screen. For example​
​Calculator.​
​The following technologies should be known Core Java [Applets,​
​AWT, Swings ======> GUI] + SQL​

​ ) Web-Based Application​
3
​Such projects involve servers​
​the ui is displayed on the browsers​

​ echnologies that should be known Core Java + Advance Java​


T
​[JDBC, Servlets, JSP] + Frameworks [Spring] + UI[HTML, CSS,​
​Javascript, Angular 14, react, bootstrap etc] + SQL [MySQL, Oracle] +​
​Dev-ops​

​ here are three editions of java​


T
​1) java Standard Edition (Java SE) Contains Libraries and packages​
​- Also known as J2SE or java 2 standard edition​
​- Referred to as the Core Java Software​
​- Used in building applets or desktop applications​
​ ) Java Enterprise Edition (Java EE) Creating Web Applications​
2
​- Also Known as J2EE or java 2 Enterprise Edition​
​- Used to build server side applications​

​ ) Java Micro Edition (java ME) Creating Mobile and small devices​
3
​application​
​- Also known as java 2 micro edition​
​- used in building applications for wireless devices such as mobile​
​phones and PDAs​

​ yntax of the abstract method​


S
​access-modifier keyword (abstract) return type method-name();​

​ ifference between normal method and abstract method​


d
​for normal methods, there will be method body, but for the abstract​
​method there will be no method body​
​Inside interface by default there are abstract methods​

​ asic java programming elements​


B
​package - Class​
​- Interface​
​- Enum​
​Class - Inside class, we can write variables, we can write methods,​
​and we can write variables inside method​
​Interface - Inside interface we can write variables, we can write​
​methods, but we cannot write variables inside methods. since​
​methods inside inside interface are abstract and abstract method don't​
​have method body​
​Enum - Inside enum, we can write variables, we can write methods,​
​and we can write variables inside method.​
​ nderstanding JVM​
U
​Q) What happens internally if we are compiling and running the java​
​program ?​
​--> to run the java program, it involves two steps compilation and​
​running the java program​
​first we compile the program what does it mean ? during compilation​
​we check whethere our java program is correct according to the​
​syntax of the java language and if it is correct a .classFile is​
​generated. the generated dot classfile consist of byte code instructions​
​which is difficult for the humans to understand. it can be only​
​understand by the machines and in our scenario it is jvm (Java virtual​
​machine).​
​the command for compiling the java program is javac [Link]​
​now what is running ? running is done by the jvm. It take the​
​generated dot classFile as input and checks whether everything is​
​good or not and gives the output if everyting is correct if it is not good​
​then we will get error​

​java is platform independent but jvm is platform dependent​

​-------------------------Day 13 22nd july—------------------------​

​Internal architecture of JVM​


​Class Loader​
​Class Loader will perform 3 operations Loading, Linking and​
​initialization​
​Linking​​- suppose there are two classes classA and​​classB both​
​are present in the same package, and we want to call the​
​method which is present in classA, in classB we can call that​
​method inside the main method which is present in classB. Now​
​to use classA method in classB, classA should be present if it is​
​not there then we will get an error. So there is a linkage between​
​class A and class B. that linking is handled by the class Loader.​
​Loading​​- when we want to run a java program we perform​​2​
​steps compilation and running, when we compile the java​
​program using the command javac [Link] if everything is​
​perfect, a dot classFile is generated and that file we gave to​
​ VM, But before giving it to JVM, that file gets load into class​
J
​Loader and this part is handled by the Loader. Loading inside the​
​loading process linking checks the linkage between the any class​
​present or not some normal checks releatedto linking is done by​
​linking.​
​Initialization -​​there are three types of variables​​static,instance​
​and local. The memory for the static variables is initialized​
​whenever we are compiling the program. The memory for​
​instance and local variable is initialized when we are running the​
​program. This function is also performed by the class loader.​
​Class Area​
​Heap Area​
​Stack Area​
​PC - Registers​
​Native Method Stack​
​Execution Engine - Interpreter and garbage collector​

​ ) How many memory areas are there in JVM ?​


Q
​-> there are 5 memory memory areas in JVM​
​1)​​Class Area​
​2)​​Heap Area​
​3)​​Stack Area​
​4)​​PC Registers​
​5)​​Native method stack​
​Class Area​​- Inside class area we store meta data​​about the class​
​Heap Area​​- Every java object will be created inside​​the heap area.​
​Inside the Heap memory there is a special memory known as SCP​
​(String Constant Pool)​
​Stack area​​- whenever we are executing a method, that​​method​
​requires some temporary memory to store the data in results, that​
​temporary memory will be allocated in the stack area​
​Consider the following example​
I​nt a =20;​
​Int b = 10;​
​Int c =20 + (a+B)​
​Now 20 will store in a, 10 will store in b, 20+(a+b) will store in c and​
​(a+b) will be stored in stack area.​
​It allocates temporary memory which is needed by the java methods​
​to store their data and results.​
​PC Registers (Program Counter Registers) -​​It maintains​​log files​
​which thread is executing at a particular point of time.​
​What are native method ?​
​The methods which are not written in java but those are used in java​
​they are known as native methods. For example all the method written​
​in applets​
​Such methods are stored in​​Native method Stack.​

​ xecution Engine​​has two components​​Interpreter​ ​and​​Garbage​


E
​Collector​
​Interpreter -​​This component reads the byte code instructions​​present​
​in the dot class file and executes them in the sequential manner.​
​Garbage Collector -​​GC is going to destroy all the​​unused or​
​unreferenced objects from the heap memory.​

-​ ------Day 14 and Day 15 videos are not available--------​


​Object Class​
​Inheritance - acquiring the properties of one class into another. We will​
​use the key word extends. But we do ot require for the object class​
​because by default it acts as a parent class for all the classes.​
​Object class act as a first class in the hierarchy of java classes​
​TODO​
​Object class​
​Basics of inheritance​
​—---Day 16 no class—--​
​ --Day 17 27th july—----------​

​Some methods which are present in object class​
​hashCode(), equals(), toString(), getClass(), finalize() these 5 methods​
​will be covered in today’s class​

​ ait(), notify(), and noifyAll() these methods are used to communicate​


w
​between threads. This concept is known as​​interthread​
​communications​

I​nside heap area we cannot get the address of the object. Objects live​
​inside heap memory and heap memory lives inside the JVM and full​
​form of JVM is java virtual machine i.e it is a virtual machine we​
​cannot get the address of the object.​
​hashCode() gives the unique identification number for the object to​
​distinguish objects​

​ quals():​​It is boolean method, which checks the address​​locations of​


e
​two objects. If both the objects are present in the same location,​
​equals() will return true, If they are different locations then equals()​
​method will return false.​

​ etClass():​​It is used to get the fully qualified​​class name. For eg. to​
g
​find method1 bleongs to which class we will uset the​
​[Link]()​

t​ oString():​​It is used to convert the object into​​String represented​


​format.​
​ hat is the difference between final, finally, finalize​
W
​Basic idea of garbage collector​
​Garbage collector will destroy all unused or unreferenced objects from​
​the heap area.​
​To call the garbage collector we can use he following method​
​[Link]​​().​

I​f garbage collector is being called in your program then internally​


​finalize method will be called​

​ --------------------------------Day 18​

​—---------------------------------------------------​

​ bject​
O
​Objects are created from the class.​
​We can create any number of objects in a class.​
​To create an class object, we need to use​​new​​keyword​​and initialize​
​that object with the help of a​​constructor.​​(Constructor​​name should​
​same as class name).​

​ ariable​
V
​A variable provides identity to a memory location by using variables,​
​we can process the information easily.​
​ClassA, meth1(), a, aobj all these are known as identifiers​

​Naming conventions of an identifier​


​1)​​A Java identifier can start wit​
​a)​​A to Z​
​b)​​a to z​
​c)​​$ of _​
​2)​​A java identifier never starts with a number. But we can any​
​number combination between 0 and 9 in the name of an​
​identifier.​
​3)​​We can use only two symbols as identifier names [$ and _ ]​
​other special characters are invalid.​
​4)​​There should not be any space between the names of an​
​identifier.​
​5)​​Java is case sensitive, so int a=10 and int A=20 both are​
​different.​

You might also like