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

Java Operators and Static Concepts Explained

The document outlines various Java programming concepts over a series of days, including operators, control statements, static keywords, and collections. It emphasizes the importance of understanding static variables, methods, and blocks, as well as the differences between instance and static methods. Additionally, it discusses the concept of auto boxing and unboxing in relation to wrapper classes and collections, along with the organization of Java packages.

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)
4 views10 pages

Java Operators and Static Concepts Explained

The document outlines various Java programming concepts over a series of days, including operators, control statements, static keywords, and collections. It emphasizes the importance of understanding static variables, methods, and blocks, as well as the differences between instance and static methods. Additionally, it discusses the concept of auto boxing and unboxing in relation to wrapper classes and collections, along with the organization of Java packages.

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

​—---------------Day 26 6th august—------------​

​ ava operators​
J
​Pre increment and post increment operators​
​Refer google for it nothing great as such​
​—------------Day 27 8th august—-----------------​

​ rithmetic Operators​
A
​Refer google for it nothing great as such​
​And control statements​

​—-----------Day 28 9th august—-----------​


​ elational operators​
R
​Refer karsi sir notes or google​

​Understanding static key word​


​ tatic keyword is mainly used for memory management in java. We can​
S
​use use static in three ways. A variable can be declared as static, a method​
​can be declared as static and a block can be declared as static.​
​Static Variable​
​1)​ ​A variable which is declared inside a class outside any method , block​
​or a constructor with the help of static keyword.​
​2)​ ​Static variables will be initialized at the time of class loading.​
​3)​ ​We can access a static variable in three ways.​
​a)​ ​By using identifier name​
​b)​ ​By using class object​
​c)​ ​By using directly class name​
​4)​ ​A static variable can never be declared as a local variable.​
​5)​ ​There will be only one copy of the static variable available in the​
​entire program.​

​ ---------------Day 29 —---------------------------​

​Static Method:​
​Static keyword is also used for all the common properties of the class​
​1)​ ​A method which is declared as static is known as static method​
​2)​ ​We can call a static method in three ways​
​a)​ ​By using identifier name​
​b)​ ​By using class object​
​c)​ ​By directly using class name​
​3)​ ​We can access a non static variable inside a static method, but​
​with the help of it’s class object. We cannot access a non static​
​variable with the help of its identifier in a static method.​
​Instance Method VS Static Method​

​1)​ I​n instance method we can access the instance variable with the​
​help of its identifier but in static method we cannot access the​
​instance method with its identifier we have to create an object of that​
​class to access the instance variable in the static method​
​2)​ ​Staic method can be called in three ways method name, by creating​
​an object of the class and call it and directly with the help of class​
​name. But instance method can be called with the help of the class​
​object only​

​Static Block​
I​n a java program if there are static blocks present (As shown in the​
​image), the program will executes the static block first then the main block​
​will be executed.​
​Otherwise if static block is not present then the main method will always​
​executed.​

​ e can write any number of static programs in the program but we cannot​
W
​call them They will be executed in the order in which they are written.​

​ ithout writing the main method can we print hello world​


W
​Ans is yes with the help of static block​​NOTE​ ​It​​was possible to write​
​before java 1.5 but in the latest versions of java we have to write the main​
​method.​

​1)​ ​In our java program if we are having a main method and a static​
​block, then the first priority will be given to static block​
​2)​ ​We can write any number of static blocks in our program they will​
​executed in the defined order​
​3)​ ​We cannot call static block​
​4)​ ​Before java 1.5 version we can print hello world statement by using​
​the static block but after java 1.5 it is mandatory to write the main​
​method in the program​
​5)​ ​For final static variables jvm will not provide the default values it is the​
​responsibility if the programmer to initialize it. I can initialize the final​
​static variable at the declaration or inside the static block, apart from​
​hat we will get an error​
​For Final static variables JVM will not provide any default values it is​
​the responsibility of the programmer to initialize them whether we are​
​using them or not. A final static variable can be initialized at the time​
​of declaration or we can initialize it inside a static block anywhere​
​else we will get compile time error.​

​ ----------------------------Day 30—-------------------------​

​Static block and static variable will have the same priority.​
​They will be executed in the defined order (even before the main method)​
​If in java program, there is a static variable and a main method then static​
​variable will be executed then the main method​

​ ------------------Day 31—-----------------​

​Type casting​
​Refer Karsi Sire notes​

​ ------------Day 32—--------------------​

​Wrapper Classes​
​For every primitive data type there are individual wrapper classes.​
​Array- It collects multiple elements of the similar data type in a continuous​
​block of memory​
​DrawBacks of array -​
​1)​ ​Its length is fixed.​
​2)​ ​It collects only homogenous data​
​3)​ ​There is no method support​
​These drawbacks can be overcome by the concept of collection framework​
​Collection framework means set of classes.​
​1)​ ​ArrayList​
​2)​ ​Linkedlist​
​3)​ ​Vector​
​4)​ ​Hashset​
​ )​ ​LinkedHashset​
5
​6)​ ​Treeset​
​7)​ ​PriorityQueue​
​8)​ ​HashMap​
​9)​ ​TreeMap etc…​
​All these are predefined package defined in [Link] package.​
​All these classes combined known as collection framework​

​These are the common topics that are asked in the interview​

​Collection classes will only accept objects they will not accept datatypes​

​ ince there are drawbacks of array such as fixed length, homogenous​


S
​data, and no methods available. The concept of collections came into the​
​picture. Collection is nothing but group of classes (ArrayList, Linkedlist,​
​Vector, Hashset etc) but condition is the collection classes accept the​
​objects and not data​​[Link]​​we need to convert the​​data types into its​
​respective classes objects/ wrapper class object and pass it to the​
​collections​

​ he Process of converting datatype into its respective class object​


T
​(Wrapper) is known as​​Auto Boxing​
​The process of converting class object (Wrapper ) into its respective data​
​type, it is known as​​Auto Unboxing​
​ uto Boxing and Auto Unboxing​ ​is different fromm​​type casting. In type​
A
​casting, we can convert from one data type into a different datatype but in​
​Auto Boxing and Auto Unboxing​​we can convert between​​the same​
​datatype only.(data Type —------ class object (Wrapper) )​

​ uto Boxing and Auto Unboxing​​was introduced in java​​1.5x version,​


A
​upto java 1.9 we have to convert manually data type into class object, but​
​after java 1.9 the data type is automatically coneverts into class object​
​when pass in collection​

​1)​ ​In java technology, if we want to represent a group of objects in the​


​form of an object we have to use collections like Likedlist, hashset,​
​ArrayList etc..​
​2)​ ​In java application, collection objects are able to allow only group of​
​other objects, not primitive data types directly.​
​3)​ ​If we want to store primitive data types in collection object then first​
​we need to convert the primitive data int object form then we have to​
​store that object data in collection classes.​
​4)​ ​For 8 primitive data types there are 8 wrapper classes​

​ ------------------------------Day 33—----------------​

​For project purposes,​​Auto Boxing and Auto Unboxing​​is not important​
​but for interview perspective it is important to know​

I​n every wrapper class there is a method valueOf.​


​Some properties fo valueOf method​

​ )​ ​It is a static method. It is called using the class name​


1
​2)​ ​It is a parametrized method. It will accept only one parameter​
​3)​ ​If the valueOf method is called by Integer , then it valueOf will accept​
​int data type. Same for other wrapper class. These methods can​
​accept string as well but in the string we have to pass only numbers​
​and not the characters.​
​4)​ ​Only character wrapper class will not accept string in the static​
​method valueOf()​

​ ---------------------Day 34—---------------------​

​Control statements. Refer Karsi sir notes​
​ ---------------------------Day 35—--------------------------​

​Control Statements. Refer Karsi sir notes​

​ ---------------Day 36—-------------------------​

​Control Statements Refer karsi sir notes​
​—--------------Day 37—-------------------​
​Control Statements Refer karsi sir notes​
​—-----------------------Day 38 22nd august—-------------​
​Control Statements Refer Karsi sir Notes loops​
​—-------------Day 39 23rd august—--------------------​
​Control statements Refer karsi sir notes​
​—--------------Day 40 24th august—-------------------​

​Control statements jump statements. Refer karsi sir notes​

​ -------------------Day 41 25th august —---------------------​



​About Scanner Class. Refer Karsi sir notes.​
​ ----------------Day 42 26th august—-----------------​

​Understanding java packages​
​1)​ ​A package consist of similar types of classes, Interfaces, ENUM and​
​sub packages​
​2)​ ​Package helps programmers easily organize the java files​
​3)​ ​In java there are two types of packages​
​a)​ ​Pre defined​
​b)​ ​User defined packages​
​4)​ ​In java there are 5000 predefined packages​
​5)​ ​[Link] package will acutomticaly imported​
​6)​ ​Package statement will be the 1st statement in every java program​
​7)​ ​We can access the members of a class which is present in the same​
​package withou importing​
​Basic hai pura​
​Lean from google​
​Topic packages​

You might also like