Ficool

Jujustu Kaisen BUT I have A Gardevoir??

Yuuuma
14
chs / week
The average realized release rate over the past 30 days is 14 chs / week.
--
NOT RATINGS
1.5k
Views
Synopsis
A twenty-seven-year-old ordinary man found himself transported to a world teeming with Cursed Spirits, reborn as the "non-existent" legitimate son and heir of the Kamo family. No Jujutsu ability, no status, unloved by his father, and uncared for by his birth mother—but none of that mattered. Because he had the "Pokémon Trainer System." I, Yuzaki Kamo, even in the world of Jujutsu Kaisen, will become a legend. I will completely change the millennium-old, rotten structure of the Jujutsu world. ⟪⟫⟪⟫⟪⟫⟪⟫⟪⟫⟪⟫⟪⟫ [Patreon] Get advance chapters on Patreon/Yuuma046 [Discord] https://discord.gg/K8t8xyAFXT
VIEW MORE

Chapter 1 - word filler

Propaganda, that "purposeful publicity is the official arm of the imperceptible government." This can be seen most unmistakably in the advanced police state and the developing native nark culture, enveloped with the pseudo-enthusiastic War on Terror. The expanding union of media has empowered the whole corporate structure to converge with government, which currently uses the idea of promulgation arrangement. Media; print, motion pictures, TV, and link news would now be able to work flawlessly to incorporate a general message which appears to have the ring of truth since it originates from such a significant number of sources, at the same time. When one moves toward becoming sensitive to recognizing the fundamental "message," one will see this engraving all over. What's more, this isn't even to specify subliminal informing. 3. Prescient Programming – Many still deny that prescient writing computer programs is genuine. Prescient programming has its causes in predominately elitist Hollywood, where the big screen can offer a major vision of where society is going. Simply glance back at the books and motion pictures which you thought were implausible, or "sci-fi" and investigate society today. For a nitty gritty breakdown of explicit models, Vigilant Citizen is an incredible asset that will most likely make you take a gander at "amusement" in a totally unique light. 4. Sports, Politics, Religion – Some may resent seeing religion, or even legislative issues, put together with sports as a technique for mind control. The focal topic is the equivalent all through: isolate and prevail. The systems are very straightforward: impede common propensity of individuals to participate for their endurance, and train them to frame groups bowed on control and winning. Sports has consistently had a job as a key diversion that corrals innate propensities into a non-significant occasion, which in present day America has arrived at silly extents where challenges will break out over a game VIP leaving their city, yet basic human issues, for example, freedom are chuckled away as immaterial. 5. Food, Water, and Air – Additives, poisons, and other nourishment harms actually modify mind science to make mildness and indifference. Fluoride in drinking water has been demonstrated to bring down IQ; Aspartame and MSG are excitotoxins which energize synapses until they kick the bucket; and simple access to the inexpensive food that contains these toxins by and large has made a populace that needs center and inspiration for a functioning way of life. The vast majority of the cutting edge world is flawlessly prepped for uninvolved responsiveness — and acknowledgment — of the authoritarian tip top. 6. Medications — we can equate this to any addictive substance, however the mission of mind controllers is to be certain you are dependent on something. One noteworthy arm of the cutting edge mind control motivation is psychiatry, which expects to characterize all individuals by their issue, instead of their human potential. This was foreshadowed in books, for example, Brave New World. Today, it has been taken to considerably assist limits as a medicinal oppression has grabbed hold where about everybody has a type of confusion — especially the individuals who question authority. The utilization of nerve tranquilizes in the military has prompted record quantities of suicides. To top it all off, the cutting edge medication state currently has over 25% of U.S. youngsters on mind-desensitizing drugs. 7. Military testing — There is a long history associated to the military as the proving ground for mind control. The military personality is maybe the most pliable, as the individuals who seek after life in the military by and large resound to the structures of progression, control, and the requirement for unchallenged submission to a mission. For the expanding number of military individual scrutinizing their influence, an ongoing story featured DARPA's arrangements for trans cranial mind control head protectors that will keep them centered. 8. Electromagnetic range — An electromagnetic soup encompasses all of us, charged by present day gadgets of comfort which have been appeared to directly affect mind work. In an implicit affirmation of what is conceivable, one scientist has been working with a "divine being head protector" to instigate dreams by adjusting the electromagnetic field of the mind. Our advanced soup has us latently washed by conceivably mind-changing waves, while a wide scope of potential outcomes, for example, phone towers is currently accessible to the eventual personality controller for more straightforward mediation. Mind control is more common than most people think. It is not easy to detect because of its subtle nature. In many instances, it happens under what is perceived as normal circumstances like through education, religion, TV programs, advertisements and so much more. Cults and their leadership use mind control to influence their members and control whatever they do. It is not easy to detect mind control. However, when one realizes it, they can get out and start afresh. Chapter 8: The Secrets of Neuro Linguistic Programming Neuro-Linguistic Programming or NLP, as it is commonly referred to, is one of the most prevalent systems of mind control in the entire universe. It is applied by nearly everyone from politicians to marketers to media personalities, and it is very nasty to its main cores. John Grinder and Richard Bandler invented this famous method of mind control in the 1970s. It would later gain much popularity in the new age, occult, and psychoanalytic spaces back in the 1980s. Later on, in the 1990s and 2000s, NLP started to make inroads in the political, marketing, as the advertising markets. Over time, it has become so interwoven with the manner at which people are communicated to and even marketed. It is also very crucial to note that NLP has, to some extent, become a type of devilish and pernicious force in the entire global space, which has been studied by nearly everybody in the business spheres. Those who have mastered the techniques of this great dark psychology trait are known for owning a Rasputin-like capability of tricking persons into some incredible ways, nearly at all times. Neuro-Linguistic Programming is used today for a variety of different things. It can be helpful in helping people overcome issues like anxiety, PTSD, and fears. These are only a very few issues that Neuro-Linguistic Programming can help with. While some people use it for good, others use it for darker desires. We would love to say that the only place you will find NLP is in your therapist's office, however, we actually see it in everyday life. From your workplace to the ads on your social media accounts, you can actually see it everywhere. NLP does not only focus on what people say but more importantly focus on what people are doing. Our body language says more than our mouths ever could. NLP has been under the debate of whether it is an actual science or if it is considered a pseudoscience. The debate still exists today, and it is hard to pinpoint this science due to the fact that it has not gone through the same rigorous testing as therapies such as CBT, Cognitive Behavioral Therapy . There is a pretty broad range of techniques used within NLP and this also makes it difficult to lock down which pieces actually work. There have been some studies performed and oftentimes the results were inconclusive. In some it appears as if NLP had made a true improvement in subjects with psychosis, instability, and other unwanted traits. Others worked on looking at its effectiveness to help issues like PTSD and anxiety. The results came back exceptionally varied. Neuro-Linguistic Programming has been around for more than forty years. For something to be around this long and continue to be used throughout many people's daily lives means there has got to be some validity to it, right? We see it used so widely on a commercial level and it certainly does have an impact. It also has its place in the world of Psychology and Dark Psychology. Due to the fact that it is quite unstructured it is difficult to show true proof of its success. There are also a plethora of different idea and ways of executing NLP. For some, it is a very effective form of therapy that truly helps them lead better lives. For others, it may not benefit them at all. These people will need to look at more traditional therapies to work through their issues and lead a happier and mentally healthier life. NLP History NLP is, in a way, a method of mind control. It was developed by a team of people. However, the majority of the credit is given to, two California boys, John Grinder and Richard Bandler. In the 1970's, they decided to combine the works of Virginia Satir, a therapist for families, Friedrich Perls, a psychotherapist, and a hypnotherapist by the name of Milton Erickson. They wanted to take the heart of linguistic therapy and improve it. Find the pieces that truly worked and make something better. The three people that they studied were chosen due to the fact that they had better results with their clients than most others in their field. In fact, people found their success to be odd and uncommon. Naturally, inquisitive minds wanted to know what these people had in common and why their methods worked so well. They studied them in live sessions and via video tape . NLP is subtle. When we think about normal hypnotherapy, we think about people falling asleep and acting out strange and silly acts. Realistically, it is used for much more meaningful purposes. For example, people use hypnotherapy to help them stop smoking or to deal with traumas of the past that may have not been coped with. NLP does things a bit differently. It is much more suggestive and not so in your face. In the beginning, Neuro-Linguistic Programming was thought to be as helpful as products like "snake juice" from the days of the old west. However, as the seventies turned into the eighties it became more and more accepted. Businesses were jumping on the bandwagon to learn about it so they could, in turn, use it to help them gain profits from consumers. In addition, everyone from therapists to political figures started to want the information on this type of "programming". It seriously started to blow up in terms of popularity. Companies became interested in NLP because it can help them communicate more clearly. This helps to improve the performance of employees and the overall performance of the business. Businesses that use NLP have experienced better growth in their companies as a whole. Not only can it help people become better negotiators it can also help them stay motivated. When you feel comfortable at work and you feel like everyone is giving it their all, it's easy to build a solid team. Being a confident leader that pays attention to tone, body language, and verbiage will help lead to better success. Implementing the practices of NLP can promote growth for companies. As people started to employ these tactics, they started to notice changes in their teams. Boosts in morale and productivity. Now we see NLP happening around us every day. This is not necessarily a bad thing as people that practice NLP tend to be more self-aware. In turn, they tend to make better choices that are made from rationality rather than emotions . Pillars of NLP There are four main points to NLP, they are referred to as the Pillars of NLP. They are Behavioral Flexibility, Rapport, Outcome Thinking, and Sensory Awareness. Each one is of equal importance as the others. Taking the time to look briefly at each one of these points gives a better understanding of NPL as a whole and how it can help you weed out the fakers in your life. The first pillar is Behavioral Flexibility. Basically, this means to go with the flow. When people can see that the tactic they are currently using isn't working and adapt their behavior it can have great results. Being able to quickly change your perspective will allow more people to understand you. The next aspect we are going to look at is Rapport. Creating a good rapport with someone is simply getting them to trust you quickly. In addition, it is the ability to form quick relationships with people. It is easy to build rapport by using common language, being polite, and showing empathy. There are many ways to build a good rapport with a person, these are only a few. Then we move on to Outcome Thinking. It is exactly what it states, spending the time to think about the end result of what you want. Oftentimes, people get stuck on a certain point that is commonly negative. It consumes the thought pattern and can make choosing the correct route to where you actually want to go difficult. With outcome thinking you are always working toward an end goal. This can promote better decision making along the way. Lastly, we have Sensory Awareness. Being aware of the surroundings contributes to knowing what is actually going on. When you walk into a public place and you take notice of the tone of the room, the colors surrounding you, the groups of people, it can be very enlightening. It can also help you easily understand how you need to behave in that situation. The more you learn about these four pillars the more success you will have with NLP. They are the foundation and anyone who wants to learn NLP will spend a lot of time on each one. Gaining more knowledgeable helps you apply what you have learned to your daily life and the more protected you will be from the ones that want to manipulate you, control you, or cause other burdens in your life. NLP has grown and changed over the years. What started out as focusing on what people's eyes were doing, the words they choose to use, and building quick rapport, turned into something much, much more. All sciences grow and change over the course of time and we imagine that this one will also continue to evolve. After focusing on what the yes were doing, word choice, and rapport this therapy started to grow and focus on other aspects. In the 80's, the people using NLP were focusing on what it is that causes feelings inside of us. This helped therapists to figure out how to help someone deal with their individual problems. More and more people started using the techniques found with NLP but they wanted to put different names to it. To say they had come up with it all on their own. When it comes down to it, no matter what you call it, NLP is the same across the globe. Today, it is used not only to help you have control and choices in how you react, but it can also help you figure out what other people are up to. The people in the here and now that are using NLP have a variety of different reasons for doing it. Some of it is to help themselves become better people while for others it is about weeding out the rats in their lives. Businesses use it in team building and marketing techniques. Here again, we can see how vast the world of Neuro-Linguistic Programming really is. It has been said that people who study Neuro-Linguistic Programming live freely. They have the ability to access all different types of situations and make choices in how they choose to proceed instead of being led by instinct and emotion. How you think, feel, behave, and speak can all be choices you make that can help you lead the best life possible. NLP can be used throughout your daily life in a huge variety of ways. Some common reasons that people start using this are that they want to motivate other people, have control over their emotions, conquer their fears, communicate more effectively, and find success in life. There are many other reasons a person would take an interest in NLP . If you are unsure of who you can trust in your crowd NLP can seriously help. Understanding behaviors and actions of people can help to clue you in on what's really going on around you. This falls into Sensory Awareness. It is startling what you can learn from looking at someone's body position and paying attention to things like their tone of voice. People really do tell you everything you need to know with very little conversation. Whether you are at your job or heading for a late-night party downtown honing these skills can keep you mentally and physically protected against predators. Knowing NLP techniques can also inform you when other people are using it for darker desires. Many people use these practices to become their best selves, however, others have more nefarious intent. Obviously, when you can adapt in a situation and make well-thought out choices you are going to be more successful. There is less of a chance that people will be able to take advantage of you. In addition, you will be able to better understand the people in your life. Weeding out the keepers from the trash is simpler when you can read the situation accurately and adjust so that you are working toward your desired outcome. How Does it Work? NLP may seem like enchantment or spellbinding. During treatment the subject dives deep into their oblivious personality and filters through layers and layers of convictions and discernments to wind up mindful of an involvement in early youth that is in charge of a standard of conduct. NLP takes a shot at the rule that everybody has every one of the assets they have to roll out positive improvements in their very own life. NLP strategies are utilized as a device to encourage these changes. NLP Therapy can be sans substance. That implies the specialist can be viable without thinking about the issue in incredible detail. Consequently the specialist need not be told about the occasion or even the issue, in this manner guaranteeing protection for the customer. Other than this we likewise have a non- exposure understanding in which the communication between the customer and the advisor is kept secret. NLP puts stock in flawlessness of nature in human creation. Henceforth NLP urges the customer to perceive their tangible sensitivities and use them to react to a specific issue. Indeed, NLP additionally accepts that the brain is fit for finding even fixes to illnesses and infections. NLP procedures include noninvasive, medication free treatment that enables the customer to find better approaches for managing enthusiastic issues, for example, low confidence, uneasiness, absence of certainty, ruinous relationship designs (adapting to separation), and are fruitful inadequate mourning guiding. NLP has its underlying foundations in the field of social science, created by Pavlov, Skinner and Thorndike. It utilizes physiology and the oblivious personality to change points of view and consequently conduct. NLP is simply the investigation of astounding correspondence both with yourself, and with others. It was created by demonstrating astounding communicators and advisors who got results with their customers. NLP is a lot of instruments and methods, yet it is far beyond that. It is a demeanor and an approach of realizing how to accomplish your objectives and get results. Dark Traits of Manipulative People Among the groups of the Dark Triad there is a conglomeration of personality traits that are oftentimes, seen in criminals. It is not a surprise to realize that most criminals have quite a bit in common. Taking notice to these dark traits is a great way of figuring out if someone has malicious intent toward you or not. There are a variety of different dark traits that we see on an everyday basis. You may know someone who is very spiteful. Anyone that does something they don't like will pay for it. Sometimes it will be petty retaliation, but it can explode into something much more dangerous, depending on who you are dealing with. Criminals tend to be spiteful, as they have malicious intent with their transgressions. Another dark trait that you want to watch out for is egoism. When someone is so self-absorbed and focused on their own achievements that they will run everyone else around them into the ground, it is a major problem. Some criminals scramble their way to the top because of their giant egos and their ability to only care about themselves. Keeping an eye on a big ego can save you a lot of trouble, especially in relationships and business. Have you ever met someone that had loose morals? You know that person that really doesn't have much regard for if what they are doing is right or wrong. Someone that even when they know what they are doing is wrong, does it anyway, and then just laugh it off. This is a personality trait referred to as moral disengagement. Obviously, the ability to commit a crime and not feel terrible about it is something common among criminals a pretty dark trait. Earlier we discussed Machiavellianism. That person that will go to any means to get what they want. They are the ones that are the masters of manipulation. The justification for what they are doing is always solid. When trying to track down criminals these are some of the hardest to catch as they tend to also be some of the smartest out there. Even experts of NLP can have a hard time locking this trait down. Entitlement or Psychological Entitlement are also dark traits that we commonly see in criminals and everyday adversaries. Unfortunately, the world's sense of entitlement has gone off the rails. Nowadays, it is natural to meet people that have a sense of entitlement and this can make it difficult to use this trait in determining somebody's true intent. Self-interest is another trait that you need to watch out for. We all have tendencies to be selfish, however, for some people it is to an extreme. They simply do not care what other people feel or want. This is commonly seen by people boasting about how much money they have or their status. In addition, their self-interest could be used to motivate them in gaining betterment in finances or society. Those that are self-interested also tend to be extremely manipulative. Then we have the narcissist. We spoke of the narcissist earlier, but their traits are very common among criminals. They have a need for attention and commonly and inflated sense of self. They will go to great extremes to prove that they are better than those that are around them. This could be in how they look, how they think, or how they act. The narcissist thinks that their ideas are the best and therefore criminal intent goes hand-in-hand with the narcissist. Psychopathy means that you are lacking in the ability to empathize with people. They have an extreme lack of concern where others are involved. This dark trait can also lead to a lack of self-control and extremely impulsive behaviors. Obviously, when thinking about criminals, this trait rings true for many of the extreme horrors we have witnessed in the past. The last dark trait that we think needs to be discussed is sadism. A sadist is a person that likes to inflict pain. In fact, they take pleasure in causing other people pain. This does not necessarily have to be physical pain. In fact, many sadists find joy and completely tearing you down mentally. A wide variety of criminal classes fall into this category and it is a common trait that we see in many of the people that are committing heinous crimes. Behavior Imitation Behavior imitation is something that can be used for good and for bad. Oftentimes, as children, we mimic the behavior of the people around us. It helps us to learn social norms. In addition, it helps us feel like we fit in to the crowd. Many traditions have been built off of people mimicking other people's behavior. As we continue to grow up, we continue to imitate people around us. Here again, it makes us feel as if we belong. Additionally, it can help us build relationships and understand the people around us more easily. While, many people use behavior imitation for the right reasons there are many others who don't. Criminals who are socially awkward have a tendency of acting like the people around them. It can make it harder to discern the good guys from the bad guys. It is a manipulation tactic that works quite well when people don't exactly know how to behave appropriately. While some people are very good at mimicking those around them it will be quite obvious when others are trying to do this. Cases of extreme social awkwardness will not allow the person to genuinely behave like those that are around them. This can be a tip to seeing what they may have planned next. Another way that behavior imitation is prevalent with criminals is when they idolize someone or something. They will change their very persona to reflect that of which they have admiration for. A good example of this are people that still follow the ideals of Adolf Hitler. The new generation of Nazis mimic the ways of old because they still believe his blasphemous thoughts to be true. This is truly scary behavior imitation . Body Language A person's body language is one of the biggest tells in how they are feeling and what they may be planning. The way a person moves and behaves while in a conversation, out in public, and at home gives great insight to what's happening with them at that particular moment. Those who work on learning NLP techniques spend a ton of time studying about body language. Body language is how we speak without using words. It can suggest that you are happy, sad, open to conversation, or completely closed off from everyone. Not only is it shown through your actual body but also through your eyes. Paying attention to the eyes is also an important part of NLP. There are some truths to be found in body language that may not be what the words coming out of someone's mouth are actually stating. It has been found that we gather more information from a person's facial expressions, eyes, and body language than we ever could from their spoken words. So, learning how to read body language can help you in just about every situation you find yourself in. Learning how shady people act can help you in avoiding unwanted issues. When you first start learning about body language, you will be able to easily identify some emotions. Obviously, we all know what it looks like when a person is happy or sad. The signs of this can be seen easily but finding out when someone is anxious or uncomfortable can be a bit more difficult. Studying non-verbal cues will take you to every area of the body. For example, slightly dilated pupils may not be from a bright light but may in fact be due to arousal. If someone is constantly biting at their lip it could be a sign of stalling or higher levels of anxiety in the current situation. How a person is standing or sitting also gives us some clues as to how they are feeling. A person with their arms folded around them is less likely to want to be approached. Whereas, an open stance with your hands on your hips means you are likely in control of the situation or you may be aggressive. Learning these types of things can seriously help improve your ability to pick out a troublemaker in a crowd . Ever been in an area and realized someone was acting kind of shifty? You know, like moving around the room frequently and during conversations they are unable to hold eye-contact. Your ability to notice these this is because most people have at least some basic knowledge on how to read a person's body language. Your posture also plays a key role in what your body is saying to other people. People who slouch and tend to wrap their arms around themselves are typical closed off. They may be feeling unwelcome or anxious. On the other hand, an open posture with your chin up and shoulders back is very welcoming. It shows that you are open to conversation, friendly, and approachable. Not only does your body language help people decide how to approach you, theirs helps you decide about them. There is a plethora of different aspects to be considered with body language. The more you delve into NLP, the more pieces of body language you will pick up. It can seriously help when trying to identify those that are threatening and may have mal intent. Language Imitation Language imitation is another piece of NLP that should be taken into consideration. When we talk to someone, even if we speak the same language, it can be difficult for us to understand each other. Each individual has what is referred to as common language. Common language is simply the words a person uses frequently and understand better than others. When you are in a therapy session or at work and you are listening to someone talk, understanding what they are saying can be hard. It can feel as if they are speaking in a different language. This doesn't work well for anyone as the person listening is actually learning anything. This is a major issue and can cause massive detriment to a company or a person's mental status. Working to hear how someone talks, the phrases they use, and the tone that they have can help you succeed in language imitation. When you can speak in common language to the person or people you are addressing, you will be much more successful. Understanding will be promoted and what everyone gets out of what you have to say will be more beneficial. Mimicking someone's language is more difficult than mimicking their body language. The more time you spend talking with a person, the easier it will be to pick up on their vocal habits. Someone that is very good at picking up other people's common language can be a danger if they have intentions of doing harm. When we speak in a common language it promotes trust. Putting trust into someone that wants to use your language against you is obviously something you want to avoid. So, be careful when dealing with people that quickly change their voice to match those that are around them. The ones that pick up on little pieces of context and repeat them to gain sympathy, trust, or control. It may be hard to recognize, at first, but the more aware you become of your surrounding the easier this will be to spot. Criminals tend to be good at this parrot like behavior. They understand that to get people to like you they absolutely need to understand you. If control is what someone is looking for this is a good place to start and get their hooks in. So, while language imitation can help you and your therapist or employees relate, it can also be used to manipulate situations in favor of the person using this tactic.

Day 40: On Talking vs. Doing It is better to practice a little than talk a lot. —A Zen saying, attributed to Muso Soseki Announcing to all of your friends, family members, and colleagues that you're going to change and going deep into details how you're going to do it is useless at best and sabotaging at worst. Firstly, not everyone will be happy to hear that you want to improve yourself because it will make it painfully obvious that they're lazy or don't have as much courage as you do. Instead of support, you can receive criticism that might make you less likely to act upon your dreams. Secondly, research suggests that announcing your plans makes you less motivated to accomplish them. 38 By talking about your plans, you get the erroneous satisfaction that you've already taken action to change yourself and consequently, you're less likely to take real action. If you want to tell your friends about your new goal, choose a person whom you know will support you. In addition, instead of telling them in a self-congratulatory way that you're finally going to achieve your dreams, ask them to hold you accountable if you don't honor your resolution. Day 41: On Arroganc e Receive wealth or prosperity without arrogance; and be ready to let it go. —Marcus Aurelius 39 Never take self-discipline for granted or assume that if you can control your urges, you're now invincible. Humility plays an important role in helping you maintain self- control. An arrogant person will be more likely to unnecessarily test their willpower, which will eventually lead to their downfall. This happens because of the restraint bias — the tendency for people to overestimate how capable they are of controlling impulsive behaviors. Research shows that people who had an inflated belief in their self-control overexposed themselves to temptations, such as recovering smokers putting themselves in situations tempting them to smoke, which increased the risk of a relapse. 40 Assume that your self-discipline is like prosperity. It's possible that it will stay with you for a long time, but it's also possible that it will disappear. Consequently, you'll work harder to keep it in your life. If it does go away when you make some mistakes, you'll accept it with more tranquility and be more likely to regain it quickly. Day 42: On Diligent Practice You can know how to win through strategy with the long sword, but it cannot be clearly explained in writing. You must practise diligently in order to understand how to win. —Miyamoto Musashi 41 Reading hundreds of books, blog posts, articles, and watching countless videos on self-discipline isn't going to automatically reprogram your brain so that one day you'll wake up with the self- control of a samurai. The intention behind this book is to offer you quick, interesting tidbits related to self-discipline that you can easily act upon. No matter how detailed my writings are, you'll always learn more by taking one little action than by reading ten of my books or re-reading the same book over and over again. For example, I can tell you that the greatest amount of willpower is needed during the first few minutes of an uncomfortable task, such as taking a cold shower. Once a couple of minutes pass, your body will adapt to the challenge and it gets easier to handle. But that's just me talking. Go and actually take an ice-cold shower. Experience the wild emotions, start shivering, feel the overpowering temptation to turn on hot water, and wonder if you can last even a second longer, and then — two or three minutes later — feel your body start to relax, with the ice-cold water no longer feeling like the worst torture in the world. Then step out the shower feeling, elated that you managed to overcome your weakness of will . The next time you face an uncomfortable situation, tap into your real-world experience — not mere words read in a book — to realize that, just like with an ice-cold shower, you can adapt to this situation, as well. WEEK 7 Day 43: On Making Continuous Efforts Genius is often only the power of making continuous efforts. The line between failure and success is so fine that we scarcely know when we pass it — so fine that we are often on the line and do not know it. How many a man has thrown up his hands at a time when a little more effort, a little more patience, would have achieved success. As the tide goes clear out, so it comes clear in. In business sometimes prospects may seem darkest when really they are on the turn. A little more persistence, a little more effort, and what seemed hopeless failure may turn to glorious success. There is no failure except in no longer trying. There is no defeat except from within, no really insurmountable barrier save our own inherent weakness of purpose. —Elbert Hubbard 42 I'm an avid rock climber. In rock climbing, particularly when climbing long routes, your forearms can get pumped to such an extent that you can no longer hold onto the rock. Climbers afraid of failing will often ask their belayer to take in the rope so that they can rest and try again with renewed strength. While this strategy is good for learning how to climb a difficult route, sometimes it costs a climber an on-sight (a clean ascent with no prior practice of the route) or a redpoint (completing a route without resting on the rope) because they give up too quickly, right after they start feeling overpowering discomfort . Even when you can barely hold onto the wall, often you can still perform one or two moves more — and those moves may be enough to upgrade your position to a rest stance where you can safely recharge and continue climbing without resting on the rope. It's the same with many other areas of life. You believe that you can't go on any longer, that your self-discipline has run out and it's time to throw up your hands in defeat, while in reality, persisting just a little bit longer is all that separates you from success. The next time you feel like giving up, persuade yourself to push a little bit longer. Chances are, success is right around the corner. Day 44: On Optimis m Optimism is the faith that leads to achievement; nothing can be done without hope. —Helen Keller 43 A positive attitude is essential if you want to build self-discipline. What's the point of denying yourself instant gratification if you don't believe that you'll get a greater compensation for it in the future? If you suffer from pessimism, realize that along with improving your self-control, you'll need to improve your ability to see the world in brighter colors. Three easy steps you can take today to become more optimistic include: 1. Express gratitude for what you already have. If you can't be happy with what you have today, you won't be happy with what you have tomorrow. 2. Reframe negative events into opportunities and lessons. An event is bad for you only if you decide it is. Think of it as a lesson or an opportunity to change your life, in order to give it a positive meaning. 3. Surround yourself with positive input. If you only read fear- mongering news and hang out with pessimistic grumblers, you'll have a hard time exhibiting optimism. Day 45: On Honest y I hope I shall possess firmness and virtue enough to maintain what I consider the most enviable of all titles, the character of an honest man. —George Washington 44 For many people, one of the hardest challenges for their self- discipline is the resolution to stop lying. We constantly encounter opportunities to lie, wherever we go and whatever we do. It seems it's even socially permissible to lie a little, whether by telling a white lie, making yourself look better on a resume, or tweaking your height, weight, and financial situation on online dating sites. As the old saying goes, honesty is the best policy — and it's also one of the best ways to strengthen your character. It's one thing to deny yourself a piece of cake, and it's a completely different thing to tell the truth when you think it will make you look bad or threaten the relationship you have with someone. Yet, over the long-term, the truth always emerges — and if not, it still eats away at your conscience, so why postpone the discomfort you'll eventually feel anyway? Vow to tell the truth no matter the circumstances (except for extreme situations, such as your life being in danger). Please note that being honest doesn't mean that you need to share everything about yourself with other people. that Telling them, "I don't feel like answering that question" (without giving any justifications — it's your right to not explain any of your decisions) is a simple way to remain honest when a person asks you a question you'd normally answer with a lie. Day 46: On Looking Fear in the Face You gain strength, courage and confidence by every experience in which you really stop to look fear in the face. You are able to say to yourself, "I lived through this horror. I can take the next thing that comes along." (…) You must do the thing you think you cannot do. —Eleanor Roosevelt 45 Self-discipline is a lot like dealing with fear. When you face temptations, look them straight in the eye and send them packing, the next time they appear in your life, you'll be able to say to yourself, "I managed to overcome them once. I can handle them this time as well." The more times you successfully overcome the temptations, the easier it will be to handle them again. Regular practice will make you less susceptible to temptations and even more likely to ignore them, just like looking fear in the face will make you more likely to act in spite of it. Granted, it's not that with enough experience, you'll become unconditionally self-disciplined, just like you won't one day stop being afraid of anything. Just remember that each situation that tests your resolve is another experience from which you can draw inspiration to overcome future challenging circumstances when they occur. Day 47: On the Folly of Loafing Around The loafer believes he is enjoying life, but sooner or later he must face disillusion. —Fausto Cercignani 46 Since self-discipline shines in the long term, and often doesn't seem to provide any benefits in the short term, you may be tempted to believe that people who are loafing around have it better. While you're watching your finances like a hawk, they spend money they don't have and show off with all the new cool gadgets. While you're eating a salad and washing it down with a cup of green tea, they're eating a bag of delicious potato chips and gulping down sugary cans of Coke. While you feel like throwing up during your workout from trying to to squeeze out one more rep, they squeeze more mayo out of the bottle to put it on the French fries they gorge on while watching their favorite TV shows. It might seem they have it better, but sooner or later the person exposing himself or herself to discomfort for the sake of achieving their long-term goals will come out on top, while the people loafing around will get to feel the negative consequences of their laziness. Irresponsible spenders will realize they're on the brink of bankruptcy. Potato chip addicts will be diagnosed with diabetes. The inactive TV fans will start taking hypertension medication . You, on the other hand, will look back at your past sacrifices and smile, happy that you've never succumbed to the temptation to take it easy and loaf around. Day 48: On the Deadening of the Soul Most of us dread the deadening of the body and will do anything to avoid it. About the deadening of the soul, however, we don't care one iota. —Epictetus 47 It's curious that millions of people all over the world spend countless amounts of money and time to improve their appearance through the use of cosmetics, plastic surgery, expensive clothes, supplements, and other treatments, but spend little to nothing on improving themselves on the inside. It's more important to avoid wrinkles than to prevent negative habits from forming. It's a better investment to fix your sagging cheeks than to learn how to exercise restraint in unnecessary spending. Nobody will comment or even notice your deterioration of mental toughness and a growing preference for complacency over growth, but everybody will praise you for your new clothes. $10 for a book that can change your life is too expensive. $100 for another pair of jeans is a screaming deal. Your spending habits — including spending in the monetary sense and the investment of energy or time — reveal your true priorities. How much do you spend on your external appearance, and how much do you expend on developing your inner world? Is the proportion healthy, or do you find it hard to justify spending for personal growth, but never fail to invest in your superficial appearance? Day 49: On Obeying Lusts Bad men obey their lusts as servants obey their masters. —Diogenes Laertius 48 A forbidden fruit is the sweetest. If it weren't so pleasant to submit to your urges, nobody would ever struggle with self-discipline. However, notwithstanding how much pleasure it can bring, it's important to see the temptation for what it is — your enemy on the path toward freedom. Obeying your lusts enslaves you, while rejecting them increases your freedom. The reward you'll get for not succumbing to your temptations will more than make up for the price you pay today for missing out on the instant gratification. Self-disciplined people may appear to some as if they were the ones being enslaved. After all, they're the ones whose lives are so limited: they don't get to ea

Prologue Ouzouk woke up with the first rays of sunlight hitting his face. He scanned the interior of his dusty hut, constructed with twigs, mud and dry grass. He scratched his back, which, as always, had been bitten by insects over and over again throughout the night. Grateful that the night had passed without any danger to his family, he crawled out, careful not to make any sounds. It was a crisp and clear morning. He would have loved to take his family for a walk around the waterfall and play with his little son, but there was work to do. It had been five days since the tribe ate something more substantial than a fistful of berries. Unfazed by the bloodthirsty mosquitoes buzzing by, Ouzouk walked over to the fire pit and warmed his calloused hands. The light scent of wood smoke filled his nostrils. He rubbed his hands together, still feeling the painful absence of his index finger lost during that fateful hunt many moons ago. One by one, his fellow tribesmen crawled out of their huts and joined him at the fire. There was Dhizgab, his friend who was bitten by a snake and was left partly paralyzed on his left side. Gnokk limped along next, with his broken foot badly healed, and a part of his skull partly caved in after a stone thrown by an enemy tribesman hit him smack dab in the middle of his forehead. Rekknodd sauntered into the group next. So far, he was the luckiest of the band, with only a deep scar on his cheek, left from an attack by a tiger that had massacred a half of the tribe. Other men—some missing limbs, some having lost their entire families, some with even more horrible memories—joined the group. When the men were ready, they separated into two groups and ventured out to secure food for the tribe. They made it back to the camp in the early afternoon, forced to make a hasty retreat after spotting a leopard resting in the thick bushes. Yet again, they had failed to obtain food, but at least they were grateful that (unlike two moons ago) this time nobody had been hurt. With empty stomachs, the adults gathered around the fire pit while small children, supervised by teenagers armed with spears and bows, played by the creek a short distance from the camp. They reluctantly decided that the area could no longer support them. While clean water was plentiful and predators rare, food was becoming increasingly scarce and successful hunts were few and far between. The next day they would gather their belongings, put them on their backs, and walk for a long time until they would find another suitable place for a new temporary dwelling. Some would die along the way, some would get hurt, but such was life, Ouzouk thought to himself. A human being couldn't ever stop struggling and fighting to survive each day. I can hear you thinking, "What a weird prologue to a book about self-discipline!" Bear with me, please… Our basic human nature hasn't changed since the days of Ouzouk. While the vast majority of humans fortunately no longer have to live in constant discomfort and fear of death, we would still do well to possess even a fraction of mental toughness and self- discipline our ancestors had. In the modern world, it's easy to live without even a modicum of self-discipline. Back then, nobody could avoid discomfort. It was a fact of life that one couldn't thrive unless they ventured into the world, facing unknown risks and possible death in a quest for a better life. Today, most people are unable to wake up early without an alarm clock, and even then, it takes them thirty minutes just to crawl out of bed. Most would find it impossible to sleep on the bare floor, with insects crawling over them and biting their bodies the entire night. If they experienced just a slight ache, most would skip work and complain about how much pain they were in. Most wouldn't be able to fast for an entire day, let alone go without food for five days in a row. Compared to our ancestors, we have it easy . Yet, or perhaps because of it, so many people struggle with self- discipline today. A great majority of them do nothing to fix that, and the ones who try are often met with ridicule. If you belong to the group that is trying to better themselves or wanting to do so, the book you're now reading is for you. I wrote 365 Days With Self-Discipline with the intention of creating a daily companion to help you embrace self-discipline in your everyday life. As the author of several bestselling books about self-discipline and being a personal growth junkie myself, self-control is a topic close to my heart. I believe that if a person wants to reach their full potential, he or she can't avoid discomfort. Doing things that might not be entirely pleasant is key to achieving long-term objectives. In the following pages, I'll share with you one thought for each day of a year that is devoted to the topic of self-discipline, mental toughness, success, or self-improvement in general. The thoughts come from some of the world's brightest minds: successful entrepreneurs, athletes, bestselling authors, researchers, performers, bloggers, and more. Since the entries are brief and get straight to the heart of the matter, you'll be able to quickly find ongoing inspiration to continue working on your most important long-term goals and on becoming an ever better person. Due to the large number of days in a year, some themes will inevitably repeat, but I strove to address each subtopic from different perspectives. Please note that I have quoted various people from numerous sources, including books, articles, blogs, speeches, interviews, and more. By citing their words, I don't necessarily endorse their works or their persona. (A note on quotes in the physical and ebook version of the book — whenever I could, I cited the source and included an endnote. Unfortunately, the exact source of a small number of quotes, particularly those by historic figures, was elusive to me. Whenever I couldn't find the author — as is often the case with many inspirational quotes circulating around the Internet — instead of risking misattribution I wrote "Unknown." ) Let's turn the page and start with Day 1 and the most important thought that defines the difference between a self-disciplined person and a weak-willed one.

Chapter 1. Getting Started: Compiling, Running, and Debugging 1.0 Introduction

This chapter covers some entry-level tasks that you need to know how to do before you can go on—it is said you must crawl before you can walk, and walk before you can ride a bicycle. Before you can try out anything in this book, you need to be able to compile and run your Java code, so I start there, showing several ways: the JDK way, the Integrated Development Environment (IDE) way, and the build tools (Ant, Maven, etc.) way. Another issue people run into is setting CLASSPATH correctly, so that's dealt with next. Deprecation warnings follow after that, because you're likely to encounter them in maintaining "old" Java code. The chapter ends with some general information about conditional compilation, unit testing, assertions, and debugging.

If you don't already have Java installed, you'll need to download it. Be aware that there are several different downloads. The JRE (Java Runtime Environment) is a smaller download for end users. The JDK or Java SDK download is the full development environment, which you'll want if you're going to be developing Java software.

Standard downloads for the current release of Java are available at Oracle's website.

You can sometimes find prerelease builds of the next major Java version on http://java.net. The entire (almost) JDK is maintained as an open source project, and the OpenJDK source tree is used (with changes and additions) to build the commercial and supported Oracle JDKs.

If you're already happy with your IDE, you may wish to skip some or all of this material. It's here to ensure that everybody can compile and debug their programs before we move on.

1.1 Compiling and Running Java: JDK Problem

You need to compile and run your Java program.

Solution

This is one of the few areas where your computer's operating system impinges on Java's portability, so let's get it out of the way first.

JDK

Using the command-line Java Development Kit (JDK) may be the best way to keep up with the very latest improvements in Java. Assuming you have the standard JDK installed in the standard location and/or have set its location in your PATH, you should be able to run the command-line JDK tools. Use the commands javac to compile and java to run your program (and, on Windows only, javaw to run a program without a console window). For example:

C:\javasrc>javac HelloWorld.java C:\javasrc>java HelloWorld Hello, World C:\javasrc>

If the program refers to other classes for which source is available (in the same directory) and a compiled .class file is not, javac will automatically compile it for you. Effective with Java 11, for simple programs that don't need any such co-compilation, you can combine the two operations, simply passing the Java source file to the java command:

java HelloWorld.java

As you can see from the compiler's (lack of) output, this compiler works on the Unix "no news is good news" philosophy: if a program was able to do what you asked it to, it shouldn't bother nattering at you to say that it did so. Many people use this compiler or one of its clones.

There is an optional setting called CLASSPATH, discussed in Recipe 1.4, that controls where Java looks for classes. CLASSPATH, if set, is used by both javac and java. In older versions of Java, you had to set your CLASSPATH to include ".", even to run a simple program from the current directory; this is no longer true on current Java implementations.

Sun/Oracle's javac compiler is the official reference implementation. There were several alternative open source command-line compilers, including Jikes and Kaffe but they are, for the most part, no longer actively maintained.

There have also been some Java runtime clones, including Apache Harmony, Japhar, the IBM Jikes Runtime (from the same site as Jikes), and even JNODE, a complete, standalone operating system written in Java, but since the Sun/Oracle JVM has been open-sourced (GPL), most of these projects have become unmaintained. Harmony was retired by Apache in November 2011.

Mac OS X

The JDK is pure command line. At the other end of the spectrum in terms of keyboard-versus-visual, we have the Apple Macintosh. Books have been written about how great the Mac user interface is, and I won't step into that debate. Mac OS X (Release 10.x of Mac OS) is built upon a BSD Unix (and "Mach") base. As such, it has a regular command line (the Terminal application, hidden away under /Applications/Utilities), as well as both the traditional Unix command-line tools and the graphical Mac tools. Mac OS X users can use the command-line JDK tools as above or any of the modern build tools. Compiled classes can be packaged into "clickable applications" using the Jar Packager discussed in [Link to Come]. Mac fans can use one of the many full IDE tools discussed in Recipe 1.2. Apple provides XCode as their IDE, but out of the box it isn't very Java-friendly.

GraalVM

A new VM implementation called GraalVM has just entered public release. Graal promises to offer better performance, the ability to mix-and-match programming languages, and the ability to pre-compile your Java code into executable form for a given platform. See The Graal VM web site for more information on GraalVM.

1.2 Compiling, Running, and Testing with an IDE Problem

It is cumbersome to use several tools for the various development tasks.

Solution

Use an integrated development environment (IDE), which combines editing, testing, compiling, running, debugging, and package management.

Discussion

Many programmers find that using a handful of separate tools—a text editor, a compiler, and a runner program, not to mention a debugger—is too many. An IDE integrates all of these into a single toolset with a graphical user interface. Many IDEs are available, ranging all the way up to fully integrated tools with their own compilers and virtual machines. Class browsers and other features of IDEs round out the ease-of-use feature sets of these tools. It has been argued many times whether an IDE really makes you more productive or if you just have more fun doing the same thing. However, today most developers use an IDE because of the productivity gains. Although I started as a command-line junkie, I do find that the following IDE benefits make me more productive:

Code completion

Ian's Rule here is that I never type more than three characters of any name that is known to the IDE; let the computer do the typing!

"Incremental compiling" features

Note and report compilation errors as you type, instead of waiting until you are finished typing.

Refactoring

The ability to make far-reaching yet behavior-preserving changes to a code base without having to manually edit dozens of individual files.

Beyond that, I don't plan to debate the IDE versus the command-line process; I use both modes at different times and on different projects. I'm just going to show a few examples of using a couple of the Java-based IDEs.

The three most popular Java IDEs, which run on all mainstream computing platforms and quite a few niche ones, are Eclipse, NetBeans, and IntelliJ IDEA. Eclipse is the most widely used, but the others each have a special place in the hearts and minds of some developers. If you develop for Android, the ADT has traditionally been developed for Eclipse, but it has now transitioned IntelliJ as the basis for "Android Studio," which is the standard IDE for Android, and for Google's other mobile platform, Flutter. All three are plug-in based and offer a wide selection of optional and third-party plugins to enhance the IDE, such as supporting other programming languages, frameworks, file types, and so on. While the following shows creating and running a program with Eclipse, the IntelliJ IDea and Netbeans IDEs all offer similar capabilities.

Perhaps the most popular cross-platform, open source IDE for Java is Eclipse, originally from IBM and now shepherded by the Eclipse Foundation, the home of many software projects including Jakarta, the follow-on to the Java Enterprise Edition. Eclipse is also used as the basis of other tools such as SpringSource Tool Suite (STS) and IBM's Rational Application Developer (RAD). All IDEs do basically the same thing for you when getting started; see, for example, the Eclipse New Java Class Wizard shown in Figure 1-1. Eclipse also features a number of refactoring capabilities, shown in Figure 1-2.

Figure 1-1. Eclipse: New Java Class Wizard Figure 1-2. Eclipse: Refactoring

Mac OS X includes Apple's Developer Tools. The main IDE is Xcode. Unfortunately, current versions of Xcode do not really support Java development, so there is little to recommend it for our purposes; it is primarily for those building non-portable (iOS-only or OS X–only) applications in the Swiift or Objective-C programming languages. So even if you are on OS X, to do Java development you should use one of the three Java IDEs.

How do you choose an IDE? Given that all three major IDEs (Eclipse, NetBeans, IntelliJ) can be downloaded free, why not try them all and see which one best fits the kind of development you do? Regardless of what platform you use to develop Java, if you have a Java runtime, you should have plenty of IDEs from which to choose.

Figure 1-3. IntelliJ program output See Also

Each IDE's web site maintains an up-to-date list of resources, including books. See Table 1-1 for the website for each.

Table 1-1. The Big 3 Java IDEs Product name Project URL Note

Eclipse

https://eclipse.org/

Basis of STS, RAD

IntelliJ Idea

https://jetbrains.com/idea/

Basis of Android Studio

Netbeans

https://netbeans.apache.org

Run anywhere JavaSE does

These major IDEs are extensible; see their documentation for a list of the many, many plug-ins available. Most of them allow you to find and install plug-ins from within the IDE. For Eclipse, use the Eclipse Marketplace, near the bottom of the Help menu. As a last resort, if you need/want to write a plug-in that extends the functionality of your IDE, you can do that too, and in Java.

For Eclipse, I have some useful information at https://darwinsys.com/java including a list of shortcuts to aid developer productivity.

1.3 Running Java with JShell Problem

You want to try out Java expressions and APIs quickly, without having to create a file with public class X { public static void main(String[] args) { … } every time.

Solution

Use JShell, Java's new REPL (read-evaluate-print-loop) interpreter.

Discussion

Starting with Java 11, jshell is included as a standard part of Java. Jshell allows you to enter Java statements and have them evaluated without the bother of creating a class and a main program. You can use it for quick calculations, or to try out an API to see how it works, or almost any purpose; if you find an expression you like, you can copy it into a regular Java class and make it permanent. JShell can also be used as a scripting language over Java, but the overhead of starting the JVM means that it won't be as fast as awk, Perl or Python for quick scripting.

REPL programs are very convenient, and hardly a new idea (LISP languages from the 1950's included them). You can think of command line interpreters (CLIs) such as the Bash or Ksh shells on UNIX/Linux, or Command.com on Microsoft Windows, as REPLs for the system as a whole. Many interpreted languages like Ruby and Python can also be used as REPLs. Java finally has its own REPL, JShell. Here's an example of using it:

$ jshell | Welcome to JShell -- Version 11.0.2 | For an introduction type: /help intro jshell> "Hello" $1 ==> "Hello" jshell> System.out.println("Hello"); Hello jshell> System.out.println("Hello") Hello jshell> "Hello" + sqrt(57) | Error: | cannot find symbol | symbol: method sqrt(int) | "Hello" + sqrt(57) | ^--^ jshell> "Hello" + Math.sqrt(57) $2 ==> "Hello7.54983443527075" jshell> String.format("Hello %6.3f", Math.sqrt(57) ...> ) $3 ==> "Hello 7.550" jshell> String x = Math.sqrt(22/7) + " " + Math.PI + ...> " and the end." x ==> "1.7320508075688772 3.141592653589793 and the end." jshell>

You can see some obvious simplifications here, and one that's not obvious from the above:

The value of an expression is printed, without needing to call System.out.println every time, but you can call it if you like;

The semicolon at the end of a statment is optional (unless you type more than one statement on a line);

If you make a mistake, you get a helpful message immediately;

If you do make a mistake, you can use "shell history" (i.e. up-arrow) to recall the statment so you can repair it;

If you omit a close quote, parenthesis or other punctuation, JShell will just wait for you, giving a continuation prompt ….

So go ahead and experiment with JShell. Read the built-in introductory tutorial for more details. When you get something you like, copy and paste it into a Java program and save it.

1.4 Using CLASSPATH Effectively Problem

You need to keep your class files in a common directory, or you're wrestling with CLASSPATH.

Solution

Set CLASSPATH to the list of directories and/or JAR files that contain the classes you want.

Discussion

CLASSPATH is one of the more "interesting" aspects of using Java. You can store your class files in any of a number of directories, JAR files, or ZIP files. Just like the PATH your system uses for finding programs, the CLASSPATH is used by the Java runtime to find classes. Even when you type something as simple as java HelloWorld, the Java interpreter looks in each of the places named in your CLASSPATH until it finds a match. Let's work through an example.

The CLASSPATH can be set as an environment variable on systems that support this (Microsoft Windows and Unix, including Mac OS X). You set it the same way you set other environment variables, such as your PATH environment variable.

Alternatively, you can specify the CLASSPATH for a given command on the command line:

C:\> java -classpath c:\ian\classes MyProg

Suppose your CLASSPATH were set to C:\classes;. on Windows or ~/classes:. on Unix (on the Mac, you can set the CLASSPATH with JBindery). Suppose you had just compiled a file named HelloWorld.java into HelloWorld.class and tried to run it. On Unix, if you run one of the kernel tracing tools (trace, strace, truss, ktrace), you would probably see the Java program open (or stat, or access) the following files:

Some file(s) in the JDK directory

Then ~/classes/HelloWorld.class, which it probably wouldn't find

Finally, ./HelloWorld.class, which it would find, open, and read into memory

The vague "some file(s) in the JDK directory" is release-dependent. You should not mess with the JDK files, but if you're curious, you can find them in the System Properties under sun.boot.class.path (see Recipe 2.2 for System Properties information).

Suppose you had also installed the JAR file containing the supporting classes for programs from this book, darwinsys-api.jar (the actual filename if you download it may have a version number as part of the filename). You might then set your CLASSPATH to C:\classes;C:\classes\darwinsys-api.jar;. on Windows or ~/classes:~/classes/darwinsys-api.jar:. on Unix. Notice that you do need to list the JAR file explicitly. Unlike a single class file, placing a JAR file into a directory listed in your CLASSPATH does not suffice to make it available.

Note that certain specialized programs (such as a web server running a Java EE Servlet container) may not use either bootpath or CLASSPATH as shown; these application servers typically provide their own ClassLoader (see [Link to Come] for information on class loaders). EE Web containers, for example, set your web app classpath to include the directory WEB-INF/classes and all the JAR files found under WEB-INF/lib.

How can you easily generate class files into a directory in your CLASSPATH? The javac command has a -d dir option, which specifies where the compiler output should go. For example, using -d to put the HelloWorld class file into my $HOME/classes directory, I just type the following (note that from here on I will be using the package name in addition to the class name, like a good kid):

javac -d $HOME/classes HelloWorld.javajava -cp $HOME/classes starting.HelloWorld Hello, world!

As long as this directory remains in my CLASSPATH, I can access the class file regardless of my current directory. That's one of the key benefits of using CLASSPATH.

Managing CLASSPATH can be tricky, particularly when you alternate among several JVMs of different vintages (as I sometimes do) or when you have multiple directories in which to look for JAR files. Some Linux distributions have an "alternatives" mechanism for managing which version of Java to use. Otherwise you may want to use some sort of batch file or shell script to control this. The following is part of the shell script that I have used—it was written for the standard shell on Unix (should work on Bash, Ksh, etc.), but similar scripts could be written in other shells or as a DOS batch file:

# These guys must be present in my classpath... export CLASSPATH=/home/ian/classes/darwinsys-api.jar: # Now a for loop, testing for .jar/.zip or [ -d ... ] OPT_JARS="$HOME/classes $HOME/classes/*.jar ${JAVAHOME}/jre/lib/ext/*.jar /usr/local/jars/antlr-3.2.0" for thing in $OPT_JARS do if [ -f $thing ]; then //must be either a file... CLASSPATH="$CLASSPATH:$thing" else if [ -d $thing ]; then //or a directory CLASSPATH="$CLASSPATH:$thing" fi done CLASSPATH="$CLASSPATH:."

This builds a minimum CLASSPATH out of darwinsys-api.jar, then goes through a list of other files and directories to check that each is present on this system (I use this script on several machines on a network), and ends up adding a dot (.) to the end of the CLASSPATH.

Warning

Note that, on Unix, a shell script executed normally can change environment variables like CLASSPATH only for itself; the "parent" shell (the one running commands in your terminal or window) is not affected. Changes that are meant to be permanent need to be stored in your startup files (.profile, .bashrc, or whatever you normally use).

Note that Java 9 and later also have a MODULEPATH, which will be covered in XXX.

1.5 Downloading and Using the Code Examples Problem

You want to try out my example code and/or use my utility classes.

Solution

Download the latest archive of the book source files, unpack it, and run Maven (see Recipe 1.6) to compile the files.

Discussion

The source code used as examples in this book is drawn from several source code repositories that have been in continuous development since 1995. These are listed in Table 1-2.

Table 1-2. The main source repositories Repository name Github.com URL Package description Approx. size

javasrc

http://github.com/IanDarwin/javasrc

Java classes from all APIs

1,200 classes

darwinsys-api

http://github.com/Iandarwin/darwinsys-api

A published API

250 classes

A small number of examples are drawn from the older javasrcee (Java EE) examples, which I split off from javasrc due to the overall size; this is also on GitHub.

You can download these repositories from the GitHub URLs shown in Table 1-2. GitHub allows you to download, by use of git clone, a ZIP file of the entire repository's current state, or to view individual files on the web interface. Downloading with git clone instead of as an archive is preferred because you can then update at any time with a simple git pull command. And with the amount of updating this has undergone for the current release of Java, you are sure to find changes after the book is published.

If you are not familiar with Git, see "CVS, Subversion, Git, Oh My!".

javasrc

This is the largest repo, and consists primarily of code written to show a particular feature or API. The files are organized into subdirectories by topic, many of which correspond more or less to book chapters—for example, a directory for strings examples (Chapter 3), regex for regular expressions (Chapter 4), numbers ([Link to Come]), and so on. The archive also contains the index by name and index by chapter files from the download site, so you can easily find the files you need.

There are about 80 subdirectories in javasrc (under src/main/java), too many to list here. They are listed in the file src/main/java/index-of-directories.txt.

darwinsys-api

I have built up a collection of useful stuff, partly by moving some reusable classes from javasrc into my own API, which I use in my own Java projects. I use example code from it in this book, and I import classes from it into many of the other examples. So, if you're going to be downloading and compiling the examples individually, you should first download the file darwinsys-api-1.x.jar (for the latest value of x) and include it in your CLASSPATH. Note that if you are going to build the javasrc code with Eclipse or Maven, you can skip this download because the top-level Maven script starts off by including the JAR file for this API.

This is the only one of the repos that appears in Maven Central; find it by searching for darwinsys. The current Maven artifact is:

com.darwinsys darwinsys-api 1.0.3

This API consists of about two dozen com.darwinsys packages, listed in Table 1-3. You will notice that the structure vaguely parallels the standard Java API; this is intentional. These packages now include more than 200 classes and interfaces. Most of them have javadoc documentation that can be viewed with the source download.

Table 1-3. The com.darwinsys packages Package name Package description

com.darwinsys.ant

A demonstration Ant task

com.darwinsys.csv

Classes for comma-separated values files

com.darwinsys.database

Classes for dealing with databases in a general way

com.darwinsys.diff

Comparison utilities

com.darwinsys.genericui

Generic GUI stuff

com.darwinsys.geo

Classes relating to country codes, provinces/states, and so on

com.darwinsys.graphics

Graphics

com.darwinsys.html

Classes (only one so far) for dealing with HTML

com.darwinsys.io

Classes for input and output operations, using Java's underlying I/O classes

com.darwinsys.jsptags

Java EE JSP tags

com.darwinsys.lang

Classes for dealing with standard features of Java

com.darwinsys.locks

Pessimistic locking API

com.darwinsys.mail

Classes for dealing with email, mainly a convenience class for sending mail

com.darwinsys.model

Modeling

com.darwinsys.net

Networking

com.darwinsys.preso

Presentations

com.darwinsys.reflection

Reflection

com.darwinsys.regex

Regular expression stuff: an REDemo program, a Grep variant, and so on

com.darwinsys.security

Security

com.darwinsys.servlet

Servlet API helpers

com.darwinsys.sql

Classes for dealing with SQL databases

com.darwinsys.swingui

Classes for helping construct and use Swing GUIs

com.darwinsys.swingui.layout

A few interesting LayoutManager implementations

com.darwinsys.testdata

Test data generators

com.darwinsys.testing

Testing tools

com.darwinsys.unix

Unix helpers

com.darwinsys.util

A few miscellaneous utility classes

com.darwinsys.xml

XML utilities

Many of these classes are used as examples in this book; just look for files whose first line begins:

package com.darwinsys;

You'll also find that many of the other examples have imports from the com.darwinsys packages.

General notes

If you are short on time, the majority of the examples are in javasrc, so cloning or downloading that repo will get you most of the code from the book. Also, its Maven script refers to a copy of the darwinsys-api that is in Maven Central, so you could get 90% of the code compilable, testable and runnable with one git clone, for javasrc. Your best bet is to use git clone to download a copy of all three, and do git pull every few months to get updates.

Alternatively, you can download a single intersection set of all three that is made up almost exclusively of files actually used in the book, from this book's catalog page. This archive is made from the sources that are dynamically included into the book at formatting time, so it should reflect exactly the examples you see in the book. But it will not include as many examples as the three individual archives, nor is it guaranteed that everything will compile because of missing dependencies. But if all you want is to copy pieces into a project you're working on, this may be the one to get.

You can find links to all of these from my own website for this book; just follow the Downloads link.

The three separate repositories are each self-contained projects with support for building both with Eclipse (Recipe 1.2) and with Maven (Recipe 1.6). Note that Maven will automatically fetch a vast array of prerequisite libraries when first invoked on a given project, so be sure you're online on a high-speed Internet link. However, Maven will ensure that all prerequisites are installed before building. If you choose to build pieces individually, look in the file pom.xml for the list of dependencies. Unfortunately, I will probably not be able to help you if you are not using either Eclipse or Maven with the control files included in the download.

If you have a version of Java older than the current Java 12, a few files will not compile. You can make up "exclusion elements" for the files that are known not to compile.

All my code in the three projects is released under the least-restrictive credit-only license, the two-clause BSD license. If you find it useful, incorporate it into your own software. There is no need to write to ask me for permission; just use it, with credit.

Tip

Most of the command-line examples refer to source files, assuming you are in src/main/java, and runnable classes, assuming you are in (or have added to your classpath) the build directory (e.g., usually target/classes). This will not be mentioned with each example, as doing so would waste a lot of paper.

Caveat Lector

The repos have been in development since 1995. This means that you will find some code that is not up to date, or that no longer reflects best practices. This is not surprising: any body of code will grow old if any part of it is not actively maintained. (Thus, at this point, I invoke Culture Club's, "Do You Really Want to Hurt Me?": "Give me time to realize my crimes.") Where advice in the book disagrees with some code you found in the repo, keep this in mind. One of the practices of Extreme Programming is Continuous Refactoring—the ability to improve any part of the code base at any time. Don't be surprised if the code in the online source directory differs from what appears in the book; it is a rare week that I don't make some improvement to the code, and the results are committed and pushed quite often. So if there are differences between what's printed in the book and what you get from GitHub, be glad, not sad, for you'll have received the benefit of hindsight. Also, people can contribute easily on GitHub via "pull request"; that's what makes it interesting. If you find a bug or an improvement, do send me a pull request!

The consolidated archive on oreilly.com will not be updated as frequently.

CVS, Subversion, Git, Oh My!

Many distributed version control systems or source code management systems are available. The ones that have been widely used in open source in recent years include:

Concurrent Versions System (CVS)

Apache Subversion

Git

As well as others that are used in particular niches (e.g., Mercurial)

Although each has its advantages and disadvantages, the use of Git in the Linux build process (and projects based on Linux, such as the Android mobile environment), as well as the availability of sites like github.com and gitorious.org, give Git a massive momentum over the others. I don't have statistics, but I suspect the number of projects in Git repositories probably exceeds the others combined. Several well-known organizations using Git are listed on the Git home page.

For this reason, I have been moving my projects to GitHub; see http://github.com/IanDarwin/. To download the projects and be able to get updates applied automatically, use Git to download them. Options include:

The command-line Git client. If you are on any modern Unix or Linux system, Git is either included or available in your ports or packaging or "developer tools," but can also be downloaded for MS Windows, Mac, Linux, and Solaris from the home page under Downloads.

All modern IDEs have Git support built in.

Numerous standalone GUI clients

Even Continuous Integration servers such as Jenkins/Hudson (see Recipe 1.11) have plug-ins available for updating a project with Git (and other popular SCMs) before building them

You will want to have one or more of these Git clients at your disposal to download my code examples. You could download them as ZIP archive files instead, but then you won't get updates! You can also view or download individual files from the GitHub page via a web browser.

make Versus Java Build Tools

make is the original build tool from the 1970s, used in Unix and C/C++ development. make and the Java-based tools each have advantages; I'll try to compare them without too much bias.

The Java build tools work the same on all platforms, as much as possible. make is rather platform-dependent; there is GNU make, BSD make, Xcode make, Visual Studio make, and several others, each with slightly different syntax.

That said, there are many Java build tools to choose from, including:

Apache Ant

Apache Maven

Gradle

Apache Buildr

Makefiles and Buildr/Gradle build files are the shortest. Make just lets you list the commands you want run and their dependencies. Buildr and Gradle each have their own language (based on Ruby and Groovy, respectively). Maven uses XML which is generally more verbose, but with a lot of sensible defaults and a standard, default workflow. Ant also uses XML, but makes you specify each task you want performed.

make runs faster for single tasks; most implementations are written in C. However, the Java tools can run many Java tasks in a single JVM—such as the built-in Java compiler, jar/war/tar/zip files, and many more—to the extent that it may be more efficient to run several Java compilations in one JVM process than to run the same compilations using make. In other words, once the JVM that is running Ant/Maven/Gradle itself is up and running, it doesn't take long at all to run the Java compiler and run the compiled class. This is Java as it was meant to be!

Java build tool files can do more for you. These tools automatically find all the *.java files in and under src/main/java. With make, you have to spell such things out.

The Java tools have special knowledge of CLASSPATH, making it easy to set a CLASSPATH in various ways for compile time. Maven offers a "scope" of test for classes and other files that will be on your classpath only when running tests, for example. You may have to duplicate this in other ways—shell scripts or batch files—for using make or for manually running or testing your application.

Maven and Gradle also handle dependency management. You simply list the API and version that you want, and the tool finds it, downloads it over the Internet, saves it in a cache folder for future use, and adds it to your classpath at the right time—all without writing any rules.

Gradle goes further yet, and allows scripting logic in its configuration file (strictly speaking, Ant and Maven do as well, but Gradle's is much easier to use).

make is simpler to extend, but harder to do so portably. You can write a one-line make rule for getting a CVS archive from a remote site, but you may run into incompatibilities between GNU make, BSD make, Microsoft make, and so on. There is a built-in Ant task for getting an archive from CVS using Ant; it was written as a Java source file instead of just a series of command-line commands.

make has been around much longer. There are probably millions (literally) more Makefiles than Ant files. Non-Java developers have typically not heard of Ant; they almost all use make. Most non-Java open source projects use make, except for programming languages that provide their own build tool (e.g., Ruby provides Rake and Thor, Haskell provides Cabal, …).

The advantages of the Java tools make more sense on larger projects. Primarily, make has been used on the really large projects. For example, make is used for telephone switch source code, which consists of hundreds of thousands of source files totalling tens or hundreds of millions of lines of source code. By contrast, Tomcat is about 500,000 lines of code, and the JBoss Java EE server "WildFly" is about 800,000 lines. Use of the Java tools is growing steadily, particularly now that most of the widely used Java IDEs (JBuilder, Eclipse, NetBeans, etc.) have interfaces to Ant, Maven, and/or Gradle. Effectively all Java open source projects use Maven; some still use Ant, or the newest kid on that block, Gradle.

make is included with most Unix and Unix-like systems and shipped with many Windows IDEs. Ant and Maven are not included with any operating system distribution that I know of, but can be installed as packages on almost all, and both are available direct from Apache. The same is true for Gradle, but it installs from http://gradle.org, and Buildr from the Apache website.

To sum up, although make and the Java tools are good, new Java projects should use one of the newer Java-based tools such as Maven or Gradle.

1.6 Automating Dependencies, Compilation, Testing, and Deployment with Apache Maven Problem

You want a tool that does it all automatically: downloads your dependencies, compiles your code, compiles and runs your tests, packages the app, and installs or deploys it.

Solution

Use Apache Maven.

Discussion

Maven is a Java-centric build tool that includes a sophisticated, distributed dependency management system that also gives it rules for building application packages such as JAR, WAR, and EAR files and deploying them to an array of different targets. Whereas older build tools focus on the how, Maven files focus on the what, specifying what you want done.

Maven is controlled by a file called pom.xml (for Project Object Model). A sample pom.xml might look like this:

4.0.0 com.example my-se-project 1.0-SNAPSHOT jar my-se-project http://com.example/ UTF-8 junit junit 4.8.1 test

This specifies a project called "my-se-project" (my standard-edition project) that will be packaged into a JAR file; it depends on the JUnit 4.x framework for unit testing (see Recipe 1.10), but only needs it for compiling and running tests. If I type mvn install in the directory with this POM, Maven will ensure that it has a copy of the given version of JUnit (and anything that JUnit depends on), then compile everything (setting CLASSPATH and other options for the compiler), run any and all unit tests, and if they all pass, generate a JAR file for the program; it will then install it in my personal Maven repo (under ~/.m2/repository) so that other Maven projects can depend on my new project JAR file. Note that I haven't had to tell Maven where the source files live, nor how to compile them—this is all handled by sensible defaults, based on a well-defined project structure. The program source is expected to be found in src/main/java, and the tests in src/test/java; if it's a web application, the web root is expected to be in src/main/webapp by default. Of course, you can override these.

Note that even the preceding config file does not have to be, and was not, written by hand; Maven's "archteype generation rules" let it build the starting version of any of several hundred types of projects. Here is how the file was created:

$ mvn archetype:generate \ -DarchetypeGroupId=org.apache.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DgroupId=com.example -DartifactId=my-se-project \[INFO] Scanning for projects... Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/ maven-deploy-plugin/2.5/maven-deploy-plugin-2.5.pom \[several dozen or hundred lines of downloading POM files and Jar files...] \[INFO] Generating project in Interactive mode \[INFO] Archetype [org.apache.maven.archetypes:maven-archetype-quickstart:1.1] found in catalog remote \[INFO] Using property: groupId = com.example \[INFO] Using property: artifactId = my-se-project Define value for property 'version': 1.0-SNAPSHOT: : \[INFO] Using property: package = com.example Confirm properties configuration: groupId: com.example artifactId: my-se-project version: 1.0-SNAPSHOT package: com.example Y: : y \[INFO] ------------------------------------------------------------------------ \[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1 \[INFO] ------------------------------------------------------------------------ \[INFO] Parameter: groupId, Value: com.example \[INFO] Parameter: packageName, Value: com.example \[INFO] Parameter: package, Value: com.example \[INFO] Parameter: artifactId, Value: my-se-project \[INFO] Parameter: basedir, Value: /private/tmp \[INFO] Parameter: version, Value: 1.0-SNAPSHOT \[INFO] project created from Old (1.x) Archetype in dir: /private/tmp/ my-se-project \[INFO] ------------------------------------------------------------------------ \[INFO] BUILD SUCCESS \[INFO] ------------------------------------------------------------------------ \[INFO] Total time: 6:38.051s \[INFO] Finished at: Sun Jan 06 19:19:18 EST 2013 \[INFO] Final Memory: 7M/81M \[INFO] ------------------------------------------------------------------------

The IDEs (see Recipe 1.2) have support for Maven. For example, if you use Eclipse, M2Eclipse (m2e) is an Eclipse plug-in that will build your Eclipse project dependencies from your POM file; this plug-in ships by default with current Java Developer builds of Eclipse, and is also available for some older releases; see the Eclipse website for plug-in details.

A POM file can redefine any of the standard "goals." Common Maven goals (predefined by default to do something sensible) include:

clean

Removes all generated artifacts

compile

Compiles all source files

test

Compiles and runs all unit tests

package

Builds the package

install

Installs the pom.xml and package into your local Maven repository for use by your other projects

deploy

Tries to install the package (e.g., on an application server)

Most of the steps implicitly invoke the previous ones—e.g., package will compile any missing .class files, and run the tests if that hasn't already been done in this run.

Typically there are application-server–specific targets provided; as a single example, with the WildFly Application Server (known as JBoss AS a decade ago), you would install some additional plug-in(s) as per their documentation, and then deploy to the app server using:

mvn wildfly:deploy

instead of the regular deploy.

Maven pros and cons

Maven can handle complex projects and is very configurable. I build the darwinsys-api and javasrc projects with Maven and let it handle finding dependencies, making the download of the project source code smaller (actually, moving the download overhead to the servers of the projects themselves). The only real downsides to Maven is that it takes a while to get fully up to speed with it, and the fact that it can be a bit hard to diagnose when things go wrong. A good web search engine is your friend when things fail.

One issue I fear is that a hacker could gain access to a project's site and modify, or install a new version of, a POM. Maven automatically fetches updated POM versions. However, it does use hash signatures to verify that files have not been tampered during the download process. I am not aware of this having happened, but it still worries me.